Java Code Examples for org.apache.lucene.search.Explanation#noMatch()
The following examples show how to use
org.apache.lucene.search.Explanation#noMatch() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DependentTermQueryBuilder.java From querqy with Apache License 2.0 | 6 votes |
@Override public Explanation explain(final LeafReaderContext context, final int doc) throws IOException { TermScorer scorer = scorer(context); if (scorer != null) { int newDoc = scorer.iterator().advance(doc); if (newDoc == doc) { float freq = scorer.freq(); LeafSimScorer docScorer = new LeafSimScorer(simScorer, context.reader(), getTerm().field(), true); Explanation freqExplanation = Explanation.match(freq, "freq, occurrences of term within document"); Explanation scoreExplanation = docScorer.explain(doc, freqExplanation); return Explanation.match( scoreExplanation.getValue(), "weight(" + getQuery() + " in " + doc + ") [" + similarity.getClass().getSimpleName() + "], result of:", scoreExplanation); } } return Explanation.noMatch("no matching term"); }
Example 2
Source File: FieldFeatureTFIDFExtractor.java From ltr4l with Apache License 2.0 | 6 votes |
@Override public Explanation explain(int target) throws IOException { int current = pe.docID(); if(current < target){ current = pe.advance(target); } if(current == target){ int freq = pe.freq(); float score = freq * idf; Explanation eTf = Explanation.match(freq, "TF = freq = " + freq); Explanation eIdf = Explanation.match(idf, "IDF = log(" + numDocs + "/" + docFreq + ")"); return Explanation.match(score, "TF * IDF:", eTf, eIdf); } else{ return Explanation.noMatch("no matching terms"); } }
Example 3
Source File: SpanWeight.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public Explanation explain(LeafReaderContext context, int doc) throws IOException { SpanScorer scorer = scorer(context); if (scorer != null) { int newDoc = scorer.iterator().advance(doc); if (newDoc == doc) { float freq = scorer.sloppyFreq(); LeafSimScorer docScorer = new LeafSimScorer(simScorer, context.reader(), field, true); Explanation freqExplanation = Explanation.match(freq, "phraseFreq=" + freq); Explanation scoreExplanation = docScorer.explain(doc, freqExplanation); return Explanation.match(scoreExplanation.getValue(), "weight("+getQuery()+" in "+doc+") [" + similarity.getClass().getSimpleName() + "], result of:", scoreExplanation); } } return Explanation.noMatch("no matching term"); }
Example 4
Source File: PayloadScoreQuery.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public Explanation explain(LeafReaderContext context, int doc) throws IOException { PayloadSpanScorer scorer = (PayloadSpanScorer)scorer(context); if (scorer == null || scorer.iterator().advance(doc) != doc) return Explanation.noMatch("No match"); scorer.score(); // force freq calculation Explanation payloadExpl = scorer.getPayloadExplanation(); if (includeSpanScore) { SpanWeight innerWeight = ((PayloadSpanWeight) scorer.getWeight()).innerWeight; Explanation innerExpl = innerWeight.explain(context, doc); return Explanation.match(scorer.scoreCurrentDoc(), "PayloadSpanQuery, product of:", innerExpl, payloadExpl); } return scorer.getPayloadExplanation(); }
Example 5
Source File: GlobalOrdinalsWithScoreQuery.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public Explanation explain(LeafReaderContext context, int doc) throws IOException { SortedDocValues values = DocValues.getSorted(context.reader(), joinField); if (values == null) { return Explanation.noMatch("Not a match"); } if (values.advance(doc) != doc) { return Explanation.noMatch("Not a match"); } int segmentOrd = values.ordValue(); BytesRef joinValue = values.lookupOrd(segmentOrd); int ord; if (globalOrds != null) { ord = (int) globalOrds.getGlobalOrds(context.ord).get(segmentOrd); } else { ord = segmentOrd; } if (collector.match(ord) == false) { return Explanation.noMatch("Not a match, join value " + Term.toString(joinValue)); } float score = collector.score(ord); return Explanation.match(score, "A match, join value " + Term.toString(joinValue)); }
Example 6
Source File: GlobalOrdinalsQuery.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public Explanation explain(LeafReaderContext context, int doc) throws IOException { SortedDocValues values = DocValues.getSorted(context.reader(), joinField); if (values == null) { return Explanation.noMatch("Not a match"); } if (values.advance(doc) != doc) { return Explanation.noMatch("Not a match"); } int segmentOrd = values.ordValue(); BytesRef joinValue = values.lookupOrd(segmentOrd); int ord; if (globalOrds != null) { ord = (int) globalOrds.getGlobalOrds(context.ord).get(segmentOrd); } else { ord = segmentOrd; } if (foundOrds.get(ord) == false) { return Explanation.noMatch("Not a match, join value " + Term.toString(joinValue)); } return Explanation.match(score(), "A match, join value " + Term.toString(joinValue)); }
Example 7
Source File: ToParentBlockJoinQuery.java From lucene-solr with Apache License 2.0 | 5 votes |
@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, in); } return Explanation.noMatch("Not a match"); }
Example 8
Source File: FieldBoostTermQueryBuilder.java From querqy with Apache License 2.0 | 5 votes |
@Override public Explanation explain(final LeafReaderContext context, final int doc) throws IOException { Scorer scorer = scorer(context); if (scorer != null) { int newDoc = scorer.iterator().advance(doc); if (newDoc == doc) { Explanation scoreExplanation = Explanation.match(score, "product of:", Explanation.match(queryBoost, "queryBoost"), Explanation.match(fieldBoost, "fieldBoost") ); Explanation result = Explanation.match(scorer.score(), "weight(" + getQuery() + " in " + doc + ") [" + FieldBoostTermQuery.this.fieldBoost.getClass().getSimpleName() + "], result of:", scoreExplanation ); return result; } } return Explanation.noMatch("no matching term"); }
Example 9
Source File: PositionMatchScorer.java From elasticsearch-position-similarity with Apache License 2.0 | 5 votes |
private Explanation explainTerm(int docID, Term term) { int termPosition = position(docID, term); if (NOT_FOUND_POSITION == termPosition) { return Explanation.noMatch( String.format("no matching terms for field=%s, term=%s", term.field(), term.text()) ); } else { float termScore = ((float) HALF_SCORE_POSITION) / (HALF_SCORE_POSITION + termPosition); String func = HALF_SCORE_POSITION + "/(" + HALF_SCORE_POSITION + "+" + termPosition + ")"; return Explanation.match( termScore, String.format("score(field=%s, term=%s, pos=%d, func=%s)", term.field(), term.text(), termPosition, func) ); } }
Example 10
Source File: ExplorerQuery.java From elasticsearch-learning-to-rank with Apache License 2.0 | 5 votes |
@Override public Explanation explain(LeafReaderContext context, int doc) throws IOException { Scorer scorer = scorer(context); if (scorer != null) { int newDoc = scorer.iterator().advance(doc); if (newDoc == doc) { return Explanation.match( scorer.score(), "Stat Score: " + type); } } return Explanation.noMatch("no matching term"); }
Example 11
Source File: PostingsExplorerQuery.java From elasticsearch-learning-to-rank with Apache License 2.0 | 5 votes |
@Override public Explanation explain(LeafReaderContext context, int doc) throws IOException { Scorer scorer = this.scorer(context); int newDoc = scorer.iterator().advance(doc); if (newDoc == doc) { return Explanation .match(scorer.score(), "weight(" + this.getQuery() + " in doc " + newDoc + ")"); } return Explanation.noMatch("no matching term"); }
Example 12
Source File: ToChildBlockJoinQuery.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public Explanation explain(LeafReaderContext context, int doc) throws IOException { ToChildBlockJoinScorer scorer = (ToChildBlockJoinScorer) scorer(context); if (scorer != null && scorer.iterator().advance(doc) == doc) { int parentDoc = scorer.getParentDoc(); return Explanation.match( scorer.score(), String.format(Locale.ROOT, "Score based on parent document %d", parentDoc + context.docBase), in.explain(context, parentDoc) ); } return Explanation.noMatch("Not a match"); }
Example 13
Source File: ExpressionValueSource.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException { Explanation[] explanations = new Explanation[variables.length]; DoubleValues dv = getValues(ctx, DoubleValuesSource.constant(scoreExplanation.getValue().doubleValue()).getValues(ctx, null)); if (dv.advanceExact(docId) == false) { return Explanation.noMatch(expression.sourceText); } int i = 0; for (DoubleValuesSource var : variables) { explanations[i++] = var.explain(ctx, docId, scoreExplanation); } return Explanation.match(dv.doubleValue(), expression.sourceText + ", computed from:", explanations); }
Example 14
Source File: IntervalQuery.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public Explanation explain(LeafReaderContext context, int doc) throws IOException { IntervalScorer scorer = (IntervalScorer) scorer(context); if (scorer != null) { int newDoc = scorer.iterator().advance(doc); if (newDoc == doc) { float freq = scorer.freq(); return scoreFunction.explain(IntervalQuery.this.toString(), boost, freq); } } return Explanation.noMatch("no matching intervals"); }
Example 15
Source File: FunctionRangeQuery.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public Explanation explain(LeafReaderContext context, int doc) throws IOException { FunctionValues functionValues = valueSource.getValues(vsContext, context); //note: by using ValueSourceScorer directly, we avoid calling scorer.advance(doc) and checking if true, // which can be slow since if that doc doesn't match, it has to linearly find the next matching ValueSourceScorer scorer = scorer(context); if (scorer.matches(doc)) { scorer.iterator().advance(doc); return Explanation.match(scorer.score(), FunctionRangeQuery.this.toString(), functionValues.explain(doc)); } else { return Explanation.noMatch(FunctionRangeQuery.this.toString(), functionValues.explain(doc)); } }
Example 16
Source File: BBoxSimilarityValueSource.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException { DoubleValues dv = getValues(ctx, DoubleValuesSource.constant(scoreExplanation.getValue().doubleValue()).getValues(ctx, null)); if (dv.advanceExact(docId)) { AtomicReference<Explanation> explanation = new AtomicReference<>(); final ShapeValues shapeValues = bboxValueSource.getValues(ctx); if (shapeValues.advanceExact(docId)) { score((Rectangle) shapeValues.value(), explanation); return explanation.get(); } } return Explanation.noMatch(this.toString()); }
Example 17
Source File: QueryRescorer.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public Explanation explain(int topLevelDocId, SearchContext context, RescoreSearchContext rescoreContext, Explanation sourceExplanation) throws IOException { QueryRescoreContext rescore = (QueryRescoreContext) rescoreContext; ContextIndexSearcher searcher = context.searcher(); if (sourceExplanation == null) { // this should not happen but just in case return Explanation.noMatch("nothing matched"); } // TODO: this isn't right? I.e., we are incorrectly pretending all first pass hits were rescored? If the requested docID was // beyond the top rescoreContext.window() in the first pass hits, we don't rescore it now? Explanation rescoreExplain = searcher.explain(rescore.query(), topLevelDocId); float primaryWeight = rescore.queryWeight(); Explanation prim; if (sourceExplanation.isMatch()) { prim = Explanation.match( sourceExplanation.getValue() * primaryWeight, "product of:", sourceExplanation, Explanation.match(primaryWeight, "primaryWeight")); } else { prim = Explanation.noMatch("First pass did not match", sourceExplanation); } // NOTE: we don't use Lucene's Rescorer.explain because we want to insert our own description with which ScoreMode was used. Maybe // we should add QueryRescorer.explainCombine to Lucene? if (rescoreExplain != null && rescoreExplain.isMatch()) { float secondaryWeight = rescore.rescoreQueryWeight(); Explanation sec = Explanation.match( rescoreExplain.getValue() * secondaryWeight, "product of:", rescoreExplain, Explanation.match(secondaryWeight, "secondaryWeight")); ScoreMode scoreMode = rescore.scoreMode(); return Explanation.match( scoreMode.combine(prim.getValue(), sec.getValue()), scoreMode + " of:", prim, sec); } else { return prim; } }
Example 18
Source File: FieldFeatureTFExtractor.java From ltr4l with Apache License 2.0 | 5 votes |
@Override public Explanation explain(int target) throws IOException { int current = pe.docID(); if(current < target){ current = pe.advance(target); } if(current == target){ int freq = pe.freq(); return Explanation.match(freq, "freq: " + freq); } else{ return Explanation.noMatch("no matching terms"); } }
Example 19
Source File: FieldFeatureNullExtractor.java From ltr4l with Apache License 2.0 | 4 votes |
@Override public Explanation explain(int doc) throws IOException { return Explanation.noMatch("no matching terms"); }
Example 20
Source File: DependentTermQueryBuilder.java From querqy with Apache License 2.0 | 4 votes |
@Override public Explanation explain(LeafReaderContext context, int doc) throws IOException { return Explanation.noMatch("no matching term"); }