-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: [SOLVED] Wrong resultSize when using a filter
PostPosted: Mon Mar 22, 2010 10:15 am 
Newbie

Joined: Mon Mar 22, 2010 9:42 am
Posts: 2
EDIT: sorry guys, forgot to enable my filter somewhere. Problem solved :)
If you have any question about filters let me know, mine is working now.



Hello,

So, I'm using a filter in one of my entity to not return outdated events in the result of my search. Here is filter:

Code:
public class OutdatedEventsFilterFactory {

   @Factory
   public Filter getNotOutdatedEventsFilter() {
      String currentDateStr = DateUtil.getTimeStr(new Date());
            
      Query eventClassQuery = new TermQuery(new Term("_hibernate_class", "module.gc.search.model.ResourceEventSearch"));      
      BooleanQuery excludeEventClass = new BooleanQuery();
      excludeEventClass.add(new MatchAllDocsQuery(), Occur.SHOULD);
      excludeEventClass.add(eventClassQuery, Occur.MUST_NOT);
      
      Filter filters[] = new Filter[2];
      filters[0] = new QueryWrapperFilter(excludeEventClass);
      filters[1] = RangeFilter.More("event_end", currentDateStr);      
      
      ChainedFilter cf = new ChainedFilter(filters, ChainedFilter.OR);
      
      return cf;
   }   
}


And I use this class in my model:
Code:
@Indexed
@Entity
@FullTextFilterDef(name="outdatedEventsFilter", impl=OutdatedEventsFilterFactory.class)
public class ResourceEventSearch extends ResourceSearch {

.....



When I search, results are well filtered, I get exactly what I need:
Code:
public List<SearchItem> list(QueryContainer query, int pageSize, int pageIndex) {
      return ftSession
            .createFullTextQuery(query, entities)
            .setProjection(FullTextQuery.DOCUMENT, FullTextQuery.THIS)
            .setMaxResults(pageSize)
            .setFirstResult(pageSize*(pageIndex - 1))
            .enableFullTextFilter("outdatedEventsFilter")
            .list();
   }


The problem is that the getResultSize() always give me the result without the filter. I mean, for example I have 4 events in the result of my search, 3 of them are filtered, so getResultSize() should return 1, but it returns 4...

So, this is not working:

Code:
public List<SearchItem> list(QueryContainer query) {
      return ftSession
            .createFullTextQuery(query, entities)
            .setProjection(FullTextQuery.DOCUMENT, FullTextQuery.THIS)
            .enableFullTextFilter("outdatedEventsFilter")
            .getResultSize();
   }


This problem is very annoying, because I display the number of result to the user. So they see the number of result is wrong. This is especially boring when all event returned by the search are being filtered: user see Events (10 results) but there are no result...

Please, I need your help ;)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.