You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by "Arnone, Anthony" <aa...@rightnow.com> on 2007/11/20 18:42:55 UTC
OR-ing together filter queries
Hello all,
I am writing my own handler, and I would like to pre-filter the results based on a field. I’m calling searcher.getDocList() with a custom constructed query and filters list, but the filters always seem to AND together. My question is this: how can I construct the List<Query> of filters to make them OR together (documents are included in results if they match *any* of my filters)?
For reference, here’s how I’m constructing my filters:
List<Query> filters = new LinkedList<Query>();
. . .
while (fieldIter.hasNext()) {
String filterStr = fieldIter.next();
filters.add(new TermQuery(new Term(accessField, filterStr))); // accessField is known ahead of time
}
. . .
results.docList = s.getDocList(finalQuery, filters.size() != 0 ? filters : null,
Sort.RELEVANCE, start, indexSize, SolrIndexSearcher.GET_SCORES);
Thanks for any help
Anthony
PS: you might notice that I'm asking for ALL of the results in that search. Never fear - I do a lot of post processing myself, and return a sane (~1000) amount of results in JSON.
Re: OR-ing together filter queries
Posted by Chris Hostetter <ho...@fucit.org>.
: I am writing my own handler, and I would like to pre-filter the results
: based on a field. Iÿÿm calling searcher.getDocList() with a custom
: constructed query and filters list, but the filters always seem to AND
: together. My question is this: how can I construct the List<Query> of
: filters to make them OR together (documents are included in results if
: they match *any* of my filters)?
if you want/need your filters to be cached independently, the easiest
thing to do is to loop over each query and call getDocSet ... then union
all of those sets together and pass the resulting DocSet to getDocList()
If you don't want/need your filters to be cached independenty, just
combine all of those TermQueries into a big BooleanQuery.
-Hoss