use of org.apache.lucene.search.TopDocs in project lucene-solr by apache.
the class BaseGeoPointTestCase method testSmallSetDistance.
public void testSmallSetDistance() throws Exception {
TopDocs td = searchSmallSet(newDistanceQuery("point", 32.94823588839368, -96.4538113027811, 6000), 20);
assertEquals(2, td.totalHits);
}
use of org.apache.lucene.search.TopDocs in project lucene-solr by apache.
the class BaseDocValuesFormatTestCase method testBytes.
public void testBytes() throws IOException {
Analyzer analyzer = new MockAnalyzer(random());
Directory directory = newDirectory();
IndexWriterConfig conf = newIndexWriterConfig(analyzer);
RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, conf);
Document doc = new Document();
String longTerm = "longtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongterm";
String text = "This is the text to be indexed. " + longTerm;
doc.add(newTextField("fieldname", text, Field.Store.YES));
doc.add(new BinaryDocValuesField("dv", new BytesRef("hello world")));
iwriter.addDocument(doc);
iwriter.close();
// Now search the index:
// read-only=true
IndexReader ireader = DirectoryReader.open(directory);
IndexSearcher isearcher = new IndexSearcher(ireader);
assertEquals(1, isearcher.search(new TermQuery(new Term("fieldname", longTerm)), 1).totalHits);
Query query = new TermQuery(new Term("fieldname", "text"));
TopDocs hits = isearcher.search(query, 1);
assertEquals(1, hits.totalHits);
// Iterate through the results:
for (int i = 0; i < hits.scoreDocs.length; i++) {
int hitDocID = hits.scoreDocs[i].doc;
Document hitDoc = isearcher.doc(hitDocID);
assertEquals(text, hitDoc.get("fieldname"));
assert ireader.leaves().size() == 1;
BinaryDocValues dv = ireader.leaves().get(0).reader().getBinaryDocValues("dv");
assertEquals(hitDocID, dv.advance(hitDocID));
assertEquals(new BytesRef("hello world"), dv.binaryValue());
}
ireader.close();
directory.close();
}
use of org.apache.lucene.search.TopDocs in project lucene-solr by apache.
the class BaseDocValuesFormatTestCase method testThreeFieldsMixed2.
public void testThreeFieldsMixed2() throws IOException {
Directory directory = newDirectory();
RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory);
Document doc = new Document();
String longTerm = "longtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongtermlongterm";
String text = "This is the text to be indexed. " + longTerm;
doc.add(newTextField("fieldname", text, Field.Store.YES));
doc.add(new BinaryDocValuesField("dv1", new BytesRef("hello world")));
doc.add(new SortedDocValuesField("dv2", new BytesRef("hello hello")));
doc.add(new NumericDocValuesField("dv3", 5));
iwriter.addDocument(doc);
iwriter.close();
// Now search the index:
// read-only=true
IndexReader ireader = DirectoryReader.open(directory);
IndexSearcher isearcher = new IndexSearcher(ireader);
assertEquals(1, isearcher.search(new TermQuery(new Term("fieldname", longTerm)), 1).totalHits);
Query query = new TermQuery(new Term("fieldname", "text"));
TopDocs hits = isearcher.search(query, 1);
assertEquals(1, hits.totalHits);
BytesRef scratch = new BytesRef();
// Iterate through the results:
for (int i = 0; i < hits.scoreDocs.length; i++) {
int docID = hits.scoreDocs[i].doc;
Document hitDoc = isearcher.doc(docID);
assertEquals(text, hitDoc.get("fieldname"));
assert ireader.leaves().size() == 1;
SortedDocValues dv = ireader.leaves().get(0).reader().getSortedDocValues("dv2");
assertEquals(docID, dv.advance(docID));
int ord = dv.ordValue();
scratch = dv.lookupOrd(ord);
assertEquals(new BytesRef("hello hello"), scratch);
NumericDocValues dv2 = ireader.leaves().get(0).reader().getNumericDocValues("dv3");
assertEquals(docID, dv2.advance(docID));
assertEquals(5, dv2.longValue());
BinaryDocValues dv3 = ireader.leaves().get(0).reader().getBinaryDocValues("dv1");
assertEquals(docID, dv3.advance(docID));
assertEquals(new BytesRef("hello world"), dv3.binaryValue());
}
ireader.close();
directory.close();
}
use of org.apache.lucene.search.TopDocs in project lucene-solr by apache.
the class BaseGeoPointTestCase method testSmallSetWholeMap.
public void testSmallSetWholeMap() throws Exception {
TopDocs td = searchSmallSet(newRectQuery("point", GeoUtils.MIN_LAT_INCL, GeoUtils.MAX_LAT_INCL, GeoUtils.MIN_LON_INCL, GeoUtils.MAX_LON_INCL), 20);
assertEquals(24, td.totalHits);
}
use of org.apache.lucene.search.TopDocs in project lucene-solr by apache.
the class BaseGeoPointTestCase method testSmallSetMultiValued.
public void testSmallSetMultiValued() throws Exception {
TopDocs td = searchSmallSet(newRectQuery("point", 32.755, 32.776, -96.454, -96.770), 20);
// 3 single valued docs + 2 multi-valued docs
assertEquals(5, td.totalHits);
}
Aggregations