@Override
 public Explanation explain(int docId, Explanation subQueryExpl) {
   float score = score(docId, subQueryExpl.getValue());
   Explanation exp = new Explanation(score, "script score function: product of:");
   exp.addDetail(subQueryExpl);
   return exp;
 }
  @Override
  public Explanation explain(AtomicReaderContext context, int doc) throws IOException {
    Scorer scorer = scorer(context, true, false, context.reader().getLiveDocs());
    if (scorer != null) {
      int newDoc = scorer.advance(doc);
      if (newDoc == doc) {
        float freq = scorer.freq();
        SloppySimScorer docScorer = similarity.sloppySimScorer(stats, context);
        ComplexExplanation result = new ComplexExplanation();
        result.setDescription(
            "weight("
                + getQuery()
                + " in "
                + doc
                + ") ["
                + similarity.getClass().getSimpleName()
                + "], result of:");
        Explanation scoreExplanation =
            docScorer.explain(doc, new Explanation(freq, "phraseFreq=" + freq));
        result.addDetail(scoreExplanation);
        result.setValue(scoreExplanation.getValue());
        result.setMatch(true);
        return result;
      }
    }

    return new ComplexExplanation(false, 0.0f, "no matching term");
  }
 @Override
 public Explanation explain(int doc, Explanation freq) {
   Explanation expl = new Explanation(score(doc, freq.getValue()), "sum of:");
   for (SimScorer subScorer : subScorers) {
     expl.addDetail(subScorer.explain(doc, freq));
   }
   return expl;
 }
示例#4
0
 @Override
 public final Explanation explain(BasicStats stats) {
   return Explanation.match(
       lambda(stats),
       getClass().getSimpleName() + ", computed from: ",
       Explanation.match(stats.getDocFreq(), "docFreq"),
       Explanation.match(stats.getNumberOfDocuments(), "numberOfDocuments"));
 }
 @Override
 public final Explanation explain(BasicStats stats, float tfn) {
   Explanation result = new Explanation();
   result.setDescription(getClass().getSimpleName() + ", computed from: ");
   result.setValue(score(stats, tfn));
   result.addDetail(new Explanation(tfn, "tfn"));
   return result;
 }
  /**
   * This method is no longer an official member of {@link Scorer}, but it is needed by SpanWeight
   * to build an explanation.
   */
  protected Explanation explain(final int doc) throws IOException {
    Explanation tfExplanation = new Explanation();

    int expDoc = advance(doc);

    float phraseFreq = (expDoc == doc) ? freq : 0.0f;
    tfExplanation.setValue(similarity.tf(phraseFreq));
    tfExplanation.setDescription("tf(phraseFreq=" + phraseFreq + ")");

    return tfExplanation;
  }
示例#7
0
 boolean findPayloadBoostInExplanation(Explanation expl) {
   if (expl.getDescription().startsWith("payloadBoost=") && expl.getValue() != 1f) {
     return true;
   } else {
     boolean found = false;
     for (Explanation sub : expl.getDetails()) {
       found |= findPayloadBoostInExplanation(sub);
     }
     return found;
   }
 }
    public Explanation explain(int doc) throws IOException {
      float sc = qWeight * vals.floatVal(doc);

      Explanation result =
          new ComplexExplanation(true, sc, "FunctionQuery(" + func + "), product of:");

      result.addDetail(vals.explain(doc));
      result.addDetail(new Explanation(getBoost(), "boost"));
      result.addDetail(new Explanation(weight.queryNorm, "queryNorm"));
      return result;
    }
示例#9
0
    @Override
    public Explanation explain(IndexReader reader, int doc) {
      // explain query weight
      Explanation queryExpl =
          new ComplexExplanation(true, getValue(), "MatchNoneDocsQuery, product of:");
      if (getBoost() != 1.0f) {
        queryExpl.addDetail(new Explanation(getBoost(), "boost"));
      }
      queryExpl.addDetail(new Explanation(queryNorm, "queryNorm"));

      return queryExpl;
    }
