Skip to content

Commit

Permalink
fix(search): replace spaces by the '&' operator when searching
Browse files Browse the repository at this point in the history
  • Loading branch information
sg-gs committed Sep 27, 2024
1 parent 121d8d5 commit 602504c
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 602504c

Please sign in to comment.