use of org.apache.lucene.search.ScoreDoc in project lucene-solr by apache.
the class TestOrdValues method doTestExactScore.
// Test that queries based on reverse/ordFieldScore returns docs with expected score.
private void doTestExactScore(String field, boolean inOrder) throws Exception {
IndexReader r = DirectoryReader.open(dir);
IndexSearcher s = newSearcher(r);
ValueSource vs;
if (inOrder) {
vs = new OrdFieldSource(field);
} else {
vs = new ReverseOrdFieldSource(field);
}
Query q = new FunctionQuery(vs);
TopDocs td = s.search(q, 1000);
assertEquals("All docs should be matched!", N_DOCS, td.totalHits);
ScoreDoc[] sd = td.scoreDocs;
for (int i = 0; i < sd.length; i++) {
float score = sd[i].score;
String id = s.getIndexReader().document(sd[i].doc).get(ID_FIELD);
log("-------- " + i + ". Explain doc " + id);
log(s.explain(q, sd[i].doc));
float expectedScore = N_DOCS - i - 1;
assertEquals("score of result " + i + " should be " + expectedScore + " != " + score, expectedScore, score, TEST_SCORE_TOLERANCE_DELTA);
String expectedId = inOrder ? // in-order ==> larger values first
id2String(N_DOCS - i) : // reverse ==> smaller values first
id2String(i + 1);
assertTrue("id of result " + i + " should be " + expectedId + " != " + score, expectedId.equals(id));
}
r.close();
}
use of org.apache.lucene.search.ScoreDoc in project lucene-solr by apache.
the class ClassificationUpdateProcessorIntegrationTest method getDoc.
private Document getDoc(String id) throws IOException {
try (SolrQueryRequest req = req()) {
SolrIndexSearcher searcher = req.getSearcher();
TermQuery query = new TermQuery(new Term(ID, id));
TopDocs doc1 = searcher.search(query, 1);
ScoreDoc scoreDoc = doc1.scoreDocs[0];
return searcher.doc(scoreDoc.doc);
}
}
use of org.apache.lucene.search.ScoreDoc in project lucene-solr by apache.
the class TestNumericRangeQuery64 method testOneMatchQuery.
@Test
public void testOneMatchQuery() throws Exception {
LegacyNumericRangeQuery<Long> q = LegacyNumericRangeQuery.newLongRange("ascfield8", 8, 1000L, 1000L, true, true);
TopDocs topDocs = searcher.search(q, noDocs);
ScoreDoc[] sd = topDocs.scoreDocs;
assertNotNull(sd);
assertEquals("Score doc count", 1, sd.length);
}
use of org.apache.lucene.search.ScoreDoc in project lucene-solr by apache.
the class TestNumericRangeQuery32 method testOneMatchQuery.
@Test
public void testOneMatchQuery() throws Exception {
LegacyNumericRangeQuery<Integer> q = LegacyNumericRangeQuery.newIntRange("ascfield8", 8, 1000, 1000, true, true);
TopDocs topDocs = searcher.search(q, noDocs);
ScoreDoc[] sd = topDocs.scoreDocs;
assertNotNull(sd);
assertEquals("Score doc count", 1, sd.length);
}
use of org.apache.lucene.search.ScoreDoc in project lucene-solr by apache.
the class TestNumericRangeQuery32 method testRightOpenRange.
private void testRightOpenRange(int precisionStep) throws Exception {
String field = "field" + precisionStep;
int count = 3000;
int lower = (count - 1) * distance + (distance / 3) + startOffset;
LegacyNumericRangeQuery<Integer> q = LegacyNumericRangeQuery.newIntRange(field, precisionStep, lower, null, true, true);
TopDocs topDocs = searcher.search(q, noDocs, Sort.INDEXORDER);
ScoreDoc[] sd = topDocs.scoreDocs;
assertNotNull(sd);
assertEquals("Score doc count", noDocs - count, sd.length);
Document doc = searcher.doc(sd[0].doc);
assertEquals("First doc", count * distance + startOffset, doc.getField(field).numericValue().intValue());
doc = searcher.doc(sd[sd.length - 1].doc);
assertEquals("Last doc", (noDocs - 1) * distance + startOffset, doc.getField(field).numericValue().intValue());
q = LegacyNumericRangeQuery.newIntRange(field, precisionStep, lower, null, true, false);
topDocs = searcher.search(q, noDocs, Sort.INDEXORDER);
sd = topDocs.scoreDocs;
assertNotNull(sd);
assertEquals("Score doc count", noDocs - count, sd.length);
doc = searcher.doc(sd[0].doc);
assertEquals("First doc", count * distance + startOffset, doc.getField(field).numericValue().intValue());
doc = searcher.doc(sd[sd.length - 1].doc);
assertEquals("Last doc", (noDocs - 1) * distance + startOffset, doc.getField(field).numericValue().intValue());
}
Aggregations