chriseldredge / Lucene.Net.Linq

LINQ provider to run native queries on a Lucene.Net index
Other
151 stars 65 forks source link

Search on arbitrary number of homogenous terms / foo.Contains(x.Id) #45

Closed cherrydev closed 10 years ago

cherrydev commented 11 years ago

If I try to do queriable.Where(x => listOfValues.Contains(x.Value)) I get an exception:

The binary operator Equal is not defined for the types 'System.String[]' and 'System.String'.

I wonder if there's a way to special-case this into a multi-term query, which should run efficiently in Lucene (although subject to the term limit, of course).

chriseldredge commented 11 years ago

Can you provide sample code that would construct a multi-term query using a list of values?

chriseldredge commented 10 years ago

I'm not sure how to implement this. If you have suggestions, feel free to reopen.

cherrydev commented 10 years ago

Ya, I tried to fuss around with this to get some sort of efficient implementation, but it appears that Lucene is simply terrible at this particular use-case. The naive implementation of constructing a long string of 'or' terms actually performs terribly on any field that has a cardinality of n (a unique field). The fastest implementation I settled on was to sort the terms, open a termdocs() on the first term, get the docID(s) and then seek to the next, etc. I don't see how that implementation could be generalized for use in Lucene.Net.Linq though.