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:
我正在使用Lucene.Net的MultiFieldQueryParser来搜索文档中的多个字段。我想找出文本找到的字段。例如,我的搜索可能如下所示:
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
我想确定是否在答案或问题字段中找到了searchphrase
2 个解决方案
#1
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.
搜索短语的某些术语可以在问题中找到,其余部分可以在答案中找到。如果您一起搜索问题和答案,则无法轻易确定哪个是哪个。
#2
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.
出于调试目的,您可以使用Lucene的explain()方法,该方法将引导您完成匹配。它与搜索本身一样昂贵,因此对于生产而言并不是那么好。另请参阅Grant Ingersoll在搜索中调试相关性问题,了解获取此信息的其他方法。
#1
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.
搜索短语的某些术语可以在问题中找到,其余部分可以在答案中找到。如果您一起搜索问题和答案,则无法轻易确定哪个是哪个。
#2
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.
出于调试目的,您可以使用Lucene的explain()方法,该方法将引导您完成匹配。它与搜索本身一样昂贵,因此对于生产而言并不是那么好。另请参阅Grant Ingersoll在搜索中调试相关性问题,了解获取此信息的其他方法。