Search in sources :

Example 6 with IndexingQueryCacheFilter

use of org.apache.ignite.spi.indexing.IndexingQueryCacheFilter in project ignite by apache.

the class GridLuceneIndex method query.

/**
 * Runs lucene fulltext query over this index.
 *
 * @param qry Query.
 * @param filters Filters over result.
 * @return Query result.
 * @throws IgniteCheckedException If failed.
 */
public <K, V> GridCloseableIterator<IgniteBiTuple<K, V>> query(String qry, IndexingQueryFilter filters) throws IgniteCheckedException {
    IndexReader reader;
    try {
        long updates = updateCntr.get();
        if (updates != 0) {
            writer.commit();
            updateCntr.addAndGet(-updates);
        }
        // We can cache reader\searcher and change this to 'openIfChanged'
        reader = DirectoryReader.open(writer, true);
    } catch (IOException e) {
        throw new IgniteCheckedException(e);
    }
    IndexSearcher searcher;
    TopDocs docs;
    try {
        searcher = new IndexSearcher(reader);
        MultiFieldQueryParser parser = new MultiFieldQueryParser(idxdFields, writer.getAnalyzer());
        // parser.setAllowLeadingWildcard(true);
        // Filter expired items.
        Query filter = NumericRangeQuery.newLongRange(EXPIRATION_TIME_FIELD_NAME, U.currentTimeMillis(), null, false, false);
        BooleanQuery query = new BooleanQuery.Builder().add(parser.parse(qry), BooleanClause.Occur.MUST).add(filter, BooleanClause.Occur.FILTER).build();
        docs = searcher.search(query, Integer.MAX_VALUE);
    } catch (Exception e) {
        U.closeQuiet(reader);
        throw new IgniteCheckedException(e);
    }
    IndexingQueryCacheFilter fltr = null;
    if (filters != null)
        fltr = filters.forCache(cacheName);
    return new It<>(reader, searcher, docs.scoreDocs, fltr);
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) BooleanQuery(org.apache.lucene.search.BooleanQuery) MultiFieldQueryParser(org.apache.lucene.queryparser.classic.MultiFieldQueryParser) Query(org.apache.lucene.search.Query) NumericRangeQuery(org.apache.lucene.search.NumericRangeQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) IOException(java.io.IOException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IOException(java.io.IOException) TopDocs(org.apache.lucene.search.TopDocs) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IndexReader(org.apache.lucene.index.IndexReader) IndexingQueryCacheFilter(org.apache.ignite.spi.indexing.IndexingQueryCacheFilter)

Aggregations

IndexingQueryCacheFilter (org.apache.ignite.spi.indexing.IndexingQueryCacheFilter)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 GridH2Row (org.apache.ignite.internal.processors.query.h2.opt.GridH2Row)3 ArrayList (java.util.ArrayList)2 H2Cursor (org.apache.ignite.internal.processors.query.h2.H2Cursor)2 IndexingQueryFilter (org.apache.ignite.spi.indexing.IndexingQueryFilter)2 IOException (java.io.IOException)1 IgniteCacheOffheapManager (org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager)1 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)1 CacheDataRow (org.apache.ignite.internal.processors.cache.persistence.CacheDataRow)1 H2RowLinkIO (org.apache.ignite.internal.processors.query.h2.database.io.H2RowLinkIO)1 GridCursorIteratorWrapper (org.apache.ignite.internal.util.GridCursorIteratorWrapper)1 GridCursor (org.apache.ignite.internal.util.lang.GridCursor)1 IndexReader (org.apache.lucene.index.IndexReader)1 MultiFieldQueryParser (org.apache.lucene.queryparser.classic.MultiFieldQueryParser)1 BooleanQuery (org.apache.lucene.search.BooleanQuery)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 NumericRangeQuery (org.apache.lucene.search.NumericRangeQuery)1 Query (org.apache.lucene.search.Query)1 TopDocs (org.apache.lucene.search.TopDocs)1