How to get Lucene explanation for SolrDocument with Solrj?

I am looking for the Solr index with SolrJ and am trying to get Lucene's explanation for maintaining it for future reference.

The code is as follows:

    SolrServer server = new CommonsHttpSolrServer("solr_url");
    SolrQuery solrquery = new SolrQuery();
    solrquery.set("fl", "score, id"); // id is a String field
    solrquery.set("rows", "1000");
    solrquery.set("debugQuery", "on");
    solrquery.setQuery("query words here");

    try {
        QueryResponse response = server.query(solrquery);
        SolrDocumentList docs = response.getResults();
        Iterator<SolrDocument> dociterator = docs.iterator();

        while (dociterator.hasNext())
        {
            SolrDocument doc = dociterator.next();
            String id = (String) doc.getFirstValue(idfield);
            Float relevance = (Float) doc.getFirstValue("score");
            String explanation = ???;
        }
    } catch (SolrServerException e) {
        e.printStackTrace();
    }

I realized that response.getEplainMap () would contain a map with a value, such as response.getEplainMap (). get (id), but it seems that the explainmap file contains only the null key with the value of the last document found.

Any ideas how to get the right explanation?

+5
source share
3 answers

In my case, there was an error in the Solr index itself. Below is the code below.

Map<String, String> explainmap = response.getExplainMap();
String explanation = explainmap.get(id);

, id, schema.xml(, <uniqueKey>id</uniqueKey>), . id, , , Solr, , , , explainmap null.

+6

? .

QueryResponse getDebugMap() getExplainMap(), . , , , :

<?xml version="1.0" encoding="UTF-8"?>
<response>
  <lst name="responseHeader">
    <int name="status">0</int>
    <int name="QTime">0</int>
    <lst name="params">
      <str name="q">stuff</str>
      <str name="start">0</str>
      <str name="indent">on</str>
      <str name="explainOther"/>
      <str name="wt">standard</str>
      <str name="hl.fl"/>
      <str name="fq"/>
      <str name="version">2.2</str>
      <str name="qt">standard</str>
      <str name="debugQuery">on</str>
      <str name="fl">*,score</str>
      <str name="rows">1</str>
    </lst>
  </lst>
  <result name="response" numFound="79" start="0" maxScore="4.050907">
    <doc>
      <float name="score">4.050907</float>
      ..other bits of data
     </doc>
  </result>
  <lst name="debug">
    <str name="rawquerystring">stuff</str>
    <str name="querystring">stuff</str>
    <str name="parsedquery">MYSEARCHFIELD:stuff</str>
    <str name="parsedquery_toString">MYSEARCHFIELD:stuff</str>
    <lst name="explain">
      <str name="6095">     <--- 6095 is the ID of the document
        4.050907 = (MATCH) fieldWeight(MYSEARCHFIELD:stuff in 1292), product of:
        1.4142135 = tf(termFreq(MYSEARCHFIELD:stuff )=2)
        9.166156 = idf(docFreq=79, maxDocs=281583)
        0.3125 = fieldNorm(field=MYSEARCHFIELD, doc=1292)
      </str>
    </lst>

    ..timing stuff here

  </lst>
</response>
+1

, [explain] ( ) .

+1

All Articles