1

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?

Febin J S
  • 1,358
  • 3
  • 26
  • 53

1 Answers1

2

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.

bentayloruk
  • 4,060
  • 29
  • 31
  • So for checking in multiple index field do i have to use multiple overloads ? or is there any way of checking for a query in multiple fields in a single statement? – Febin J S May 23 '11 at 12:57
  • You can use the single overload. However, I not 100% sure if this is what you want. Here is an example: MultiFieldQueryParser.Parse(new[] { query }, new[] { "Name", "Description"}, new[] { BooleanClause.Occur.SHOULD, BooleanClause.Occur.SHOULD }, new StandardAnalyzer()); – bentayloruk May 23 '11 at 13:02
  • Have you tried this answer [Lucene QueryParser two fields](http://stackoverflow.com/questions/2005084/lucene-queryparser-two-fields)? Looks like your question may be a dupe. – bentayloruk May 23 '11 at 13:12