Skip to content

Commit

Permalink
Normalize field queries when searching
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-va committed May 23, 2024
1 parent 063bf13 commit fcc4e0e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions apps/server-asset-sg/src/app/search/asset-search-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ export class AssetSearchService {
should: [
{
query_string: {
query: query,
query: normalizeFieldQuery(query),
fields: scope,
},
},
Expand Down Expand Up @@ -604,7 +604,7 @@ const mapQueryToElasticDsl = (query: AssetSearchQuery): QueryDslQueryContainer =
should: query.text.includes(':')
? {
query_string: {
query: query.text,
query: normalizeFieldQuery(query.text),
fields: scope,
},
}
Expand Down Expand Up @@ -761,3 +761,11 @@ interface PageOptions {
const escapeElasticQuery = (query: string): string => {
return query.replace(/(&&|\|\||!|\(|\)|\{|}|\[|]|\^|"|~|\*|\?|:|\\)/, '\\$1');
};

const normalizeFieldQuery = (query: string): string => (
query
.replace(/title(_*)public:/i, 'titlePublic:')
.replace(/title(_*)original:/i, 'titleOriginal:')
.replace(/contact(_*)ame:/i, 'contactNames:')
.replace(/sgs(_*)id:/i, 'sgsId:')
);

0 comments on commit fcc4e0e

Please sign in to comment.