Huzaifa
Huzaifa

Reputation: 1171

How to search an array of search strings with Lucene.Net

I want to know if we can search an array of values for one field in Lucene?

For example:

String s[] = {"John","Daniel", "Doe"---------------------------until 50 or 1000};

All the string values are for FirstName field. Is it possible to search for multiple values in one field without making the operation expensive?

Thanks.

Upvotes: 2

Views: 4367

Answers (1)

rae1
rae1

Reputation: 6144

You can just do,

fieldName: John Daniel Doe ...

All terms will be ORed, so the result set will contain all documents that matched any of the values.

The code to generate such query can be,

var nameValues = new[] { "John", "Daniel", "Doe", ... };
var query = new QueryParser(currentVersion, fieldName, analyzer)
                .Parse(string.Join(" ", nameValues))

Upvotes: 2

Related Questions