Skip to content

Commit

Permalink
feat(SQL): improve quoting of token count query (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
missinglink authored Mar 22, 2022
1 parent c3ce64c commit 6fc8535
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
9 changes: 2 additions & 7 deletions lib/Queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions query/count_tokens.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT COUNT(*) AS cnt
FROM fulltext AS ft
WHERE ft.fulltext MATCH $token_quoted

0 comments on commit 6fc8535

Please sign in to comment.