Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HSEARCH-2242 Convert FacetManager implementation to no longer use Fil…
…ters
- Loading branch information
Showing
6 changed files
with
112 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
engine/src/main/java/org/hibernate/search/query/engine/impl/QueryFilters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.query.engine.impl; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import org.apache.lucene.search.BooleanClause; | ||
import org.apache.lucene.search.BooleanQuery; | ||
import org.apache.lucene.search.Query; | ||
import org.apache.lucene.search.BooleanClause.Occur; | ||
|
||
/** | ||
* Internal representation for a set of filters to be applied on a query. | ||
* | ||
* @author Sanne Grinovero | ||
*/ | ||
public final class QueryFilters { | ||
|
||
public static final QueryFilters EMPTY_FILTERSET = new QueryFilters(); | ||
|
||
private final List<Query> filterQueries; | ||
|
||
private QueryFilters() { | ||
filterQueries = Collections.emptyList(); | ||
} | ||
|
||
public QueryFilters(List<Query> filterQueries) { | ||
this.filterQueries = filterQueries; | ||
} | ||
|
||
/** | ||
* Will wrap the passed Query into a BooleanQuery to apply all filters as boolean clauses. | ||
* Returns the unmodified (same instance) of the input if there are no filters to be applied. | ||
* @param filteredQuery | ||
* @return | ||
*/ | ||
public Query filterOrPassthrough(Query filteredQuery) { | ||
if ( isEmpty() ) { | ||
return filteredQuery; | ||
} | ||
else { | ||
BooleanQuery.Builder boolQueryBuilder = new BooleanQuery.Builder(); | ||
boolQueryBuilder.add( filteredQuery, Occur.MUST ); | ||
for ( Query bc : filterQueries ) { | ||
boolQueryBuilder.add( bc, BooleanClause.Occur.FILTER ); | ||
} | ||
return boolQueryBuilder.build(); | ||
} | ||
} | ||
|
||
/** | ||
* @return lists all Lucene query instances which should be applied as filters | ||
*/ | ||
public List<Query> getFilterQueries() { | ||
return filterQueries; | ||
} | ||
|
||
/** | ||
* @return <tt>true</tt> if this contains to filters to be applied. | ||
*/ | ||
public boolean isEmpty() { | ||
return filterQueries.isEmpty(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters