简体   繁体   中英

Solr/Lucene get the field in which the result is found

When I query multiple fields for a string, is it possible to retrieve information in which field the query term was found ?

I want to query description, information, additional information ... But then I need to know which field gave the result As I want to give different layouts.

Lucene way: look at IndexSearcher.explain(...) . This will give an Explanation that describes how doc scored against query .

Solr way: add &debugQuery=true . I queried for collection:61 and got this document:

<doc>
  <str name="collection">61</str>
  ...other fields...
  <long name="uuid">1111</long>
</doc>

And then below comes this

<lst name="explain">
  <str name="1111">
     0.882217 = (MATCH) fieldWeight(collection:61 in 0), product of: 1.0 =
     tf(termFreq(collection:61)=1) 0.882217 = idf(docFreq=8, maxDocs=8) 1.0 =
     fieldNorm(field=collection, doc=0)
  </str>
  ...
 </lst>

Above basically tells that item 1111 had field collection with value 61 . You can also request for debug.explain.structured to get this explanation string in a more structured format.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM