Hi,
I successfully implemented facet search with hibernate search. Now, I want to restrict (or filter) my results, but I don't know how to do this.
Let's say, I have entities with some values. When I do faceted search I want to get the results (facet values) of a subset of entities (f.ex. entityID in (....)).
My code looks like this:
Code:
List<String> restrictedEntityIDs = ... //get the list of entity ids which should be used to search the facet values
FullTextSession fullTextSession = ...
SearchFactory searchFactory = fullTextSession.getSearchFactory();
QueryBuilder queryBuilder = searchFactory.buildQueryBuilder().forEntity(Entity.class).get();
Query luceneQuery = ...; // build the lucene query
FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(luceneQuery, Entity.class);
// this does not work
if (!restrictedEntityIDs .isEmpty()) {
Criteria restricted = fullTextSession.createCriteria(Entity.class).add(Restrictions.in("ID", restrictedEntityIDs));
fullTextQuery.setCriteriaQuery(restricted);
}
FacetingRequest facetingRequest = queryBuilder.facet().name("facet").onField("property")
.discrete().orderedBy(FacetSortOrder.COUNT_DESC).includeZeroCounts(false).createFacetingRequest();
FacetManager facetManager = fullTextQuery.getFacetManager();
facetManager.enableFaceting(facetingRequest);
List<Facet> facets = facetManager.getFacets("facet");
// this returns the facet values of all entities :(
I also tried to implement a Filter but the Filter cannot get a collection parameter, only a single value.
Do you have an idea how to solve this?
Thanks and regards, jacquipre.