Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix analyzed prefix query in query_string #35756

Merged
merged 1 commit into from Nov 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -484,10 +484,13 @@ protected Query getPrefixQuery(String field, String termStr) throws ParseExcepti
List<Query> queries = new ArrayList<>();
for (Map.Entry<String, Float> entry : fields.entrySet()) {
Query q = getPrefixQuerySingle(entry.getKey(), termStr);
assert q != null;
queries.add(applyBoost(q, entry.getValue()));
if (q != null) {
queries.add(applyBoost(q, entry.getValue()));
}
}
if (queries.size() == 1) {
if (queries.isEmpty()) {
return null;
} else if (queries.size() == 1) {
return queries.get(0);
} else {
float tiebreaker = groupTieBreaker == null ? type.tieBreaker() : groupTieBreaker;
Expand Down Expand Up @@ -561,7 +564,7 @@ private Query getPossiblyAnalyzedPrefixQuery(String field, String termStr) throw
}

if (tlist.size() == 0) {
return super.getPrefixQuery(field, termStr);
return null;
}

if (tlist.size() == 1 && tlist.get(0).size() == 1) {
Expand Down
Expand Up @@ -1422,6 +1422,16 @@ public void testPhraseSlop() throws Exception {
assertEquals(expected, query);
}

public void testAnalyzedPrefix() throws Exception {
Query query = new QueryStringQueryBuilder("quick* @&*")
.field(STRING_FIELD_NAME)
.analyzer("standard")
.analyzeWildcard(true)
.toQuery(createShardContext());
Query expected = new PrefixQuery(new Term(STRING_FIELD_NAME, "quick"));
assertEquals(expected, query);
}

private static IndexMetaData newIndexMeta(String name, Settings oldIndexSettings, Settings indexSettings) {
Settings build = Settings.builder().put(oldIndexSettings)
.put(indexSettings)
Expand Down