You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Van Nguyen <vn...@ur.com> on 2006/12/09 00:49:09 UTC

Filter question

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:
CachingWrapperFilter(QueryFilter())

 

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

            }

            else

            {

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

            }

 

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

 


Re: Filter question

Posted by Chris Hostetter <ho...@fucit.org>.
: 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:
: CachingWrapperFilter(QueryFilter())
	...
: will result in no results.  If there are no criteria in the filter,
: shouldn't that return all the results based on the query?

No.  If you filter a query, the filter defines the super set of all
results you can get back -- if you have a filter that matches nothing,
then you can't get anything back.





-Hoss


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org