use of org.apache.lucene.index.MultiReader in project elasticsearch by elastic.
the class TDigestPercentileRanksAggregatorTests method testEmpty.
public void testEmpty() throws IOException {
PercentileRanksAggregationBuilder aggBuilder = new PercentileRanksAggregationBuilder("my_agg").field("field").method(PercentilesMethod.TDIGEST).values(0.5);
MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.DOUBLE);
fieldType.setName("field");
try (IndexReader reader = new MultiReader()) {
IndexSearcher searcher = new IndexSearcher(reader);
PercentileRanks ranks = search(searcher, new MatchAllDocsQuery(), aggBuilder, fieldType);
Percentile rank = ranks.iterator().next();
assertEquals(Double.NaN, rank.getPercent(), 0d);
assertEquals(0.5, rank.getValue(), 0d);
}
}
use of org.apache.lucene.index.MultiReader in project lucene-solr by apache.
the class ReverseOrdFieldSource method getValues.
@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
final int off = readerContext.docBase;
final LeafReader r;
Object o = context.get("searcher");
if (o instanceof SolrIndexSearcher) {
SolrIndexSearcher is = (SolrIndexSearcher) o;
SchemaField sf = is.getSchema().getFieldOrNull(field);
if (sf != null && sf.hasDocValues() == false && sf.multiValued() == false && sf.getType().getNumberType() != null) {
// it's a single-valued numeric field: we must currently create insanity :(
List<LeafReaderContext> leaves = is.getIndexReader().leaves();
LeafReader[] insaneLeaves = new LeafReader[leaves.size()];
int upto = 0;
for (LeafReaderContext raw : leaves) {
insaneLeaves[upto++] = Insanity.wrapInsanity(raw.reader(), field);
}
r = SlowCompositeReaderWrapper.wrap(new MultiReader(insaneLeaves));
} else {
// reuse ordinalmap
r = ((SolrIndexSearcher) o).getSlowAtomicReader();
}
} else {
IndexReader topReader = ReaderUtil.getTopLevelContext(readerContext).reader();
r = SlowCompositeReaderWrapper.wrap(topReader);
}
// if it's e.g. tokenized/multivalued, emulate old behavior of single-valued fc
final SortedDocValues sindex = SortedSetSelector.wrap(DocValues.getSortedSet(r, field), SortedSetSelector.Type.MIN);
final int end = sindex.getValueCount();
return new IntDocValues(this) {
@Override
public int intVal(int doc) throws IOException {
if (doc + off > sindex.docID()) {
sindex.advance(doc + off);
}
if (doc + off == sindex.docID()) {
return (end - sindex.ordValue() - 1);
} else {
return end;
}
}
};
}
use of org.apache.lucene.index.MultiReader in project lucene-solr by apache.
the class BoostingQueryTest method testRewrite.
public void testRewrite() throws IOException {
IndexReader reader = new MultiReader();
BoostingQuery q = new BoostingQuery(new BooleanQuery.Builder().build(), new MatchAllDocsQuery(), 3);
Query rewritten = new IndexSearcher(reader).rewrite(q);
Query expectedRewritten = new BoostingQuery(new MatchNoDocsQuery(), new MatchAllDocsQuery(), 3);
assertEquals(expectedRewritten, rewritten);
assertSame(rewritten, rewritten.rewrite(reader));
}
use of org.apache.lucene.index.MultiReader in project lucene-solr by apache.
the class TestClassicSimilarity method testSaneNormValues.
public void testSaneNormValues() throws IOException {
ClassicSimilarity sim = new ClassicSimilarity();
for (int i = 0; i < 256; i++) {
float boost = TFIDFSimilarity.OLD_NORM_TABLE[i];
assertFalse("negative boost: " + boost + ", byte=" + i, boost < 0.0f);
assertFalse("inf bost: " + boost + ", byte=" + i, Float.isInfinite(boost));
assertFalse("nan boost for byte=" + i, Float.isNaN(boost));
if (i > 0) {
assertTrue("boost is not increasing: " + boost + ",byte=" + i, boost > TFIDFSimilarity.OLD_NORM_TABLE[i - 1]);
}
}
TFIDFSimilarity.IDFStats stats = (IDFStats) sim.computeWeight(1f, new IndexSearcher(new MultiReader()).collectionStatistics("foo"));
for (int i = 0; i < 256; i++) {
float boost = stats.normTable[i];
assertFalse("negative boost: " + boost + ", byte=" + i, boost < 0.0f);
assertFalse("inf bost: " + boost + ", byte=" + i, Float.isInfinite(boost));
assertFalse("nan boost for byte=" + i, Float.isNaN(boost));
if (i > 0) {
assertTrue("boost is not decreasing: " + boost + ",byte=" + i, boost < stats.normTable[i - 1]);
}
}
}
use of org.apache.lucene.index.MultiReader in project lucene-solr by apache.
the class TestSortedNumericSortField method testEmptyIndex.
public void testEmptyIndex() throws Exception {
IndexSearcher empty = newSearcher(new MultiReader());
Query query = new TermQuery(new Term("contents", "foo"));
Sort sort = new Sort();
sort.setSort(new SortedNumericSortField("sortednumeric", SortField.Type.LONG));
TopDocs td = empty.search(query, 10, sort, true, true);
assertEquals(0, td.totalHits);
// for an empty index, any selector should work
for (SortedNumericSelector.Type v : SortedNumericSelector.Type.values()) {
sort.setSort(new SortedNumericSortField("sortednumeric", SortField.Type.LONG, false, v));
td = empty.search(query, 10, sort, true, true);
assertEquals(0, td.totalHits);
}
}
Aggregations