From 903d27a8fd8cc8b490a6d10810d4bf417d6b3b04 Mon Sep 17 00:00:00 2001 From: Jim Ferenczi Date: Fri, 16 Nov 2018 09:08:07 +0100 Subject: [PATCH] Fix phrase_slop in query_string query (#35533) This change ensures that custom `phrase_slop`s are correctly handled in the `query_string` query. Fixes #35125 --- .../index/search/QueryStringQueryParser.java | 6 +++ .../query/QueryStringQueryBuilderTests.java | 38 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/server/src/main/java/org/elasticsearch/index/search/QueryStringQueryParser.java b/server/src/main/java/org/elasticsearch/index/search/QueryStringQueryParser.java index fa2fd033bee..bcf1e924315 100644 --- a/server/src/main/java/org/elasticsearch/index/search/QueryStringQueryParser.java +++ b/server/src/main/java/org/elasticsearch/index/search/QueryStringQueryParser.java @@ -160,6 +160,12 @@ public class QueryStringQueryParser extends XQueryParser { queryBuilder.setOccur(op == Operator.AND ? BooleanClause.Occur.MUST : BooleanClause.Occur.SHOULD); } + @Override + public void setPhraseSlop(int phraseSlop) { + super.setPhraseSlop(phraseSlop); + queryBuilder.setPhraseSlop(phraseSlop); + } + /** * @param type Sets how multiple fields should be combined to build textual part queries. */ diff --git a/server/src/test/java/org/elasticsearch/index/query/QueryStringQueryBuilderTests.java b/server/src/test/java/org/elasticsearch/index/query/QueryStringQueryBuilderTests.java index ee56d07ca65..296fd973a5b 100644 --- a/server/src/test/java/org/elasticsearch/index/query/QueryStringQueryBuilderTests.java +++ b/server/src/test/java/org/elasticsearch/index/query/QueryStringQueryBuilderTests.java @@ -1387,6 +1387,44 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase