Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Faceted search: FullTextQuery with IN restriction
PostPosted: Tue Nov 08, 2011 10:49 am 
Beginner
Beginner

Joined: Thu Jan 06, 2011 6:19 am
Posts: 25
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.


Top
 Profile  
 
 Post subject: Re: Faceted search: FullTextQuery with IN restriction
PostPosted: Thu Nov 10, 2011 4:54 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

Code:
    // this does not work
    if (!restrictedEntityIDs .isEmpty()) {
         Criteria restricted = fullTextSession.createCriteria(Entity.class).add(Restrictions.in("ID", restrictedEntityIDs));
         fullTextQuery.setCriteriaQuery(restricted);
     }


Right. It is not supported. You cannot mix Criteria query with full text search queries. At the moment only the fetch mode can be adjusted via the criteria api.

It also looks like that you don't want faceting after all. If you just want to restrict your search results you should either via a BooleanQuery add the restricted entity ids or as you say use a filter. For the latter you should be able to pass any parameter you like. What is your actual use case and what is the problem with the filter?

--Hardy


Top
 Profile  
 
 Post subject: Re: Faceted search: FullTextQuery with IN restriction
PostPosted: Fri Nov 18, 2011 5:11 am 
Beginner
Beginner

Joined: Thu Jan 06, 2011 6:19 am
Posts: 25
Hi and thanks for your answer.

My use case: get facets of entities for a special query, filtered by restricted entity ids. These restricted entity ids could be a list of more than 10000 ids, so I don't know if adding this restriction to the query is not effective enough...?


Top
 Profile  
 
 Post subject: Re: Faceted search: FullTextQuery with IN restriction
PostPosted: Fri Nov 18, 2011 6:24 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
I am still not 100% what your use case is, but looking at your original code I still think you should use a Hibernate Search filter - http://docs.jboss.org/hibernate/stable/ ... ery-filter

--Hardy


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.