Conversation
lib/elasticsearch/cql_grammar.js
Outdated
| } | ||
|
|
||
| function displayParsed (string) { | ||
| const parsed = rightCqlParser.getAST(reverseString(string)) |
There was a problem hiding this comment.
Is there a way to better ensure that the chain of calls you're making to parse the string in this case matches the chain of calls in parseWithRightCql?
There was a problem hiding this comment.
👍 good point, actually parseWithRightCql returns an AST so we can just call it directly
| const queryJson = ElasticQueryBuilder.forApiRequest(request).query.toJson() | ||
| if (queryJson.bool && queryJson.bool.filter) { | ||
| return { filter: queryJson.bool.filter } | ||
| } |
There was a problem hiding this comment.
I assume this is a temporary measure until we can migrate the filter stuff into something else?
There was a problem hiding this comment.
That makes sense, we could factor out the filter stuff into a separate module shared by the cql_query_builder and ElasticQueryBuilder.
| }) | ||
| .map(([fieldType, fieldNames]) => fieldNames) | ||
| .flat() | ||
| } |
There was a problem hiding this comment.
Having trouble following what the types of these vars are and what they represent. If this part of the code is feeling final, let's add some documentation.
There was a problem hiding this comment.
yeah this is complicated, I've added a comment, let me know if it needs work
charmingduchess
left a comment
There was a problem hiding this comment.
Nothing blocking merge into QA - mostly formatting/importing suggestions and clarifying questions.
Great work!
There was a problem hiding this comment.
Do we want to ensure that the fields are the same for equivalent search_scopes? Or do we have a reason to keep these distinct?
There was a problem hiding this comment.
I think this has to do something more complicated than the search_scopes mapping, and also doesn't use the boosting. Might be a way to combine them but not sure
lib/elasticsearch/config.js
Outdated
| // We do custom field matching for this search-scope | ||
| } | ||
| }, | ||
| cql: {} |
There was a problem hiding this comment.
maybe worth a comment directing the reader to cql/index_mapping.js
There was a problem hiding this comment.
good catch, I've deleted that
|
|
||
| function buildBoolean (operator, queries) { | ||
| if (['NOT', 'AND NOT'].includes(operator)) return buildNegation(queries) | ||
| const esOperator = operator === 'AND' ? 'must' : 'should' |
There was a problem hiding this comment.
Is it correct to assume that there is validation upstream that would ensure these would only be AND or OR? Also, would that validation allow for OR NOT?
There was a problem hiding this comment.
Yep, that validation is done by the parser, which only allows operators that match the grammar
| return children | ||
| } | ||
|
|
||
| function displayParsed (string) { |
There was a problem hiding this comment.
Can you write a comment describing the left/right/reverse switcheration that (I think) is happening here?
| function buildNegation (queries) { | ||
| return { | ||
| bool: { | ||
| must: [buildEsQueryFromTree(queries[0])], |
There was a problem hiding this comment.
At what point do the queries get split into this array?
There was a problem hiding this comment.
This is done by the buildEsQueryFromTree, which filters out the subqueries and hands them to buildBoolean in case of a boolean query
| } | ||
|
|
||
| const table = { | ||
| exact: { term: 'term', prefix: 'prefix', fields: 'X', exact_fields: 'term' }, |
There was a problem hiding this comment.
What does 'X' represent here?
There was a problem hiding this comment.
These are fields that we don't use in that particular case. E.g. in the exact case, don't use the basic fields, since these are text, instead use the matching exact_fields. I've added a comment
| multi_match: { | ||
| query: 'Hamlet', | ||
| fields: [ | ||
| 'title', |
There was a problem hiding this comment.
Maybe import these fields from the index-mapping.json? Would be less brittle if/when we update scopes.
There was a problem hiding this comment.
Yeah I want to revisit the whole testing approach eventually
There was a problem hiding this comment.
this file is quite long. are there any clear groupings that could be split across different files, or even just demarcated with comments?
There was a problem hiding this comment.
perhaps split the boolean and atomic cases?
Initial work for NYQL. Still a work in progress, but so far we have:
EDIT: Merged in some other tickets which add:
==) queries(this covers SCC-5168/69/70)
Still to come:
inner_hits(this may be unnecessary)