Hi Eric, Thanks for the answer.. This does works for me in most cases..
I am actually new to lucene and still getting acquainted to the various features exposed by it. When I looked at the API of IndexSearcher I thought that it is the purpose of the filter class to filter the returned result set. So : public TopDocs search(Weight weight, Filter filter, int nDocs) throws IOException { So my thinking was that there should be some Filter available in lucene which would filter out the resultset on match on a field. I think the reason this functionality is not there in Lucene is because searching a subset of the index will be much faster - and this can be specified in BooleanQuery. However what if I have a use case where I want to score documents on all the fields but filter them later on on certian fields ? How shoudl I handle this in Lucene ? -amg On Sat, Jan 22, 2011 at 12:32 PM, Erick Erickson <erickerick...@gmail.com> wrote: > I guess I don't see what the problem is. These look to me like > standard Lucene query syntax options. If I'm off base here, > let me know. > > If you're building your own BooleanQuery, > you can add these as sub-clauses > > Here's the Lucene query syntax: > http://lucene.apache.org/java/2_9_1/queryparsersyntax.html > > See below > > Best > Erick > > On Sat, Jan 22, 2011 at 2:32 PM, amg qas <amg...@gmail.com> wrote: > >> Hi, >> >> I have couple of questions on filtering result set while performing a >> search in lucene index : >> >> 1) I want to filter the document set returned when searching an index >> based on a match on a particular field. >> For eg if I have a Field in my index called CompanyName - then while >> searching for documents that match >> some query I want to restict the result set to only those documents >> where CompanyName = 'Foo'. I looked >> at the existing Filters in Lucene and could not figure out a way to >> accomplish this using any of those filters. >> >> > Add a clause +CompanyName:foo > > >> 2) Filter result set on a collection of values - for eg in the case >> mentioned in 1 can I filter documents >> where CompanyName = 'Foo' OR 'Bar' OR 'FooBar'. >> >> Add a clause like +CompanyName:(Foo Bar) > > >> 3) Filter result set on multiple fields - for eg if my index has the >> fields CompanyName & Location - >> can I filter documents where CompanyName = 'Foo' & Location = 'Arizona'. >> >> +CompanyName:Foo +Location:Arizona > > >> 4) Filter result set on multiple fileds on collection of values for >> each field - for eg if my index has the fields >> CompanyName & Location - can I filter documents where (CompanyName = >> 'Foo' OR 'Bar') & (Location = 'Arizona' >> OR 'Washington'). >> >> +CompanyName:(Foo Bar) +Location:(Arizona Washington) > > >> Thanks, >> -amg >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org >> For additional commands, e-mail: java-user-h...@lucene.apache.org >> >> > --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org For additional commands, e-mail: java-user-h...@lucene.apache.org