Rob, It looks like you want to do a full text search of names, but with results restricted to an arbitrary subset of the full corpus with the subset containing a person's friends based on a match on user id. Is that a correct assessment?
There are a few ways to achieve this - * BooleanQuery Approach Use two clauses: one forthe 'DisplayName' field to match the text, another with a BooleanQuery that is an OR of all of the potential user ids. This is fairly simple to construct, but if you have more than a handful of user ids it will perform poorly. One thing to note is that I would advise against a leading wildcard as it is very heavy and will cause you to walk over _all_ of the terms in the field - trailing wild card has a similar effect depending on how many terms match the wild card. * Terms Filter Approach There is a filter in the Java contrib section called TermsFilter (under contrib\queries\) which creates a filter from a list of terms. There is not an equivalent in the Lucene.Net contrib yet, however creating a .Net version is fairly simple. I've done something similar to that to implement a similar use case, and the filter is used to filter the results to just the user ids that match those in your criteria. This is fairly performant when coupled with an index schema with at least two fields - one for the display name and the other for the user id - plus any other data you may need to search. Michael -----Original Message----- From: Robert Pohl [mailto:robba...@gmail.com] Sent: Tuesday, December 15, 2009 10:48 AM To: lucene-net-user@incubator.apache.org Subject: Equiv. to where in(ids) Hi, I'm constructing a query where I want to search for members that are your friends (in a social network). And I'm not sure how construct the search that look for a member name which need to have an ID that is A or B or C. I would do that in SQL like this: select *from members where username like '%rob%' and ID in(select Id from friends) The problem: The problem is that the query must match ALL ids. I want it to match ANY id. My code: String[] fields = searchQuery.Split(' '); QueryParser qp = new QueryParser("DisplayName", new StandardAnalyzer()); BooleanQuery query = new BooleanQuery(); foreach (string s in fields) { query.Add(qp.Parse(s), BooleanClause.Occur.SHOULD); } if(memberIds != null) // List<int> with friend id's { foreach (int id in memberIds) { QueryParser qp2 = new QueryParser("Id", new StandardAnalyzer()); Query q2 = qp2.Parse(id.ToString()); qp2.SetDefaultOperator(QueryParser.Operator.OR); BooleanClause bc = new BooleanClause(q2, BooleanClause.Occur.MUST); query.Add(bc); } Thanks, Rob