Skip to content

Commit

Permalink
#197 Use >< rather than LIKE for first-letter search (#198)
Browse files Browse the repository at this point in the history
* #197 Use >< rather than LIKE for first-letter search

* Fix anywhere query
  • Loading branch information
navdeepsinghkhalsa authored Jul 13, 2018
1 parent 686db4e commit f3596bd
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions www/js/search-database.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,27 @@ module.exports = {
}
dbQuery += `,${charCode}`;
}
// Add trailing wildcard
dbQuery += '%';
if (searchType === 1) {
dbQuery = `%${dbQuery}`;
}

// Replace kh with kh pair bindi
let bindiQuery = '';
let replaced = '';
if (dbQuery.includes('075')) {
bindiQuery = `OR ${searchCol} LIKE '${dbQuery.replace(/075/g, '094')}'`;
replaced = dbQuery.replace(/075/g, '094');
}

// Use LIKE if anywhere, otherwise use operators
if (searchType === CONSTS.SEARCH_TYPES.FIRST_LETTERS_ANYWHERE) {
condition = `${searchCol} LIKE '%${dbQuery}%'`;
if (replaced) {
condition += ` OR ${searchCol} LIKE '%${replaced}%'`;
}
} else {
condition = `(${searchCol} > '${dbQuery}' AND ${searchCol} < '${dbQuery},z')`;
if (replaced) {
condition += ` OR (${searchCol} > '${replaced}' AND ${searchCol} < '${replaced},z')`;
}
}
condition = `${searchCol} LIKE '${dbQuery}' ${bindiQuery}`;

// Give preference to shorter lines if searching for 1 or 2 words
if (searchQuery.length < 3) {
order.push('v.FirstLetterLen');
}
Expand Down

0 comments on commit f3596bd

Please sign in to comment.