diff --git a/lib/Queries.js b/lib/Queries.js index 73250e3..3e4dc37 100644 --- a/lib/Queries.js +++ b/lib/Queries.js @@ -142,15 +142,10 @@ module.exports.matchSubjectObject = function( subject, object, cb ){ }; module.exports._hasTooManyCombinations = function(subject, object) { - const terms = [ subject, object ]; + const stmt = this.prepare(query.count_tokens); - const stmt = this.prepare('SELECT count(*) as cnt from fulltext where fulltext.fulltext = ?'); - - const counts = terms.map(function(token) { - return stmt.get(token).cnt; - }); - + const counts = terms.map(token => stmt.get({ token_quoted: `"${token}"` }).cnt); const combinations = counts.reduce((a, b) => a * b, 1); return combinations >= 1e6; diff --git a/query/count_tokens.sql b/query/count_tokens.sql new file mode 100644 index 0000000..ee9edb2 --- /dev/null +++ b/query/count_tokens.sql @@ -0,0 +1,3 @@ +SELECT COUNT(*) AS cnt +FROM fulltext AS ft +WHERE ft.fulltext MATCH $token_quoted