Skip to content

Commit

Permalink
If some facets are set, we should not run answer extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
zotya committed Jan 12, 2023
1 parent 0ca77cf commit dc89c71
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions searchlib/components/AnswerBox/requestBodyModifier.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,37 @@
function findKeyInTree(tree, key) {
let found = false;
if (typeof tree === 'object') {
Object.keys(tree).forEach((node_name) => {
if (node_name === key) {
found = true;
} else {
found = found || findKeyInTree(tree[node_name], key);
}
});
}
return found;
}
function findKeysInTree(tree, keys) {
let found = false;
keys.forEach((key) => {
found = found || findKeyInTree(tree, key);
});

return found;
}

export default function addQAParams(body, config) {
// const { from, size } = body;

if (Object.keys(body.aggs).length !== 0) return body;
if (!config.enableNLP) return body;

const ignoreNLPWhenActive = config.facets
.filter((facet) => facet.ignoreNLPWhenActive === true)
.map((facet) => facet['field']);
let query_types = config.nlp.qa.qa_queryTypes;
if (findKeysInTree(body.query, ignoreNLPWhenActive)) {
query_types = ['ignore'];
}
body.params = {
...(body.params || {}),

Expand All @@ -28,7 +56,7 @@ export default function addQAParams(body, config) {
cutoff: parseFloat(config.nlp.qa.cutoffScore ?? 0.1),
},
QuerySearch: {
query_types: config.nlp.qa.qa_queryTypes,
query_types: query_types,
},
};

Expand Down

0 comments on commit dc89c71

Please sign in to comment.