Skip to content

Commit

Permalink
Fix analyzed wildcard query in simple_query_string when disjunctions …
Browse files Browse the repository at this point in the history
…is empty (#114264) (#114355)

This change fixes analyzed wildcard query in simple_query_string when disjunctions is empty.

Closes #114185

(cherry picked from commit 6955bc1)

Co-authored-by: Halil Bülent Orhon <[email protected]>
  • Loading branch information
benwtrent and halilbulentorhon authored Oct 8, 2024
1 parent e461f86 commit ed457e4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/changelog/114264.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 114264
summary: "Fix analyzed wildcard query in simple_query_string when disjunctions is empty"
area: Search
type: bug
issues: [114185]
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,32 @@ public void testFieldAliasOnDisallowedFieldType() throws Exception {
});
}

public void testSimpleQueryStringWithAnalysisStopWords() throws Exception {
String mapping = Strings.toString(
XContentFactory.jsonBuilder()
.startObject()
.startObject("properties")
.startObject("body")
.field("type", "text")
.field("analyzer", "stop")
.endObject()
.endObject()
.endObject()
);

CreateIndexRequestBuilder mappingRequest = indicesAdmin().prepareCreate("test1").setMapping(mapping);
mappingRequest.get();
indexRandom(true, prepareIndex("test1").setId("1").setSource("body", "Some Text"));
refresh();

assertHitCount(
prepareSearch().setQuery(
simpleQueryStringQuery("the* text*").analyzeWildcard(true).defaultOperator(Operator.AND).field("body")
),
1
);
}

private void assertHits(SearchHits hits, String... ids) {
assertThat(hits.getTotalHits().value, equalTo((long) ids.length));
Set<String> hitIds = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ public Query newPrefixQuery(String text) {
if (disjuncts.size() == 1) {
return disjuncts.get(0);
}
if (disjuncts.size() == 0) {
return null;
}
return new DisjunctionMaxQuery(disjuncts, 1.0f);
}

Expand Down

0 comments on commit ed457e4

Please sign in to comment.