Skip to content

Commit

Permalink
fix: missing util file
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanoshadjipetrou committed Jul 10, 2024
1 parent 314866a commit 867180b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/utils/filtering/globalsearch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import filteringUtils from '../../config/filtering/index.json';

export function buildGlobalSearchFilterString(
fields: string[],
template: string,
keywords: string[],
): string {
const strArray: string[] = [];

keywords.forEach((keyword: string) => {
const fieldStrArray: string[] = fields.map((field: string) =>
template
.replace('<field>', field)
.replace(
'<value>',
`'${encodeURIComponent(keyword.replace(/'/g, "''"))}'`,
),
);
strArray.push(`(${fieldStrArray.join(` ${filteringUtils.or_operator} `)})`);
});

return strArray.join(` ${filteringUtils.and_operator} `);
}

0 comments on commit 867180b

Please sign in to comment.