Skip to content

Commit

Permalink
Merge pull request #398 from internxt/fix/search-with-spaces-between-…
Browse files Browse the repository at this point in the history
…words

[PB-2973, PB-2974]: fix/replace-spaces-by-the-&-operator-when-searching
  • Loading branch information
sg-gs authored Sep 27, 2024
2 parents 121d8d5 + 602504c commit 17668d9
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/modules/fuzzy-search/look-up.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ export class SequelizeLookUpRepository implements LookUpRepository {
partialName: string,
offset = 0,
): Promise<LookUpResult> {
const partialNameFormatted = partialName.replace(/\s+/g, ' & ');

const result = await this.model.findAll({
attributes: {
include: [
[
Sequelize.literal(
'nullif(ts_rank("tokenized_name", to_tsquery(:partialName)), 1)',
'nullif(ts_rank("tokenized_name", to_tsquery(:partialNameFormatted)), 1)',
),
'rank',
],
Expand All @@ -68,7 +70,9 @@ export class SequelizeLookUpRepository implements LookUpRepository {
where: {
user_id: userUuid,
[Op.or]: [
Sequelize.literal(`to_tsquery(:partialName) @@ "tokenized_name"`),
Sequelize.literal(
`to_tsquery(:partialNameFormatted) @@ "tokenized_name"`,
),
Sequelize.where(
Sequelize.fn(
'similarity',
Expand All @@ -86,7 +90,7 @@ export class SequelizeLookUpRepository implements LookUpRepository {
],
limit: 5,
offset: offset,
replacements: { partialName, userUuid },
replacements: { partialName, partialNameFormatted, userUuid },
include: [
{
model: FileModel,
Expand Down

0 comments on commit 17668d9

Please sign in to comment.