Febin J S
Febin J S

Reputation: 1368

How to pass multiple fields in Queryparser in Lucene?

Can i pass multiple index fields in a Querparser in Lucene? I have done something like this

  QueryParser queryParser =  MultiFieldQueryParser.Parse(new[] { query }, new[] { "Name", "Description", "ExternalIdentifier", "OriginalFileName", "Text" }, new StandardAnalyzer());
  queryParser.setDefaultOperator(QueryParser.Operator.AND);

But it shows some error? i am little bit confused can anybody give me a help?

Upvotes: 1

Views: 1648

Answers (1)

bentayloruk
bentayloruk

Reputation: 4101

The documentation for the specific overload of MultiFieldQueryParser.Parse that you are using states the following:

IllegalArgumentException - if the length of the queries, fields, and flags array differ.

I suspect you are getting this exception as you have one query and 5 fields. If this is the method that you want to use, you must provide an array of queries with a length of five.

You may want to use a different parse overload, which will take a single query but multiple fields and flags.

Upvotes: 2

Related Questions