Search in sources :

Example 1 with TermRangeFilter

use of org.apache.lucene.search.TermRangeFilter 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);
        }
        reader = IndexReader.open(writer, true);
    } catch (IOException e) {
        throw new IgniteCheckedException(e);
    }
    IndexSearcher searcher = new IndexSearcher(reader);
    MultiFieldQueryParser parser = new MultiFieldQueryParser(Version.LUCENE_30, idxdFields, writer.getAnalyzer());
    // Filter expired items.
    Filter f = new TermRangeFilter(EXPIRATION_TIME_FIELD_NAME, DateTools.timeToString(U.currentTimeMillis(), DateTools.Resolution.MILLISECOND), null, false, false);
    TopDocs docs;
    try {
        docs = searcher.search(parser.parse(qry), f, Integer.MAX_VALUE);
    } catch (Exception e) {
        throw new IgniteCheckedException(e);
    }
    IgniteBiPredicate<K, V> 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) MultiFieldQueryParser(org.apache.lucene.queryParser.MultiFieldQueryParser) IOException(java.io.IOException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IOException(java.io.IOException) TopDocs(org.apache.lucene.search.TopDocs) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IndexingQueryFilter(org.apache.ignite.spi.indexing.IndexingQueryFilter) TermRangeFilter(org.apache.lucene.search.TermRangeFilter) Filter(org.apache.lucene.search.Filter) IndexReader(org.apache.lucene.index.IndexReader) TermRangeFilter(org.apache.lucene.search.TermRangeFilter)

Aggregations

IOException (java.io.IOException)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IndexingQueryFilter (org.apache.ignite.spi.indexing.IndexingQueryFilter)1 IndexReader (org.apache.lucene.index.IndexReader)1 MultiFieldQueryParser (org.apache.lucene.queryParser.MultiFieldQueryParser)1 Filter (org.apache.lucene.search.Filter)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 TermRangeFilter (org.apache.lucene.search.TermRangeFilter)1 TopDocs (org.apache.lucene.search.TopDocs)1