Search in sources :

Example 21 with LeafReader

use of org.apache.lucene.index.LeafReader in project lucene-solr by apache.

the class TestUnifiedHighlighterExtensibility method testFieldOffsetStrategyExtensibility.

/**
   * This test is for maintaining the extensibility of the FieldOffsetStrategy
   * for customizations out of package.
   */
@Test
public void testFieldOffsetStrategyExtensibility() {
    final UnifiedHighlighter.OffsetSource offsetSource = UnifiedHighlighter.OffsetSource.NONE_NEEDED;
    FieldOffsetStrategy strategy = new FieldOffsetStrategy("field", new BytesRef[0], PhraseHelper.NONE, new CharacterRunAutomaton[0]) {

        @Override
        public UnifiedHighlighter.OffsetSource getOffsetSource() {
            return offsetSource;
        }

        @Override
        public List<OffsetsEnum> getOffsetsEnums(IndexReader reader, int docId, String content) throws IOException {
            return Collections.emptyList();
        }

        @Override
        protected List<OffsetsEnum> createOffsetsEnumsFromReader(LeafReader leafReader, int doc) throws IOException {
            return super.createOffsetsEnumsFromReader(leafReader, doc);
        }
    };
    assertEquals(offsetSource, strategy.getOffsetSource());
}
Also used : FieldOffsetStrategy(org.apache.lucene.search.uhighlight.FieldOffsetStrategy) LeafReader(org.apache.lucene.index.LeafReader) UnifiedHighlighter(org.apache.lucene.search.uhighlight.UnifiedHighlighter) IndexReader(org.apache.lucene.index.IndexReader) OffsetsEnum(org.apache.lucene.search.uhighlight.OffsetsEnum) Test(org.junit.Test)

Example 22 with LeafReader

use of org.apache.lucene.index.LeafReader in project lucene-solr by apache.

the class DistanceValueSource method getValues.

/**
   * Returns the FunctionValues used by the function query.
   */
@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
    LeafReader reader = readerContext.reader();
    final NumericDocValues ptX = DocValues.getNumeric(reader, strategy.getFieldNameX());
    final NumericDocValues ptY = DocValues.getNumeric(reader, strategy.getFieldNameY());
    return new FunctionValues() {

        private int lastDocID = -1;

        private final Point from = DistanceValueSource.this.from;

        private final DistanceCalculator calculator = strategy.getSpatialContext().getDistCalc();

        private final double nullValue = (strategy.getSpatialContext().isGeo() ? 180 * multiplier : Double.MAX_VALUE);

        private double getDocValue(NumericDocValues values, int doc) throws IOException {
            int curDocID = values.docID();
            if (doc > curDocID) {
                curDocID = values.advance(doc);
            }
            if (doc == curDocID) {
                return Double.longBitsToDouble(values.longValue());
            } else {
                return 0.0;
            }
        }

        @Override
        public float floatVal(int doc) throws IOException {
            return (float) doubleVal(doc);
        }

        @Override
        public double doubleVal(int doc) throws IOException {
            // make sure it has minX and area
            double x = getDocValue(ptX, doc);
            if (ptX.docID() == doc) {
                double y = getDocValue(ptY, doc);
                assert ptY.docID() == doc;
                return calculator.distance(from, x, y) * multiplier;
            }
            return nullValue;
        }

        @Override
        public String toString(int doc) throws IOException {
            return description() + "=" + floatVal(doc);
        }
    };
}
Also used : DistanceCalculator(org.locationtech.spatial4j.distance.DistanceCalculator) NumericDocValues(org.apache.lucene.index.NumericDocValues) LeafReader(org.apache.lucene.index.LeafReader) FunctionValues(org.apache.lucene.queries.function.FunctionValues) Point(org.locationtech.spatial4j.shape.Point) Point(org.locationtech.spatial4j.shape.Point)

Example 23 with LeafReader

use of org.apache.lucene.index.LeafReader in project lucene-solr by apache.

the class AnalyzingInfixSuggester method ramBytesUsed.

@Override
public long ramBytesUsed() {
    long mem = RamUsageEstimator.shallowSizeOf(this);
    try {
        if (searcherMgr != null) {
            SearcherManager mgr;
            IndexSearcher searcher;
            synchronized (searcherMgrLock) {
                // acquire & release on same SearcherManager, via local reference
                mgr = searcherMgr;
                searcher = mgr.acquire();
            }
            try {
                for (LeafReaderContext context : searcher.getIndexReader().leaves()) {
                    LeafReader reader = FilterLeafReader.unwrap(context.reader());
                    if (reader instanceof SegmentReader) {
                        mem += ((SegmentReader) context.reader()).ramBytesUsed();
                    }
                }
            } finally {
                mgr.release(searcher);
            }
        }
        return mem;
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) LeafReader(org.apache.lucene.index.LeafReader) FilterLeafReader(org.apache.lucene.index.FilterLeafReader) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) SearcherManager(org.apache.lucene.search.SearcherManager) IOException(java.io.IOException) SegmentReader(org.apache.lucene.index.SegmentReader)

