Search in sources :

Example 6 with MultiFieldQueryParser

use of org.apache.lucene.queryparser.classic.MultiFieldQueryParser in project textdb by TextDB.

the class RegexMatcherSourceOperator method createLuceneQuery.

public static Query createLuceneQuery(RegexSourcePredicate predicate) throws StorageException {
    Query luceneQuery;
    String queryString;
    // Try to apply translator. If it fails, use scan query.
    try {
        queryString = RegexToGramQueryTranslator.translate(predicate.getRegex()).getLuceneQueryString();
    } catch (com.google.re2j.PatternSyntaxException e) {
        queryString = DataConstants.SCAN_QUERY;
    }
    // Try to parse the query string. It if fails, raise an exception.
    try {
        luceneQuery = new MultiFieldQueryParser(predicate.getAttributeNames().stream().toArray(String[]::new), RelationManager.getRelationManager().getTableAnalyzer(predicate.getTableName())).parse(queryString);
    } catch (ParseException e) {
        throw new StorageException(e);
    }
    return luceneQuery;
}
Also used : Query(org.apache.lucene.search.Query) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) MultiFieldQueryParser(org.apache.lucene.queryparser.classic.MultiFieldQueryParser) ParseException(org.apache.lucene.queryparser.classic.ParseException) StorageException(edu.uci.ics.textdb.api.exception.StorageException)

Aggregations

MultiFieldQueryParser (org.apache.lucene.queryparser.classic.MultiFieldQueryParser)6 Query (org.apache.lucene.search.Query)4 ParseException (org.apache.lucene.queryparser.classic.ParseException)3 IndexSearcher (org.apache.lucene.search.IndexSearcher)3 IndexReader (org.apache.lucene.index.IndexReader)2 QueryParser (org.apache.lucene.queryparser.classic.QueryParser)2 TopDocs (org.apache.lucene.search.TopDocs)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)1 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)1 DataFlowException (edu.uci.ics.textdb.api.exception.DataFlowException)1 StorageException (edu.uci.ics.textdb.api.exception.StorageException)1 ScoredDocuments (io.anserini.rerank.ScoredDocuments)1 IOException (java.io.IOException)1 Map (java.util.Map)1 Analyzer (org.apache.lucene.analysis.Analyzer)1 SimpleAnalyzer (org.apache.lucene.analysis.core.SimpleAnalyzer)1 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)1 Document (org.apache.lucene.document.Document)1 TextField (org.apache.lucene.document.TextField)1