Java

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • Filter question

    1 answers - 1504 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    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? is there a more elegant way?
  • No.1 | | 785 bytes | |

    : 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 (AT) lucene (DOT) apache.org
    For additional commands, e-mail: java-user-help (AT) lucene (DOT) apache.org

Re: Filter question


max 4000 letters.
Your nickname that display:
In order to stop the spam: 7 + 6 =
QUESTION ON "Java"

EMSDN.COM