Example 24 with LeafReader

use of org.apache.lucene.index.LeafReader in project lucene-solr by apache.

the class AnalyzingInfixSuggester method getChildResources.

@Override
public Collection<Accountable> getChildResources() {
    List<Accountable> resources = new ArrayList<>();
    try {
        if (searcherMgr != null) {
            SearcherManager mgr;
            IndexSearcher searcher;
            synchronized (searcherMgrLock) {
                // acquire & release on same SearcherManager, via local reference
                mgr = searcherMgr;
                searcher = mgr.acquire();
            }
            try {
                for (LeafReaderContext context : searcher.getIndexReader().leaves()) {
                    LeafReader reader = FilterLeafReader.unwrap(context.reader());
                    if (reader instanceof SegmentReader) {
                        resources.add(Accountables.namedAccountable("segment", (SegmentReader) reader));
                    }
                }
            } finally {
                mgr.release(searcher);
            }
        }
        return Collections.unmodifiableList(resources);
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) LeafReader(org.apache.lucene.index.LeafReader) FilterLeafReader(org.apache.lucene.index.FilterLeafReader) ArrayList(java.util.ArrayList) Accountable(org.apache.lucene.util.Accountable) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) SearcherManager(org.apache.lucene.search.SearcherManager) IOException(java.io.IOException) SegmentReader(org.apache.lucene.index.SegmentReader)

Example 25 with LeafReader

use of org.apache.lucene.index.LeafReader in project lucene-solr by apache.

the class PointInGeo3DShapeQuery method createWeight.

@Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
    return new ConstantScoreWeight(this, boost) {

        @Override
        public Scorer scorer(LeafReaderContext context) throws IOException {
            LeafReader reader = context.reader();
            PointValues values = reader.getPointValues(field);
            if (values == null) {
                return null;
            }
            /*
        XYZBounds bounds = new XYZBounds();
        shape.getBounds(bounds);

        final double planetMax = planetModel.getMaximumMagnitude();
        if (planetMax != treeDV.planetMax) {
          throw new IllegalStateException(planetModel + " is not the same one used during indexing: planetMax=" + planetMax + " vs indexing planetMax=" + treeDV.planetMax);
        }
        */
            /*
        GeoArea xyzSolid = GeoAreaFactory.makeGeoArea(planetModel,
                                                      bounds.getMinimumX(),
                                                      bounds.getMaximumX(),
                                                      bounds.getMinimumY(),
                                                      bounds.getMaximumY(),
                                                      bounds.getMinimumZ(),
                                                      bounds.getMaximumZ());

        assert xyzSolid.getRelationship(shape) == GeoArea.WITHIN || xyzSolid.getRelationship(shape) == GeoArea.OVERLAPS: "expected WITHIN (1) or OVERLAPS (2) but got " + xyzSolid.getRelationship(shape) + "; shape="+shape+"; XYZSolid="+xyzSolid;
        */
            DocIdSetBuilder result = new DocIdSetBuilder(reader.maxDoc(), values, field);
            values.intersect(new PointInShapeIntersectVisitor(result, shape, shapeBounds));
            return new ConstantScoreScorer(this, score(), result.build().iterator());
        }
    };
}
Also used : PointValues(org.apache.lucene.index.PointValues) LeafReader(org.apache.lucene.index.LeafReader) ConstantScoreScorer(org.apache.lucene.search.ConstantScoreScorer) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) DocIdSetBuilder(org.apache.lucene.util.DocIdSetBuilder) ConstantScoreWeight(org.apache.lucene.search.ConstantScoreWeight)

Aggregations

LeafReader (org.apache.lucene.index.LeafReader)187 BytesRef (org.apache.lucene.util.BytesRef)69 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)68 Document (org.apache.lucene.document.Document)65 Directory (org.apache.lucene.store.Directory)62 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)55 DirectoryReader (org.apache.lucene.index.DirectoryReader)49 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)42 Test (org.junit.Test)41 IndexWriter (org.apache.lucene.index.IndexWriter)35 Terms (org.apache.lucene.index.Terms)34 NumericDocValues (org.apache.lucene.index.NumericDocValues)33 TermsEnum (org.apache.lucene.index.TermsEnum)32 IndexReader (org.apache.lucene.index.IndexReader)26 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)24 SortedSetDocValues (org.apache.lucene.index.SortedSetDocValues)24 Term (org.apache.lucene.index.Term)24 SortedDocValues (org.apache.lucene.index.SortedDocValues)22 Bits (org.apache.lucene.util.Bits)21 IOException (java.io.IOException)20