Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve quoting of token count query #223

Merged
merged 1 commit into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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