Search in sources :

Example 1 with IndexFieldDataCache

use of org.opensearch.index.fielddata.IndexFieldDataCache in project OpenSearch by opensearch-project.

the class PercolateQueryBuilder method wrap.

static QueryShardContext wrap(QueryShardContext shardContext) {
    return new QueryShardContext(shardContext) {

        @Override
        public IndexReader getIndexReader() {
            // the reader of the MemoryIndex. We just use `null` for simplicity.
            return null;
        }

        @Override
        public BitSetProducer bitsetFilter(Query query) {
            return context -> {
                final IndexReaderContext topLevelContext = ReaderUtil.getTopLevelContext(context);
                final IndexSearcher searcher = new IndexSearcher(topLevelContext);
                searcher.setQueryCache(null);
                final Weight weight = searcher.createWeight(searcher.rewrite(query), ScoreMode.COMPLETE_NO_SCORES, 1f);
                final Scorer s = weight.scorer(context);
                if (s != null) {
                    return new BitDocIdSet(BitSet.of(s.iterator(), context.reader().maxDoc())).bits();
                } else {
                    return null;
                }
            };
        }

        @Override
        @SuppressWarnings("unchecked")
        public <IFD extends IndexFieldData<?>> IFD getForField(MappedFieldType fieldType) {
            IndexFieldData.Builder builder = fieldType.fielddataBuilder(shardContext.getFullyQualifiedIndex().getName(), shardContext::lookup);
            IndexFieldDataCache cache = new IndexFieldDataCache.None();
            CircuitBreakerService circuitBreaker = new NoneCircuitBreakerService();
            return (IFD) builder.build(cache, circuitBreaker);
        }
    };
}
Also used : Query(org.apache.lucene.search.Query) ConstructingObjectParser(org.opensearch.common.xcontent.ConstructingObjectParser) FieldNameAnalyzer(org.opensearch.index.analysis.FieldNameAnalyzer) NoneCircuitBreakerService(org.opensearch.indices.breaker.NoneCircuitBreakerService) Version(org.opensearch.Version) InputStreamStreamInput(org.opensearch.common.io.stream.InputStreamStreamInput) BitSet(org.apache.lucene.util.BitSet) OpenSearchException(org.opensearch.OpenSearchException) XContentParser(org.opensearch.common.xcontent.XContentParser) MapperService(org.opensearch.index.mapper.MapperService) ByteArrayInputStream(java.io.ByteArrayInputStream) IndexFieldDataCache(org.opensearch.index.fielddata.IndexFieldDataCache) Directory(org.apache.lucene.store.Directory) XContentFactory(org.opensearch.common.xcontent.XContentFactory) ActionListener(org.opensearch.action.ActionListener) BitDocIdSet(org.apache.lucene.util.BitDocIdSet) Scorer(org.apache.lucene.search.Scorer) BytesRef(org.apache.lucene.util.BytesRef) MappedFieldType(org.opensearch.index.mapper.MappedFieldType) DirectoryReader(org.apache.lucene.index.DirectoryReader) Collection(java.util.Collection) LoggingDeprecationHandler(org.opensearch.common.xcontent.LoggingDeprecationHandler) QueryShardException(org.opensearch.index.query.QueryShardException) Objects(java.util.Objects) IndexWriter(org.apache.lucene.index.IndexWriter) List(java.util.List) QueryBuilder(org.opensearch.index.query.QueryBuilder) LeafReader(org.apache.lucene.index.LeafReader) QueryShardContext(org.opensearch.index.query.QueryShardContext) XContentType(org.opensearch.common.xcontent.XContentType) AbstractQueryBuilder(org.opensearch.index.query.AbstractQueryBuilder) BinaryDocValues(org.apache.lucene.index.BinaryDocValues) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) IndexReader(org.apache.lucene.index.IndexReader) IndexSearcher(org.apache.lucene.search.IndexSearcher) ReaderUtil(org.apache.lucene.index.ReaderUtil) BytesReference(org.opensearch.common.bytes.BytesReference) MemoryIndex(org.apache.lucene.index.memory.MemoryIndex) Weight(org.apache.lucene.search.Weight) StreamOutput(org.opensearch.common.io.stream.StreamOutput) ResourceNotFoundException(org.opensearch.ResourceNotFoundException) ParseField(org.opensearch.common.ParseField) Supplier(java.util.function.Supplier) ConstructingObjectParser.constructorArg(org.opensearch.common.xcontent.ConstructingObjectParser.constructorArg) NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) ArrayList(java.util.ArrayList) DeprecationLogger(org.opensearch.common.logging.DeprecationLogger) BitSetProducer(org.apache.lucene.search.join.BitSetProducer) IndexFieldData(org.opensearch.index.fielddata.IndexFieldData) SourceToParse(org.opensearch.index.mapper.SourceToParse) ByteBuffersDirectory(org.apache.lucene.store.ByteBuffersDirectory) DelegatingAnalyzerWrapper(org.apache.lucene.analysis.DelegatingAnalyzerWrapper) ParsedDocument(org.opensearch.index.mapper.ParsedDocument) ConstructingObjectParser.optionalConstructorArg(org.opensearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg) NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) StreamInput(org.opensearch.common.io.stream.StreamInput) ParseContext(org.opensearch.index.mapper.ParseContext) SetOnce(org.apache.lucene.util.SetOnce) Analyzer(org.apache.lucene.analysis.Analyzer) GetRequest(org.opensearch.action.get.GetRequest) Rewriteable(org.opensearch.index.query.Rewriteable) IOException(java.io.IOException) DocumentMapper(org.opensearch.index.mapper.DocumentMapper) ScoreMode(org.apache.lucene.search.ScoreMode) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) XContentHelper(org.opensearch.common.xcontent.XContentHelper) QueryRewriteContext(org.opensearch.index.query.QueryRewriteContext) CircuitBreakerService(org.opensearch.indices.breaker.CircuitBreakerService) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) ALLOW_EXPENSIVE_QUERIES(org.opensearch.search.SearchService.ALLOW_EXPENSIVE_QUERIES) Collections(java.util.Collections) IndexReaderContext(org.apache.lucene.index.IndexReaderContext) InputStream(java.io.InputStream) IndexSearcher(org.apache.lucene.search.IndexSearcher) BitDocIdSet(org.apache.lucene.util.BitDocIdSet) Query(org.apache.lucene.search.Query) Scorer(org.apache.lucene.search.Scorer) IndexReaderContext(org.apache.lucene.index.IndexReaderContext) Weight(org.apache.lucene.search.Weight) IndexFieldDataCache(org.opensearch.index.fielddata.IndexFieldDataCache) MappedFieldType(org.opensearch.index.mapper.MappedFieldType) QueryShardContext(org.opensearch.index.query.QueryShardContext) IndexFieldData(org.opensearch.index.fielddata.IndexFieldData) NoneCircuitBreakerService(org.opensearch.indices.breaker.NoneCircuitBreakerService) CircuitBreakerService(org.opensearch.indices.breaker.CircuitBreakerService) NoneCircuitBreakerService(org.opensearch.indices.breaker.NoneCircuitBreakerService)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Objects (java.util.Objects)1 Supplier (java.util.function.Supplier)1 Analyzer (org.apache.lucene.analysis.Analyzer)1 DelegatingAnalyzerWrapper (org.apache.lucene.analysis.DelegatingAnalyzerWrapper)1 BinaryDocValues (org.apache.lucene.index.BinaryDocValues)1 DirectoryReader (org.apache.lucene.index.DirectoryReader)1 IndexReader (org.apache.lucene.index.IndexReader)1 IndexReaderContext (org.apache.lucene.index.IndexReaderContext)1 IndexWriter (org.apache.lucene.index.IndexWriter)1 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)1 LeafReader (org.apache.lucene.index.LeafReader)1 ReaderUtil (org.apache.lucene.index.ReaderUtil)1 MemoryIndex (org.apache.lucene.index.memory.MemoryIndex)1