Skip to content

Commit

Permalink
Update search query (way faster!)
Browse files Browse the repository at this point in the history
  • Loading branch information
rvazarkar committed Jul 22, 2020
1 parent 8f6fe81 commit 4d763ec
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,15 @@ function getRealLabel(label) {
export function buildSearchQuery(searchterm) {
if (searchterm.includes(':')) {
let [type, term] = searchterm.split(':');
term = escapeRegExp(term);
let t = '(?i).*' + term + '.*';
type = getRealLabel(type);

let statement = `MATCH (n:${type}) WHERE n.name =~ $name OR n.objectid =~ $name RETURN n LIMIT 10`;
let statement = `MATCH (n:${type}) WHERE n.name CONTAINS $name OR n.objectid CONTAINS $name RETURN n LIMIT 10`;

return [statement, t];
return [statement, term.toUpperCase()];
} else {
let q = escapeRegExp(searchterm);
let t = '(?i).*' + q + '.*';

return [
'MATCH (n) WHERE n.name =~ $name OR n.objectid =~ $name RETURN n LIMIT 10',
t,
'MATCH (n) WHERE n.name CONTAINS $name OR n.objectid CONTAINS $name RETURN n LIMIT 10',
searchterm.toUpperCase(),
];
}
}
Expand Down

0 comments on commit 4d763ec

Please sign in to comment.