use of org.apache.lucene.search.Explanation in project lucene-solr by apache.
the class TestSweetSpotSimilarityFactory method computeNorm.
private static float computeNorm(Similarity sim, int length) throws IOException {
String value = IntStream.range(0, length).mapToObj(i -> "a").collect(Collectors.joining(" "));
Directory dir = newDirectory();
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig().setSimilarity(sim));
w.addDocument(Collections.singleton(newTextField("foo", value, Store.NO)));
DirectoryReader reader = DirectoryReader.open(w);
w.close();
IndexSearcher searcher = new IndexSearcher(reader);
searcher.setSimilarity(sim);
Explanation expl = searcher.explain(new TermQuery(new Term("foo", "a")), 0);
reader.close();
dir.close();
Explanation norm = findExplanation(expl, "fieldNorm");
assertNotNull(norm);
return norm.getValue();
}
use of org.apache.lucene.search.Explanation in project lucene-solr by apache.
the class TestNearSpansOrdered method testSpanNearScorerExplain.
/**
* 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 = searcher.explain(q, 1);
assertTrue("Scorer explanation value for doc#1 isn't positive: " + e.toString(), 0.0f <= e.getValue());
}
use of org.apache.lucene.search.Explanation in project lucene-solr by apache.
the class DistanceToShapeValueSource method getValues.
@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
final FunctionValues shapeValues = shapeValueSource.getValues(context, readerContext);
return new DoubleDocValues(this) {
@Override
public double doubleVal(int doc) throws IOException {
Shape shape = (Shape) shapeValues.objectVal(doc);
if (shape == null || shape.isEmpty())
return nullValue;
Point pt = shape.getCenter();
return distCalc.distance(queryPoint, pt) * multiplier;
}
@Override
public Explanation explain(int doc) throws IOException {
Explanation exp = super.explain(doc);
List<Explanation> details = new ArrayList<>(Arrays.asList(exp.getDetails()));
details.add(shapeValues.explain(doc));
return Explanation.match(exp.getValue(), exp.getDescription(), details);
}
};
}
use of org.apache.lucene.search.Explanation in project lucene-solr by apache.
the class ShapePredicateValueSource method getValues.
@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
final FunctionValues shapeValues = shapeValuesource.getValues(context, readerContext);
return new BoolDocValues(this) {
@Override
public boolean boolVal(int doc) throws IOException {
Shape indexedShape = (Shape) shapeValues.objectVal(doc);
if (indexedShape == null)
return false;
return op.evaluate(indexedShape, queryShape);
}
@Override
public Explanation explain(int doc) throws IOException {
Explanation exp = super.explain(doc);
List<Explanation> details = new ArrayList<>(Arrays.asList(exp.getDetails()));
details.add(shapeValues.explain(doc));
return Explanation.match(exp.getValue(), exp.getDescription(), details);
}
};
}
use of org.apache.lucene.search.Explanation in project lucene-solr by apache.
the class SolrPluginUtils method doStandardResultsDebug.
public static void doStandardResultsDebug(SolrQueryRequest req, Query query, DocList results, boolean dbgResults, NamedList dbg) throws IOException {
if (dbgResults) {
SolrIndexSearcher searcher = req.getSearcher();
IndexSchema schema = searcher.getSchema();
boolean explainStruct = req.getParams().getBool(CommonParams.EXPLAIN_STRUCT, false);
if (results != null) {
NamedList<Explanation> explain = getExplanations(query, results, searcher, schema);
dbg.add("explain", explainStruct ? explanationsToNamedLists(explain) : explanationsToStrings(explain));
}
String otherQueryS = req.getParams().get(CommonParams.EXPLAIN_OTHER);
if (otherQueryS != null && otherQueryS.length() > 0) {
DocList otherResults = doSimpleQuery(otherQueryS, req, 0, 10);
dbg.add("otherQuery", otherQueryS);
NamedList<Explanation> explainO = getExplanations(query, otherResults, searcher, schema);
dbg.add("explainOther", explainStruct ? explanationsToNamedLists(explainO) : explanationsToStrings(explainO));
}
}
}
Aggregations