Skip to content

Commit

Permalink
[Query Builder] Correctly handle match phrases when a single value is…
Browse files Browse the repository at this point in the history
… specified or when the match phrases is negated (opensearch-project#33)

* [Build query] Correctly handle phrases filter that specify only one single value

Contrary to the phrase filter type which always specify a meta.params.query, the phrases filter type never specify a meta.params.query even when a single value is selected.
This anomaly trigger an error generated by the MonoFieldQueryBase included in the elastic-builder dependency and prevent the generation of the report.

Signed-off-by: Kévin Masseix <masseix.kevin@gmail.com>

* [Build query] Correctly handle negated phrases filter that specify only one single value

Signed-off-by: Kévin Masseix <masseix.kevin@gmail.com>

* [Build query] Correctlty handle negated phrases to exclude them from the report instead of including them

Signed-off-by: Kévin Masseix <masseix.kevin@gmail.com>
  • Loading branch information
MKCG authored May 17, 2021
1 parent f082eff commit d2124ea
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions server/routes/utils/dataReportHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const buildQuery = (report, is_count) => {
}
} else {
requestBody.should(
esb.matchPhraseQuery(item.meta.key, item.meta.params.query)
esb.matchPhraseQuery(item.meta.key, item.meta.value)
);
}
requestBody.minimumShouldMatch(1);
Expand All @@ -104,17 +104,19 @@ export const buildQuery = (report, is_count) => {
requestBody.mustNot(esb.existsQuery(item.meta.key));
break;
case 'phrases':
let negatedBody = esb.boolQuery();
if (item.meta.value.indexOf(',') > -1) {
const valueSplit = item.meta.value.split(', ');
for (const [key, incr] of valueSplit.entries()) {
requestBody.should(esb.matchPhraseQuery(item.meta.key, incr));
negatedBody.should(esb.matchPhraseQuery(item.meta.key, incr));
}
} else {
requestBody.should(
esb.matchPhraseQuery(item.meta.key, item.meta.params.query)
negatedBody.should(
esb.matchPhraseQuery(item.meta.key, item.meta.value)
);
}
requestBody.minimumShouldMatch(1);
negatedBody.minimumShouldMatch(1);
requestBody.mustNot(negatedBody);
break;
}
break;
Expand Down

0 comments on commit d2124ea

Please sign in to comment.