-->
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.  [ 2 posts ] 
Author Message
 Post subject: Search Filter Returns No Results
PostPosted: Tue Feb 23, 2010 12:08 am 
Newbie

Joined: Mon Oct 19, 2009 5:44 pm
Posts: 6
I have a pretty basic search filter that should filter out any results where that flag is false or '0'. I am using an example from Hibernate Search In Action. After the filter executes I don't get any results at all back. It seems that everything is written right so I'm pretty confused about this. Does anything stand out in my code bellow? Thanks for any help.

FilterFactory
Code:
@Component
public class ActiveArticleFilterFactory {
   
   @Factory
   public Filter getFilter() {
      //some additional steps to cache the filter results per IndexReader
        Filter activeArticleFilter = new ActiveArticleFilter();
        return new CachingWrapperFilter(activeArticleFilter);
   }

}


Filter
Code:
public class ActiveArticleFilter extends Filter {
   
    /**
    * Generated Serial ID
    */
   private static final long serialVersionUID = -4677423449624112706L;

   public DocIdSet getDocIdSet(IndexReader reader) throws IOException {
        OpenBitSet bitSet = new OpenBitSet( reader.maxDoc() );
        TermDocs termDocs = reader.termDocs( new Term( "article.active", "0" ) );
        while ( termDocs.next() ) {
            bitSet.set( termDocs.doc() );
        }
        return bitSet;
    }
}


Query
Code:
@Component
public class SearchHandler {
   
   @Autowired ArticleHandler articleHandler = null;
   
   public HashMap<String,List<?>> basicSearch(String searchString) throws ParseException, ObjectNotFoundException {
      
      List<Article> articles = new ArrayList<Article>();
      List<User> users = new ArrayList<User>();
      
      FullTextSession fullTextSession = Search.getFullTextSession(HibernateSessionFactory.getSession());
         
      // create native Lucene query
      String[] fields = new String[]{"articleTitle", "articleText", "firstName", "lastName", "gamerTag", "active"};
      MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, new StandardAnalyzer());
      org.apache.lucene.search.Query query = parser.parse(searchString);

      // wrap Lucene query in a org.hibernate.Query
      FullTextQuery hibQuery = fullTextSession.createFullTextQuery(query, Article.class, User.class);
      
      hibQuery.enableFullTextFilter("notActive");

      // execute search
      List<?> resultList = hibQuery.list();
      
      for (Object object : resultList) {
         
         if (object instanceof Article) {
            articles.add((Article)object);
         }
         
         if (object instanceof User) {
            users.add((User)object);
         }
      }
      
      HashMap<String,List<?>> results = new HashMap<String, List<?>>();
      
      results.put("Articles", articleHandler.trimArticleText(articles));
      results.put("Users", users);
       
      HibernateSessionFactory.getSession().close();
      
      return results;
      
   }

}


Top
 Profile  
 
 Post subject: Re: Search Filter Returns No Results
PostPosted: Thu Feb 25, 2010 12:31 am 
Newbie

Joined: Mon Oct 19, 2009 5:44 pm
Posts: 6
Does anyone know why the results are coming back empty when this filter is applied? Is this how you would filter a boolean value out of the results?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.