Search in sources :

Example 61 with Explanation

use of org.apache.lucene.search.Explanation in project lucene-solr by apache.

the class DFRSimilarity method explain.

@Override
protected void explain(List<Explanation> subs, BasicStats stats, int doc, float freq, float docLen) {
    if (stats.getBoost() != 1.0f) {
        subs.add(Explanation.match(stats.getBoost(), "boost"));
    }
    Explanation normExpl = normalization.explain(stats, freq, docLen);
    float tfn = normExpl.getValue();
    subs.add(normExpl);
    subs.add(basicModel.explain(stats, tfn));
    subs.add(afterEffect.explain(stats, tfn));
}
Also used : Explanation(org.apache.lucene.search.Explanation)

Example 62 with Explanation

use of org.apache.lucene.search.Explanation in project lucene-solr by apache.

the class LMDirichletSimilarity method explain.

@Override
protected void explain(List<Explanation> subs, BasicStats stats, int doc, float freq, float docLen) {
    if (stats.getBoost() != 1.0f) {
        subs.add(Explanation.match(stats.getBoost(), "boost"));
    }
    subs.add(Explanation.match(mu, "mu"));
    Explanation weightExpl = Explanation.match((float) Math.log(1 + freq / (mu * ((LMStats) stats).getCollectionProbability())), "term weight");
    subs.add(weightExpl);
    subs.add(Explanation.match((float) Math.log(mu / (docLen + mu)), "document norm"));
    super.explain(subs, stats, doc, freq, docLen);
}
Also used : Explanation(org.apache.lucene.search.Explanation)

Example 63 with Explanation

use of org.apache.lucene.search.Explanation in project lucene-solr by apache.

the class TFIDFSimilarity method computeWeight.

@Override
public final SimWeight computeWeight(float boost, CollectionStatistics collectionStats, TermStatistics... termStats) {
    final Explanation idf = termStats.length == 1 ? idfExplain(collectionStats, termStats[0]) : idfExplain(collectionStats, termStats);
    float[] normTable = new float[256];
    for (int i = 1; i < 256; ++i) {
        int length = SmallFloat.byte4ToInt((byte) i);
        float norm = lengthNorm(length);
        normTable[i] = norm;
    }
    normTable[0] = 1f / normTable[255];
    return new IDFStats(collectionStats.field(), boost, idf, normTable);
}
Also used : Explanation(org.apache.lucene.search.Explanation)

Example 64 with Explanation

use of org.apache.lucene.search.Explanation in project lucene-solr by apache.

the class TFIDFSimilarity method explainField.

private Explanation explainField(int doc, Explanation freq, IDFStats stats, NumericDocValues norms, float[] normTable) throws IOException {
    Explanation tfExplanation = Explanation.match(tf(freq.getValue()), "tf(freq=" + freq.getValue() + "), with freq of:", freq);
    float norm;
    if (norms == null) {
        norm = 1f;
    } else if (norms.advanceExact(doc) == false) {
        norm = 0f;
    } else {
        norm = normTable[(int) (norms.longValue() & 0xFF)];
    }
    Explanation fieldNormExpl = Explanation.match(norm, "fieldNorm(doc=" + doc + ")");
    return Explanation.match(tfExplanation.getValue() * stats.idf.getValue() * fieldNormExpl.getValue(), "fieldWeight in " + doc + ", product of:", tfExplanation, stats.idf, fieldNormExpl);
}
Also used : Explanation(org.apache.lucene.search.Explanation)

Example 65 with Explanation

use of org.apache.lucene.search.Explanation in project lucene-solr by apache.

the class TFIDFSimilarity method explainScore.

private Explanation explainScore(int doc, Explanation freq, IDFStats stats, NumericDocValues norms, float[] normTable) throws IOException {
    Explanation queryExpl = Explanation.match(stats.boost, "boost");
    Explanation fieldExpl = explainField(doc, freq, stats, norms, normTable);
    if (stats.boost == 1f) {
        return fieldExpl;
    }
    return Explanation.match(queryExpl.getValue() * fieldExpl.getValue(), "score(doc=" + doc + ",freq=" + freq.getValue() + "), product of:", queryExpl, fieldExpl);
}
Also used : Explanation(org.apache.lucene.search.Explanation)

Aggregations

Explanation (org.apache.lucene.search.Explanation)77 TermQuery (org.apache.lucene.search.TermQuery)16 ArrayList (java.util.ArrayList)13 Query (org.apache.lucene.search.Query)13 IndexSearcher (org.apache.lucene.search.IndexSearcher)12 Term (org.apache.lucene.index.Term)11 IOException (java.io.IOException)9 BooleanQuery (org.apache.lucene.search.BooleanQuery)8 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)8 Directory (org.apache.lucene.store.Directory)8 Document (org.apache.lucene.document.Document)7 TopDocs (org.apache.lucene.search.TopDocs)7 IndexReader (org.apache.lucene.index.IndexReader)6 IndexWriter (org.apache.lucene.index.IndexWriter)6 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)6 Collectors (java.util.stream.Collectors)5 Collections (java.util.Collections)4 DirectoryReader (org.apache.lucene.index.DirectoryReader)4 FunctionValues (org.apache.lucene.queries.function.FunctionValues)4 SearchResponse (org.elasticsearch.action.search.SearchResponse)4