示例#10
0
 public static Explanation readExplanation(StreamInput in) throws IOException {
   float value = in.readFloat();
   String description = in.readString();
   Explanation explanation = new Explanation(value, description);
   if (in.readBoolean()) {
     int size = in.readVInt();
     for (int i = 0; i < size; i++) {
       explanation.addDetail(readExplanation(in));
     }
   }
   return explanation;
 }
  /*
   * (non-Javadoc)
   *
   * @see org.apache.lucene.search.Scorer#explain(int)
   */
  public Explanation explain(int doc) throws IOException {
    // TODO: Work out what a proper explanation would be here?
    Explanation tfExplanation = new Explanation();

    while (next() && doc() < doc) {}

    float phraseFreq = (doc() == doc) ? freq : 0.0f;
    tfExplanation.setValue(getSimilarity().tf(phraseFreq));
    tfExplanation.setDescription("tf(phraseFreq=" + phraseFreq + ")");

    return tfExplanation;
  }
示例#12
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());
    }
  }
示例#13
0
 @Override
 public Explanation explain(LeafReaderContext context, int doc) throws IOException {
   SortedDocValues values = DocValues.getSorted(context.reader(), joinField);
   if (values != null) {
     int segmentOrd = values.getOrd(doc);
     if (segmentOrd != -1) {
       BytesRef joinValue = values.lookupOrd(segmentOrd);
       return Explanation.match(
           queryNorm, "Score based on join value " + joinValue.utf8ToString());
     }
   }
   return Explanation.noMatch("Not a match");
 }
 /*     */ public Explanation customExplain(
     int doc, Explanation subQueryExpl, Explanation valSrcExpl)
     /*     */ throws IOException
       /*     */ {
   /* 154 */ float valSrcScore = 1.0F;
   /* 155 */ if (valSrcExpl != null) {
     /* 156 */ valSrcScore *= valSrcExpl.getValue();
     /*     */ }
   /* 158 */ Explanation exp =
       new Explanation(valSrcScore * subQueryExpl.getValue(), "custom score: product of:");
   /* 159 */ exp.addDetail(subQueryExpl);
   /* 160 */ exp.addDetail(valSrcExpl);
   /* 161 */ return exp;
   /*     */ }
示例#15
0
 public static void writeExplanation(StreamOutput out, Explanation explanation)
     throws IOException {
   out.writeFloat(explanation.getValue());
   out.writeString(explanation.getDescription());
   Explanation[] subExplanations = explanation.getDetails();
   if (subExplanations == null) {
     out.writeBoolean(false);
   } else {
     out.writeBoolean(true);
     out.writeVInt(subExplanations.length);
     for (Explanation subExp : subExplanations) {
       writeExplanation(out, subExp);
     }
   }
 }
 private void buildExplanation(XContentBuilder builder, Explanation explanation)
     throws IOException {
   builder.startObject();
   builder.field(Fields.VALUE, explanation.getValue());
   builder.field(Fields.DESCRIPTION, explanation.getDescription());
   Explanation[] innerExps = explanation.getDetails();
   if (innerExps != null) {
     builder.startArray(Fields.DETAILS);
     for (Explanation exp : innerExps) {
       buildExplanation(builder, exp);
     }
     builder.endArray();
   }
   builder.endObject();
 }
 public Explanation explain(int docBase) throws IOException {
   int start = docBase + prevParentDoc + 1; // +1 b/c prevParentDoc is previous parent doc
   int end = docBase + parentDoc - 1; // -1 b/c parentDoc is parent doc
   return Explanation.match(
       score(),
       String.format(Locale.ROOT, "Score based on child doc range from %d to %d", start, end));
 }
 @Override
 protected Explanation explain(int doc) throws IOException {
   Explanation result = new Explanation();
   // Add detail about tf/idf...
   Explanation nonPayloadExpl = super.explain(doc);
   result.addDetail(nonPayloadExpl);
   // Add detail about payload
   Explanation payloadExpl = function.explain(doc, payloadsSeen, payloadScore);
   result.addDetail(payloadExpl);
   result.setValue(nonPayloadExpl.getValue() * payloadExpl.getValue());
   result.setDescription("PayloadNearQuery, product of:");
   return result;
 }
 @Override
 public Explanation explain(LeafReaderContext context, int doc) throws IOException {
   BlockJoinScorer scorer = (BlockJoinScorer) scorer(context);
   if (scorer != null && scorer.iterator().advance(doc) == doc) {
     return scorer.explain(context.docBase);
   }
   return Explanation.noMatch("Not a match");
 }
 @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();
     }
   }
 }
  @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;
  }
 @Override
 public Explanation explain(LeafReaderContext context, int doc) throws IOException {
   SortedDocValues values = DocValues.getSorted(context.reader(), joinField);
   if (values != null) {
     int segmentOrd = values.getOrd(doc);
     if (segmentOrd != -1) {
       final float score;
       if (globalOrds != null) {
         long globalOrd = globalOrds.getGlobalOrds(context.ord).get(segmentOrd);
         score = collector.score((int) globalOrd);
       } else {
         score = collector.score(segmentOrd);
       }
       BytesRef joinValue = values.lookupOrd(segmentOrd);
       return Explanation.match(score, "Score based on join value " + joinValue.utf8ToString());
     }
   }
   return Explanation.noMatch("Not a match");
 }
