Ejemplo n.º 1
0
  public static void explainQuery(IndexSearcher searcher, Query query) throws IOException {

    TopDocs topDocs = searcher.search(query, 10);

    for (ScoreDoc match : topDocs.scoreDocs) {

      Explanation explanation = searcher.explain(query, match.doc);

      System.out.println("---------------");

      System.out.println(explanation.toString());
    }
  }
Ejemplo n.º 2
0
 @Override
 public void transform(SolrDocument doc, int docid) {
   if (context != null && context.query != null) {
     try {
       Explanation exp = context.searcher.explain(context.query, docid);
       if (style == Style.nl) {
         doc.setField(name, SolrPluginUtils.explanationToNamedList(exp));
       } else if (style == Style.html) {
         doc.setField(name, exp.toHtml());
       } else {
         doc.setField(name, exp.toString());
       }
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
 }
Ejemplo n.º 3
0
  @Override
  public List<T> collectObjects(SearchResponse rsp) {
    SearchHits docs = rsp.getHits();
    List<T> list = new ArrayList<T>(docs.hits().length);
    for (SearchHit sd : docs) {
      if (sd.getExplanation() != null) {
        String res = "";
        for (Explanation str : sd.getExplanation().getDetails()) {
          res += str.toString();
        }
        logger.info(sd.getId() + " " + res);
      }
      T o = readDoc(sd.getId(), sd.getVersion(), sd.getSource());
      if (o != null) list.add(o);
    }

    return list;
  }
Ejemplo n.º 4
0
 /** not a direct test of NearSpans, but a demonstration of how/when this causes problems */
 public void testSpanNearScorerExplain() throws Exception {
   SpanNearQuery q = makeQuery();
   Explanation e = q.weight(searcher).explain(searcher.getIndexReader(), 1);
   assertTrue(
       "Scorer explanation value for doc#1 isn't positive: " + e.toString(), 0.0f < e.getValue());
 }