Skip to content

Commit

Permalink
HSEARCH-2208 Replace Filter with Query in ElasticsearchHSQueryImpl fi…
Browse files Browse the repository at this point in the history
…ltering code

Because Filter has been deprecated in favor of Query and will be removed.
  • Loading branch information
yrodiere authored and Sanne committed May 9, 2017
1 parent 5cf59a9 commit 7fbc3ec
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
Expand Up @@ -29,7 +29,6 @@
import org.apache.lucene.document.LongField;
import org.apache.lucene.document.StringField;
import org.apache.lucene.search.Explanation;
import org.apache.lucene.search.Filter;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.TopDocs;
Expand Down Expand Up @@ -1141,8 +1140,9 @@ protected JsonObject createFullTextFilter(FilterDef def, Object filterOrFactory)
}

private JsonObject toJsonFilter(Object candidateFilter) {
if ( candidateFilter instanceof Filter ) {
return ToElasticsearch.fromLuceneFilter( (Filter) candidateFilter );
if ( candidateFilter instanceof Query ) {
// This also handles the case where the query extends Filter
return ToElasticsearch.fromLuceneQuery( (Query) candidateFilter );
}
else if ( candidateFilter instanceof ElasticsearchFilter ) {
return JSON_PARSER.parse( ( (ElasticsearchFilter) candidateFilter ).getJsonFilter() ).getAsJsonObject();
Expand Down
Expand Up @@ -16,7 +16,6 @@
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.CachingWrapperQuery;
import org.apache.lucene.search.ConstantScoreQuery;
import org.apache.lucene.search.Filter;
import org.apache.lucene.search.FilteredQuery;
Expand All @@ -39,7 +38,7 @@
import org.hibernate.search.elasticsearch.util.impl.FieldHelper;
import org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity;
import org.hibernate.search.exception.AssertionFailure;
import org.hibernate.search.filter.impl.CachingWrapperFilter;
import org.hibernate.search.filter.impl.CachingWrapperQuery;
import org.hibernate.search.query.dsl.impl.DiscreteFacetRequest;
import org.hibernate.search.query.dsl.impl.FacetRange;
import org.hibernate.search.query.dsl.impl.RangeFacetRequest;
Expand Down Expand Up @@ -247,6 +246,10 @@ else if ( query instanceof CachingWrapperQuery ) {
JsonObject result = fromLuceneQuery( ( (CachingWrapperQuery) query ).getQuery() );
return wrapBoostIfNecessary( result, query.getBoost() );
}
else if ( query instanceof org.apache.lucene.search.CachingWrapperQuery ) {
JsonObject result = fromLuceneQuery( ( (org.apache.lucene.search.CachingWrapperQuery) query ).getQuery() );
return wrapBoostIfNecessary( result, query.getBoost() );
}

throw LOG.cannotTransformLuceneQueryIntoEsQuery( query );
}
Expand Down Expand Up @@ -717,13 +720,10 @@ else if ( luceneFilter instanceof DistanceFilter ) {
else if ( luceneFilter instanceof SpatialHashFilter ) {
return convertSpatialHashFilter( (SpatialHashFilter) luceneFilter );
}
else if ( luceneFilter instanceof CachingWrapperFilter ) {
return fromLuceneFilter( ( (CachingWrapperFilter) luceneFilter ).getCachedFilter() );
}
else if ( luceneFilter instanceof org.apache.lucene.search.CachingWrapperFilter ) {
return fromLuceneFilter( ( (org.apache.lucene.search.CachingWrapperFilter) luceneFilter ).getFilter() );
}
throw LOG.cannotTransformLuceneFilterIntoEsQuery( luceneFilter );
throw LOG.cannotTransformLuceneQueryIntoEsQuery( luceneFilter );
}

/**
Expand Down
Expand Up @@ -10,7 +10,6 @@
import java.util.List;
import java.util.Map;

import org.apache.lucene.search.Filter;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.SortField;
import org.hibernate.search.analyzer.spi.AnalyzerReference;
Expand Down Expand Up @@ -47,10 +46,6 @@ public interface Log extends org.hibernate.search.util.logging.impl.Log {
value = "Lucene query '%1$s' cannot be transformed into equivalent Elasticsearch query" )
SearchException cannotTransformLuceneQueryIntoEsQuery(Query query);

@Message(id = ES_BACKEND_MESSAGES_START_ID + 3,
value = "Lucene filter '%1$s' cannot be transformed into equivalent Elasticsearch query" )
SearchException cannotTransformLuceneFilterIntoEsQuery(Filter filter);

@Message(id = ES_BACKEND_MESSAGES_START_ID + 4,
value = "The sort order RANGE_DEFINITION_ORDER cant not be sent used with Elasticsearch" )
SearchException cannotSendRangeDefinitionOrderToElasticsearchBackend();
Expand Down

0 comments on commit 7fbc3ec

Please sign in to comment.