Search in sources :

Example 6 with MultiReader

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);
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) Percentile(org.elasticsearch.search.aggregations.metrics.percentiles.Percentile) PercentileRanksAggregationBuilder(org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanksAggregationBuilder) MultiReader(org.apache.lucene.index.MultiReader) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) IndexReader(org.apache.lucene.index.IndexReader) PercentileRanks(org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery)

Example 7 with MultiReader

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;
            }
        }
    };
}
Also used : SchemaField(org.apache.solr.schema.SchemaField) LeafReader(org.apache.lucene.index.LeafReader) MultiReader(org.apache.lucene.index.MultiReader) IndexReader(org.apache.lucene.index.IndexReader) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) IntDocValues(org.apache.lucene.queries.function.docvalues.IntDocValues) SortedDocValues(org.apache.lucene.index.SortedDocValues)

Example 8 with MultiReader

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));
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) Query(org.apache.lucene.search.Query) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) MultiReader(org.apache.lucene.index.MultiReader) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) IndexReader(org.apache.lucene.index.IndexReader) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery)

Example 9 with MultiReader

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]);
        }
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) MultiReader(org.apache.lucene.index.MultiReader) IDFStats(org.apache.lucene.search.similarities.TFIDFSimilarity.IDFStats) IDFStats(org.apache.lucene.search.similarities.TFIDFSimilarity.IDFStats)

Example 10 with MultiReader

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);
    }
}
Also used : MultiReader(org.apache.lucene.index.MultiReader) Term(org.apache.lucene.index.Term)

Aggregations

MultiReader (org.apache.lucene.index.MultiReader)47 IndexReader (org.apache.lucene.index.IndexReader)20 Term (org.apache.lucene.index.Term)20 IndexSearcher (org.apache.lucene.search.IndexSearcher)14 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)7 Document (org.apache.lucene.document.Document)6 Query (org.apache.lucene.search.Query)6 IOException (java.io.IOException)5 TermQuery (org.apache.lucene.search.TermQuery)5 BooleanQuery (org.apache.lucene.search.BooleanQuery)4 HashSet (java.util.HashSet)3 List (java.util.List)3 TreeSet (java.util.TreeSet)3 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)3 MatchNoDocsQuery (org.apache.lucene.search.MatchNoDocsQuery)3 Sort (org.apache.lucene.search.Sort)3 ArrayList (java.util.ArrayList)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 LuceneIndexReader (org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReader)2 LeafReader (org.apache.lucene.index.LeafReader)2