views:

485

answers:

2

I'm using Lucene.Net's MultiFieldQueryParser to search multiple fields in my documents. I want to find out which field the text was found. For example, my search might look like this:

var parser = new MultiFieldQueryParser(new string[] {"question","answer"}, analyzer);
var query = parser.Parse(searchphrase);

for(int idx=0; idx<hits.Length() ++idx)
{
     var doc = hits.Doc(i);
     // was this hit found in "answer" or "question"??
}

I want to determine whether searchphrase was found in the answer or question field

+3  A: 

The only way to tell would be to store the fields, retrieve them for each hit, and examine them yourself for a match.

A hit can result from some terms of the search phrase being found in the question, with the rest in the answer. If you search questions and answers together, you can't easily determine which was which.

erickson
A: 

For debugging purposes, you can use Lucene's explain() method, which walks you through the matching. It is as costly as the search itself, so it is not so good for production. See also Debugging Relevance Issues in Search by Grant Ingersoll about other ways to get this information.

Yuval F