示例#23
0
  @Override
  protected Explanation createExplain(Explanation innerExplain, IndexReader reader, int doc)
      throws IOException {
    if (reader instanceof BoboIndexReader) {
      Explanation finalExpl = new Explanation();
      finalExpl.addDetail(innerExplain);

      _func.initializeReader((BoboIndexReader) reader, _jsonParam);

      float innerValue = innerExplain.getValue();
      float value = 0;
      if (_func.useInnerScore()) value = _func.newScore(innerValue, doc);
      else value = _func.newScore(doc);

      finalExpl.setValue(value);
      finalExpl.setDescription("Custom score: " + _func.getExplainString(innerValue, doc));
      return finalExpl;
    } else {
      throw new IllegalStateException("reader not instance of " + BoboIndexReader.class);
    }
  }
 /*     */ public Explanation customExplain(
     int doc, Explanation subQueryExpl, Explanation[] valSrcExpls)
     /*     */ throws IOException
       /*     */ {
   /* 124 */ if (valSrcExpls.length == 1) {
     /* 125 */ return customExplain(doc, subQueryExpl, valSrcExpls[0]);
     /*     */ }
   /* 127 */ if (valSrcExpls.length == 0) {
     /* 128 */ return subQueryExpl;
     /*     */ }
   /* 130 */ float valSrcScore = 1.0F;
   /* 131 */ for (int i = 0; i < valSrcExpls.length; i++) {
     /* 132 */ valSrcScore *= valSrcExpls[i].getValue();
     /*     */ }
   /* 134 */ Explanation exp =
       new Explanation(valSrcScore * subQueryExpl.getValue(), "custom score: product of:");
   /* 135 */ exp.addDetail(subQueryExpl);
   /* 136 */ for (int i = 0; i < valSrcExpls.length; i++) {
     /* 137 */ exp.addDetail(valSrcExpls[i]);
     /*     */ }
   /* 139 */ return exp;
   /*     */ }
 /**
  * Returns an explanation for the normalized term frequency.
  *
  * <p>The default normalization methods use the field length of the document and the average field
  * length to compute the normalized term frequency. This method provides a generic explanation for
  * such methods. Subclasses that use other statistics must override this method.
  */
 public Explanation explain(BasicStats stats, float tf, float len) {
   Explanation result = new Explanation();
   result.setDescription(getClass().getSimpleName() + ", computed from: ");
   result.setValue(tfn(stats, tf, len));
   result.addDetail(new Explanation(tf, "tf"));
   result.addDetail(new Explanation(stats.getAvgFieldLength(), "avgFieldLength"));
   result.addDetail(new Explanation(len, "len"));
   return result;
 }
