lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Van Nguyen" <vngu...@ur.com>
Subject Filter question
Date Fri, 08 Dec 2006 23:49:09 GMT
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?

 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message