Optimize search SQL query (I hope :p)

This commit is contained in:
Chocobozzz 2018-07-27 15:20:10 +02:00
parent a3c1738eea
commit dbfd3e9bfe
No known key found for this signature in database
GPG key ID: 583A612D890159BE
2 changed files with 17 additions and 29 deletions

View file

@ -51,17 +51,6 @@ function createSimilarityAttribute (col: string, value: string) {
)
}
function createSearchTrigramQuery (col: string, value: string) {
return {
[ Sequelize.Op.or ]: [
// FIXME: use word_similarity instead of just similarity?
Sequelize.where(searchTrigramNormalizeCol(col), ' % ', searchTrigramNormalizeValue(value)),
Sequelize.where(searchTrigramNormalizeCol(col), ' LIKE ', searchTrigramNormalizeValue(`%${value}%`))
]
}
}
// ---------------------------------------------------------------------------
export {
@ -69,8 +58,7 @@ export {
getSortOnModel,
createSimilarityAttribute,
throwIfNotValid,
buildTrigramSearchIndex,
createSearchTrigramQuery
buildTrigramSearchIndex
}
// ---------------------------------------------------------------------------