示例#26
0
 public Explanation explain(int doc) throws IOException {
   Explanation subQueryExpl = weight.qWeight.explain(reader, doc);
   if (!subQueryExpl.isMatch()) {
     return subQueryExpl;
   }
   float sc = subQueryExpl.getValue() * vals.floatVal(doc);
   Explanation res =
       new ComplexExplanation(true, sc, BoostedQuery.this.toString() + ", product of:");
   res.addDetail(subQueryExpl);
   res.addDetail(vals.explain(doc));
   return res;
 }
示例#27
0
 private Explanation doExplain(IndexReader reader, int doc) throws IOException {
   Explanation subQueryExpl = subQueryWeight.explain(reader, doc);
   if (!subQueryExpl.isMatch()) {
     return subQueryExpl;
   }
   // match
   Explanation[] valSrcExpls = new Explanation[valSrcWeights.length];
   for (int i = 0; i < valSrcWeights.length; i++) {
     valSrcExpls[i] = valSrcWeights[i].explain(reader, doc);
   }
   Explanation customExp =
       CustomScoreQuery.this
           .getCustomScoreProvider(reader)
           .customExplain(doc, subQueryExpl, valSrcExpls);
   float sc = getValue() * customExp.getValue();
   Explanation res =
       new ComplexExplanation(true, sc, CustomScoreQuery.this.toString() + ", product of:");
   res.addDetail(customExp);
   res.addDetail(
       new Explanation(
           getValue(),
           "queryBoost")); // actually using the q boost as q weight (== weight value)
   return res;
 }
示例#28
0
      @Override
      protected Explanation explain(final int doc) throws IOException {
        ComplexExplanation result = new ComplexExplanation();
        Explanation nonPayloadExpl = super.explain(doc);
        result.addDetail(nonPayloadExpl);
        // QUESTION: Is there a way to avoid this skipTo call? We need to know
        // whether to load the payload or not
        Explanation payloadBoost = new Explanation();
        result.addDetail(payloadBoost);

        float payloadScore = getPayloadScore();
        payloadBoost.setValue(payloadScore);
        // GSI: I suppose we could toString the payload, but I don't think that
        // would be a good idea
        payloadBoost.setDescription("scorePayload(...)");
        result.setValue(nonPayloadExpl.getValue() * payloadScore);
        result.setDescription("btq, product of:");
        result.setMatch(
            nonPayloadExpl.getValue() == 0 ? Boolean.FALSE : Boolean.TRUE); // LUCENE-1303
        return result;
      }
示例#29
0
    @Override
    public Explanation explain(IndexReader reader, int doc) throws IOException {
      SolrIndexReader topReader = (SolrIndexReader) reader;
      SolrIndexReader[] subReaders = topReader.getLeafReaders();
      int[] offsets = topReader.getLeafOffsets();
      int readerPos = SolrIndexReader.readerIndex(doc, offsets);
      int readerBase = offsets[readerPos];

      Explanation subQueryExpl = qWeight.explain(reader, doc);
      if (!subQueryExpl.isMatch()) {
        return subQueryExpl;
      }

      DocValues vals = boostVal.getValues(context, subReaders[readerPos]);
      float sc = subQueryExpl.getValue() * vals.floatVal(doc - readerBase);
      Explanation res =
          new ComplexExplanation(true, sc, BoostedQuery.this.toString() + ", product of:");
      res.addDetail(subQueryExpl);
      res.addDetail(vals.explain(doc - readerBase));
      return res;
    }
示例#30
0
 /**
  * Explains the score. Returns the name of the model only, since both {@code tfn} and {@code
  * lambda} are explained elsewhere.
  */
 public Explanation explain(BasicStats stats, float tfn, float lambda) {
   return Explanation.match(score(stats, tfn, lambda), getClass().getSimpleName());
 }