I have a query that uses a filter... looking something like this:

BooleanQuery filterQuery = new BooleanQuery();

// add criteria

QueryFilter qf = new QueryFilter(filterQuery);

CachingWrapperFilter cwf = new CachingWrapperFilter(qf);

BooleanQuery query = new BooleanQuery();

// add criteria

// cached searcher

searcher = index.getSearcher();

Sort sort = new Sort();

Hits = searcher.search(query, cwf, sort);

That works fine if there are some criteria in filterQuery and query.
But sometimes, the bean I'm passing in will not pass any criteria into
the filterQuery part. If that's the case, cwf looks like this:

Passing that into the Hits = searcher.search(query, cwf, sort) method
will result in no results. If there are no criteria in the filter,
shouldn't that return all the results based on the query?

For now... I've resorted to doing this:

Hits hits = null;

if(Validate.isEmpty(filterQuery.toString())) // own
method to check if

{ //
string is null or empty

hits = searcher.search(query, sort);


else if(Validate.isEmpty(query.toString()))


hits = searcher.search(filterQuery, sort);




hits = searcher.search(query, cwf, sort);


Is this the best way to go about this?? Or is there a more elegant way?

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 2 | next ›
Discussion Overview
groupjava-user @
postedDec 8, '06 at 11:49p
activeDec 9, '06 at 8:07a

2 users in discussion

Van Nguyen: 1 post Chris Hostetter: 1 post



site design / logo © 2022 Grokbase