use of org.apache.lucene.search.ScoreDoc in project lucene-solr by apache.
the class TestLongNormValueSource method assertHits.
void assertHits(Query q, float[] scores) throws Exception {
ScoreDoc[] expected = new ScoreDoc[scores.length];
int[] expectedDocs = new int[scores.length];
for (int i = 0; i < expected.length; i++) {
expectedDocs[i] = i;
expected[i] = new ScoreDoc(i, scores[i]);
}
TopDocs docs = searcher.search(q, 2, new Sort(new SortField("id", SortField.Type.STRING)));
/*
for (int i=0;i<docs.scoreDocs.length;i++) {
System.out.println(searcher.explain(q, docs.scoreDocs[i].doc));
}
*/
CheckHits.checkHits(random(), q, "", searcher, expectedDocs);
CheckHits.checkHitsQuery(q, expected, docs.scoreDocs, expectedDocs);
CheckHits.checkExplanations(q, "", searcher);
}
use of org.apache.lucene.search.ScoreDoc in project lucene-solr by apache.
the class TestFunctionRangeQuery method testExplain.
@Test
public void testExplain() throws IOException {
Query rangeQuery = new FunctionRangeQuery(INT_VALUESOURCE, 2, 2, true, true);
ScoreDoc[] scoreDocs = indexSearcher.search(rangeQuery, N_DOCS).scoreDocs;
Explanation explain = indexSearcher.explain(rangeQuery, scoreDocs[0].doc);
// Just validate it looks reasonable
assertEquals("2.0 = frange(int(" + INT_FIELD + ")):[2 TO 2]\n" + " 2.0 = int(" + INT_FIELD + ")=2\n", explain.toString());
}
use of org.apache.lucene.search.ScoreDoc in project lucene-solr by apache.
the class TestBoostedQuery method assertHits.
void assertHits(Query q, float[] scores) throws Exception {
ScoreDoc[] expected = new ScoreDoc[scores.length];
int[] expectedDocs = new int[scores.length];
for (int i = 0; i < expected.length; i++) {
expectedDocs[i] = i;
expected[i] = new ScoreDoc(i, scores[i]);
}
TopDocs docs = is.search(q, 10, new Sort(new SortField("id", SortField.Type.STRING)));
CheckHits.checkHits(random(), q, "", is, expectedDocs);
CheckHits.checkHitsQuery(q, expected, docs.scoreDocs, expectedDocs);
CheckHits.checkExplanations(q, "", is);
}
use of org.apache.lucene.search.ScoreDoc in project lucene-solr by apache.
the class TestMultiFieldQueryParser method testStopWordSearching.
public void testStopWordSearching() throws Exception {
Analyzer analyzer = new MockAnalyzer(random());
Directory ramDir = newDirectory();
IndexWriter iw = new IndexWriter(ramDir, newIndexWriterConfig(analyzer));
Document doc = new Document();
doc.add(newTextField("body", "blah the footest blah", Field.Store.NO));
iw.addDocument(doc);
iw.close();
MultiFieldQueryParser mfqp = new MultiFieldQueryParser(new String[] { "body" }, analyzer);
mfqp.setDefaultOperator(QueryParser.Operator.AND);
Query q = mfqp.parse("the footest");
IndexReader ir = DirectoryReader.open(ramDir);
IndexSearcher is = newSearcher(ir);
ScoreDoc[] hits = is.search(q, 1000).scoreDocs;
assertEquals(1, hits.length);
ir.close();
ramDir.close();
}
use of org.apache.lucene.search.ScoreDoc in project lucene-solr by apache.
the class SpatialTestCase method executeQuery.
protected SearchResults executeQuery(Query query, int numDocs) {
try {
TopDocs topDocs = indexSearcher.search(query, numDocs);
List<SearchResult> results = new ArrayList<>();
for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
results.add(new SearchResult(scoreDoc.score, indexSearcher.doc(scoreDoc.doc)));
}
return new SearchResults(topDocs.totalHits, results);
} catch (IOException ioe) {
throw new RuntimeException("IOException thrown while executing query", ioe);
}
}
Aggregations