Deprecate the method names `namedFilter` in favor of `namedQueries`.
The reason behind this is that the `_name` support has been extended to queries as well and the name `namedQueries` suggests better that it is applicable to the whole query dsl. Relates to #3581
This commit is contained in:
parent
2767c081cd
commit
29ea6b3071
|
@ -174,15 +174,27 @@ public interface SearchHit extends Streamable, ToXContent, Iterable<SearchHitFie
|
|||
Object[] getSortValues();
|
||||
|
||||
/**
|
||||
* The set of filter names the query matched. Mainly makes sense for OR filters.
|
||||
* @deprecated In favor for {@link #matchedQueries()}.
|
||||
*/
|
||||
@Deprecated
|
||||
String[] matchedFilters();
|
||||
|
||||
/**
|
||||
* The set of filter names the query matched. Mainly makes sense for OR filters.
|
||||
* @deprecated In favor for {@link #getMatchedQueries()}.
|
||||
*/
|
||||
@Deprecated
|
||||
String[] getMatchedFilters();
|
||||
|
||||
/**
|
||||
* The set of query and filter names the query matched. Mainly makes sense for compound filters and queries.
|
||||
*/
|
||||
String[] matchedQueries();
|
||||
|
||||
/**
|
||||
* The set of query and filter names the query matched. Mainly makes sense for compound filters and queries.
|
||||
*/
|
||||
String[] getMatchedQueries();
|
||||
|
||||
/**
|
||||
* The shard of the search hit.
|
||||
*/
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.elasticsearch.search.dfs.DfsPhase;
|
|||
import org.elasticsearch.search.facet.FacetModule;
|
||||
import org.elasticsearch.search.fetch.FetchPhase;
|
||||
import org.elasticsearch.search.fetch.explain.ExplainFetchSubPhase;
|
||||
import org.elasticsearch.search.fetch.matchedfilters.MatchedFiltersFetchSubPhase;
|
||||
import org.elasticsearch.search.fetch.matchedfilters.MatchedQueriesFetchSubPhase;
|
||||
import org.elasticsearch.search.fetch.partial.PartialFieldsFetchSubPhase;
|
||||
import org.elasticsearch.search.fetch.script.ScriptFieldsFetchSubPhase;
|
||||
import org.elasticsearch.search.fetch.source.FetchSourceSubPhase;
|
||||
|
@ -63,7 +63,7 @@ public class SearchModule extends AbstractModule implements SpawnModules {
|
|||
bind(PartialFieldsFetchSubPhase.class).asEagerSingleton();
|
||||
bind(FetchSourceSubPhase.class).asEagerSingleton();
|
||||
bind(VersionFetchSubPhase.class).asEagerSingleton();
|
||||
bind(MatchedFiltersFetchSubPhase.class).asEagerSingleton();
|
||||
bind(MatchedQueriesFetchSubPhase.class).asEagerSingleton();
|
||||
bind(HighlightPhase.class).asEagerSingleton();
|
||||
|
||||
bind(SearchServiceTransportAction.class).asEagerSingleton();
|
||||
|
|
|
@ -33,7 +33,7 @@ import org.elasticsearch.search.SearchHitField;
|
|||
import org.elasticsearch.search.SearchParseElement;
|
||||
import org.elasticsearch.search.SearchPhase;
|
||||
import org.elasticsearch.search.fetch.explain.ExplainFetchSubPhase;
|
||||
import org.elasticsearch.search.fetch.matchedfilters.MatchedFiltersFetchSubPhase;
|
||||
import org.elasticsearch.search.fetch.matchedfilters.MatchedQueriesFetchSubPhase;
|
||||
import org.elasticsearch.search.fetch.partial.PartialFieldsFetchSubPhase;
|
||||
import org.elasticsearch.search.fetch.script.ScriptFieldsFetchSubPhase;
|
||||
import org.elasticsearch.search.fetch.source.FetchSourceContext;
|
||||
|
@ -59,9 +59,9 @@ public class FetchPhase implements SearchPhase {
|
|||
|
||||
@Inject
|
||||
public FetchPhase(HighlightPhase highlightPhase, ScriptFieldsFetchSubPhase scriptFieldsPhase, PartialFieldsFetchSubPhase partialFieldsPhase,
|
||||
MatchedFiltersFetchSubPhase matchFiltersPhase, ExplainFetchSubPhase explainPhase, VersionFetchSubPhase versionPhase,
|
||||
MatchedQueriesFetchSubPhase matchedQueriesPhase, ExplainFetchSubPhase explainPhase, VersionFetchSubPhase versionPhase,
|
||||
FetchSourceSubPhase fetchSourceSubPhase) {
|
||||
this.fetchSubPhases = new FetchSubPhase[]{scriptFieldsPhase, partialFieldsPhase, matchFiltersPhase, explainPhase, highlightPhase,
|
||||
this.fetchSubPhases = new FetchSubPhase[]{scriptFieldsPhase, partialFieldsPhase, matchedQueriesPhase, explainPhase, highlightPhase,
|
||||
fetchSourceSubPhase, versionPhase};
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ import java.util.Map;
|
|||
/**
|
||||
*
|
||||
*/
|
||||
public class MatchedFiltersFetchSubPhase implements FetchSubPhase {
|
||||
public class MatchedQueriesFetchSubPhase implements FetchSubPhase {
|
||||
|
||||
@Override
|
||||
public Map<String, ? extends SearchParseElement> parseElements() {
|
||||
|
@ -65,16 +65,16 @@ public class MatchedFiltersFetchSubPhase implements FetchSubPhase {
|
|||
public void hitExecute(SearchContext context, HitContext hitContext) throws ElasticSearchException {
|
||||
List<String> 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<String, Filter> namedFilters, List<String> matchedFilters) {
|
||||
private void addMatchedQueries(HitContext hitContext, ImmutableMap<String, Filter> namedFilters, List<String> matchedFilters) {
|
||||
for (Map.Entry<String, Filter> entry : namedFilters.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
Filter filter = entry.getValue();
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
Loading…
Reference in New Issue