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;
}
}