Skip to content

Commit

Permalink
Adding a null pointer check to fix index_prefix query (opensearch-pro…
Browse files Browse the repository at this point in the history
…ject#2879)

* Adding a null pointer check to fix index_prefix query

Signed-off-by: Vacha Shah <[email protected]>

* Adding test

Signed-off-by: Vacha Shah <[email protected]>
  • Loading branch information
VachaShah authored Apr 14, 2022
1 parent c4b684d commit 452e368
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,9 @@ public Query prefixQuery(String value, MultiTermQuery.RewriteMethod method, bool
}
Automaton automaton = Operations.concatenate(automata);
AutomatonQuery query = new AutomatonQuery(new Term(name(), value + "*"), automaton);
query.setRewriteMethod(method);
if (method != null) {
query.setRewriteMethod(method);
}
return new BooleanQuery.Builder().add(query, BooleanClause.Occur.SHOULD)
.add(new TermQuery(new Term(parentField.name(), value)), BooleanClause.Occur.SHOULD)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,17 @@ public void testIndexPrefixes() {
);

assertThat(q, equalTo(expected));

q = ft.prefixQuery("g", null, false, randomMockShardContext());
automaton = Operations.concatenate(Arrays.asList(Automata.makeChar('g'), Automata.makeAnyChar()));

expected = new ConstantScoreQuery(
new BooleanQuery.Builder().add(new AutomatonQuery(new Term("field._index_prefix", "g*"), automaton), BooleanClause.Occur.SHOULD)
.add(new TermQuery(new Term("field", "g")), BooleanClause.Occur.SHOULD)
.build()
);

assertThat(q, equalTo(expected));
}

public void testFetchSourceValue() throws IOException {
Expand Down

0 comments on commit 452e368

Please sign in to comment.