diff --git a/src/main/java/org/elasticsearch/search/SearchHit.java b/src/main/java/org/elasticsearch/search/SearchHit.java index f2374636344..9574e66282f 100644 --- a/src/main/java/org/elasticsearch/search/SearchHit.java +++ b/src/main/java/org/elasticsearch/search/SearchHit.java @@ -174,15 +174,27 @@ public interface SearchHit extends Streamable, ToXContent, Iterable parseElements() { @@ -65,16 +65,16 @@ public class MatchedFiltersFetchSubPhase implements FetchSubPhase { public void hitExecute(SearchContext context, HitContext hitContext) throws ElasticSearchException { List matchedFilters = Lists.newArrayListWithCapacity(2); - addMatchedFilters(hitContext, context.parsedQuery().namedFilters(), matchedFilters); + addMatchedQueries(hitContext, context.parsedQuery().namedFilters(), matchedFilters); if (context.parsedFilter() != null) { - addMatchedFilters(hitContext, context.parsedFilter().namedFilters(), matchedFilters); + addMatchedQueries(hitContext, context.parsedFilter().namedFilters(), matchedFilters); } - hitContext.hit().matchedFilters(matchedFilters.toArray(new String[matchedFilters.size()])); + hitContext.hit().matchedQueries(matchedFilters.toArray(new String[matchedFilters.size()])); } - private void addMatchedFilters(HitContext hitContext, ImmutableMap namedFilters, List matchedFilters) { + private void addMatchedQueries(HitContext hitContext, ImmutableMap namedFilters, List matchedFilters) { for (Map.Entry entry : namedFilters.entrySet()) { String name = entry.getKey(); Filter filter = entry.getValue(); diff --git a/src/main/java/org/elasticsearch/search/internal/InternalSearchHit.java b/src/main/java/org/elasticsearch/search/internal/InternalSearchHit.java index 11799f87ec9..45ee2f42e17 100644 --- a/src/main/java/org/elasticsearch/search/internal/InternalSearchHit.java +++ b/src/main/java/org/elasticsearch/search/internal/InternalSearchHit.java @@ -78,7 +78,7 @@ public class InternalSearchHit implements SearchHit { private Object[] sortValues = EMPTY_SORT_VALUES; - private String[] matchedFilters = Strings.EMPTY_ARRAY; + private String[] matchedQueries = Strings.EMPTY_ARRAY; private Explanation explanation; @@ -358,17 +358,37 @@ public class InternalSearchHit implements SearchHit { this.shard = target; } + + /** + * @deprecated In favor for {@link #matchedQueries(String[])} + */ + @Deprecated public void matchedFilters(String[] matchedFilters) { - this.matchedFilters = matchedFilters; + this.matchedQueries = matchedFilters; } + @Deprecated public String[] matchedFilters() { - return this.matchedFilters; + return this.matchedQueries; + } + + @Deprecated + public String[] getMatchedFilters() { + return this.matchedQueries; + } + + public void matchedQueries(String[] matchedFilters) { + this.matchedQueries = matchedFilters; } @Override - public String[] getMatchedFilters() { - return this.matchedFilters; + public String[] matchedQueries() { + return this.matchedQueries; + } + + @Override + public String[] getMatchedQueries() { + return this.matchedQueries; } public static class Fields { @@ -456,9 +476,9 @@ public class InternalSearchHit implements SearchHit { } builder.endArray(); } - if (matchedFilters.length > 0) { + if (matchedQueries.length > 0) { builder.startArray(Fields.MATCH_FILTERS); - for (String matchedFilter : matchedFilters) { + for (String matchedFilter : matchedQueries) { builder.value(matchedFilter); } builder.endArray(); @@ -609,9 +629,9 @@ public class InternalSearchHit implements SearchHit { size = in.readVInt(); if (size > 0) { - matchedFilters = new String[size]; + matchedQueries = new String[size]; for (int i = 0; i < size; i++) { - matchedFilters[i] = in.readString(); + matchedQueries[i] = in.readString(); } } @@ -704,11 +724,11 @@ public class InternalSearchHit implements SearchHit { } } - if (matchedFilters.length == 0) { + if (matchedQueries.length == 0) { out.writeVInt(0); } else { - out.writeVInt(matchedFilters.length); - for (String matchedFilter : matchedFilters) { + out.writeVInt(matchedQueries.length); + for (String matchedFilter : matchedQueries) { out.writeString(matchedFilter); } } diff --git a/src/test/java/org/elasticsearch/test/integration/search/matchedfilters/MatchedFiltersTests.java b/src/test/java/org/elasticsearch/test/integration/search/matchedfilters/MatchedQueriesTests.java similarity index 82% rename from src/test/java/org/elasticsearch/test/integration/search/matchedfilters/MatchedFiltersTests.java rename to src/test/java/org/elasticsearch/test/integration/search/matchedfilters/MatchedQueriesTests.java index b5a5cb263c2..5514bc585f0 100644 --- a/src/test/java/org/elasticsearch/test/integration/search/matchedfilters/MatchedFiltersTests.java +++ b/src/test/java/org/elasticsearch/test/integration/search/matchedfilters/MatchedQueriesTests.java @@ -35,10 +35,10 @@ import static org.hamcrest.Matchers.hasItemInArray; /** * */ -public class MatchedFiltersTests extends AbstractSharedClusterTest { +public class MatchedQueriesTests extends AbstractSharedClusterTest { @Test - public void simpleMatchedFilterFromFilteredQuery() throws Exception { + public void simpleMatchedQueryFromFilteredQuery() throws Exception { client().admin().indices().prepareCreate("test").execute().actionGet(); client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet(); @@ -69,11 +69,11 @@ public class MatchedFiltersTests extends AbstractSharedClusterTest { assertThat(searchResponse.getHits().totalHits(), equalTo(3l)); for (SearchHit hit : searchResponse.getHits()) { if (hit.id().equals("1") || hit.id().equals("2")) { - assertThat(hit.matchedFilters().length, equalTo(1)); - assertThat(hit.matchedFilters(), hasItemInArray("test1")); + assertThat(hit.matchedQueries().length, equalTo(1)); + assertThat(hit.matchedQueries(), hasItemInArray("test1")); } else if (hit.id().equals("3")) { - assertThat(hit.matchedFilters().length, equalTo(1)); - assertThat(hit.matchedFilters(), hasItemInArray("test2")); + assertThat(hit.matchedQueries().length, equalTo(1)); + assertThat(hit.matchedQueries(), hasItemInArray("test2")); } else { fail("Unexpected document returned with id " + hit.id()); } @@ -88,11 +88,11 @@ public class MatchedFiltersTests extends AbstractSharedClusterTest { assertThat(searchResponse.getHits().totalHits(), equalTo(3l)); for (SearchHit hit : searchResponse.getHits()) { if (hit.id().equals("1") || hit.id().equals("2")) { - assertThat(hit.matchedFilters().length, equalTo(1)); - assertThat(hit.matchedFilters(), hasItemInArray("test1")); + assertThat(hit.matchedQueries().length, equalTo(1)); + assertThat(hit.matchedQueries(), hasItemInArray("test1")); } else if (hit.id().equals("3")) { - assertThat(hit.matchedFilters().length, equalTo(1)); - assertThat(hit.matchedFilters(), hasItemInArray("test2")); + assertThat(hit.matchedQueries().length, equalTo(1)); + assertThat(hit.matchedQueries(), hasItemInArray("test2")); } else { fail("Unexpected document returned with id " + hit.id()); } @@ -100,7 +100,7 @@ public class MatchedFiltersTests extends AbstractSharedClusterTest { } @Test - public void simpleMatchedFilterFromTopLevelFilter() throws Exception { + public void simpleMatchedQueryFromTopLevelFilter() throws Exception { client().admin().indices().prepareCreate("test").execute().actionGet(); client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet(); @@ -132,12 +132,12 @@ public class MatchedFiltersTests extends AbstractSharedClusterTest { for (SearchHit hit : searchResponse.getHits()) { if (hit.id().equals("1")) { - assertThat(hit.matchedFilters().length, equalTo(2)); - assertThat(hit.matchedFilters(), hasItemInArray("name")); - assertThat(hit.matchedFilters(), hasItemInArray("title")); + assertThat(hit.matchedQueries().length, equalTo(2)); + assertThat(hit.matchedQueries(), hasItemInArray("name")); + assertThat(hit.matchedQueries(), hasItemInArray("title")); } else if (hit.id().equals("2") || hit.id().equals("3")) { - assertThat(hit.matchedFilters().length, equalTo(1)); - assertThat(hit.matchedFilters(), hasItemInArray("name")); + assertThat(hit.matchedQueries().length, equalTo(1)); + assertThat(hit.matchedQueries(), hasItemInArray("name")); } else { fail("Unexpected document returned with id " + hit.id()); } @@ -155,12 +155,12 @@ public class MatchedFiltersTests extends AbstractSharedClusterTest { for (SearchHit hit : searchResponse.getHits()) { if (hit.id().equals("1")) { - assertThat(hit.matchedFilters().length, equalTo(2)); - assertThat(hit.matchedFilters(), hasItemInArray("name")); - assertThat(hit.matchedFilters(), hasItemInArray("title")); + assertThat(hit.matchedQueries().length, equalTo(2)); + assertThat(hit.matchedQueries(), hasItemInArray("name")); + assertThat(hit.matchedQueries(), hasItemInArray("title")); } else if (hit.id().equals("2") || hit.id().equals("3")) { - assertThat(hit.matchedFilters().length, equalTo(1)); - assertThat(hit.matchedFilters(), hasItemInArray("name")); + assertThat(hit.matchedQueries().length, equalTo(1)); + assertThat(hit.matchedQueries(), hasItemInArray("name")); } else { fail("Unexpected document returned with id " + hit.id()); } @@ -168,7 +168,7 @@ public class MatchedFiltersTests extends AbstractSharedClusterTest { } @Test - public void simpleMatchedFilterFromTopLevelFilterAndFilteredQuery() throws Exception { + public void simpleMatchedQueryFromTopLevelFilterAndFilteredQuery() throws Exception { client().admin().indices().prepareCreate("test").execute().actionGet(); client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet(); @@ -200,9 +200,9 @@ public class MatchedFiltersTests extends AbstractSharedClusterTest { for (SearchHit hit : searchResponse.getHits()) { if (hit.id().equals("1") || hit.id().equals("2") || hit.id().equals("3")) { - assertThat(hit.matchedFilters().length, equalTo(2)); - assertThat(hit.matchedFilters(), hasItemInArray("name")); - assertThat(hit.matchedFilters(), hasItemInArray("title")); + assertThat(hit.matchedQueries().length, equalTo(2)); + assertThat(hit.matchedQueries(), hasItemInArray("name")); + assertThat(hit.matchedQueries(), hasItemInArray("title")); } else { fail("Unexpected document returned with id " + hit.id()); } @@ -218,9 +218,9 @@ public class MatchedFiltersTests extends AbstractSharedClusterTest { for (SearchHit hit : searchResponse.getHits()) { if (hit.id().equals("1") || hit.id().equals("2") || hit.id().equals("3")) { - assertThat(hit.matchedFilters().length, equalTo(2)); - assertThat(hit.matchedFilters(), hasItemInArray("name")); - assertThat(hit.matchedFilters(), hasItemInArray("title")); + assertThat(hit.matchedQueries().length, equalTo(2)); + assertThat(hit.matchedQueries(), hasItemInArray("name")); + assertThat(hit.matchedQueries(), hasItemInArray("title")); } else { fail("Unexpected document returned with id " + hit.id()); }