Skip to content

Commit

Permalink
Ading comments, minor refactoring
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Gaievski <[email protected]>
  • Loading branch information
martin-gaievski committed Nov 29, 2023
1 parent 9a0c209 commit b8f794b
Showing 1 changed file with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,31 @@ private boolean isHybridQuery(final Query query, final SearchContext searchConte
if (query instanceof HybridQuery) {
return true;
} else if (hasNestedFieldOrNestedDocs(query, searchContext) && mightBeWrappedHybridQuery(query)) {
BooleanQuery booleanQuery = (BooleanQuery) query;
return booleanQuery.clauses()
// checking if this is a hybrid query that is wrapped into a Bool query by core Opensearch code
// https://github.com/opensearch-project/OpenSearch/blob/main/server/src/main/java/org/opensearch/search/DefaultSearchContext.java#L367-L370.
// main reason for that is performance optimization, at time of writing we are ok with loosing on performance if that's unblocks
// hybrid query for indexes with nested field types.
// in such case we consider query a valid hybrid query. Later in the code we will extract it and execute as a main query for
// this search request.
// below is sample structure of such query:
//
// Boolean {
// should: {
// hybrid: {
// sub_query1 {}
// sub_query2 {}
// }
// }
// filter: {
// exists: {
// field: "_primary_term"
// }
// }
// }
if (query instanceof BooleanQuery == false) {
return false;

Check warning on line 104 in src/main/java/org/opensearch/neuralsearch/search/query/HybridQueryPhaseSearcher.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/neuralsearch/search/query/HybridQueryPhaseSearcher.java#L104

Added line #L104 was not covered by tests
}
return ((BooleanQuery) query).clauses()
.stream()
.filter(clause -> clause.getQuery() instanceof HybridQuery == false)
.allMatch(
Expand Down

0 comments on commit b8f794b

Please sign in to comment.