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);
}
Aggregations