use of org.apache.lucene.queryparser.flexible.standard.StandardQueryParser in project geode by apache.
the class StringQueryProvider method getQuery.
@Override
public synchronized Query getQuery(LuceneIndex index) throws LuceneQueryException {
if (luceneQuery == null) {
String[] fields = index.getFieldNames();
LuceneIndexImpl indexImpl = (LuceneIndexImpl) index;
StandardQueryParser parser = new StandardQueryParser(indexImpl.getAnalyzer());
parser.setAllowLeadingWildcard(true);
try {
luceneQuery = parser.parse(query, defaultField);
if (logger.isDebugEnabled()) {
logger.debug("User query " + query + " is parsed to be: " + luceneQuery);
}
} catch (QueryNodeException e) {
logger.warn("Caught the following exception attempting parse query '" + query + "': ", e);
throw new LuceneQueryException(LocalizedStrings.StringQueryProvider_PARSING_QUERY_0_FAILED_DUE_TO_1.toLocalizedString("'" + query + "'", e.getMessage()));
}
}
return luceneQuery;
}
use of org.apache.lucene.queryparser.flexible.standard.StandardQueryParser in project jackrabbit-oak by apache.
the class LucenePropertyIndex method tokenToQuery.
static Query tokenToQuery(String text, String fieldName, Analyzer analyzer) {
if (analyzer == null) {
return null;
}
StandardQueryParser parserHelper = new StandardQueryParser(analyzer);
parserHelper.setAllowLeadingWildcard(true);
parserHelper.setDefaultOperator(StandardQueryConfigHandler.Operator.AND);
text = rewriteQueryText(text);
try {
return parserHelper.parse(text, fieldName);
} catch (QueryNodeException e) {
throw new RuntimeException(e);
}
}
use of org.apache.lucene.queryparser.flexible.standard.StandardQueryParser in project vertigo by KleeGroup.
the class RamLuceneQueryFactory method createFilteredQuery.
private static Query createFilteredQuery(final Analyzer queryAnalyser, final Query keywordsQuery, final List<ListFilter> filters) {
final Builder queryBuilder = new BooleanQuery.Builder().add(keywordsQuery, BooleanClause.Occur.MUST);
final StandardQueryParser queryParser = new StandardQueryParser(queryAnalyser);
for (final ListFilter filter : filters) {
try {
queryBuilder.add(queryParser.parse(filter.getFilterValue(), null), isExclusion(filter) ? BooleanClause.Occur.MUST_NOT : BooleanClause.Occur.MUST);
} catch (final QueryNodeException e) {
throw WrappedException.wrap(e, "Erreur lors de la création du filtrage de la requete");
}
}
return queryBuilder.build();
}
use of org.apache.lucene.queryparser.flexible.standard.StandardQueryParser in project vertigo by KleeGroup.
the class RamLuceneQueryFactory method createFilteredQuery.
private static Query createFilteredQuery(final Analyzer queryAnalyser, final Query keywordsQuery, final List<ListFilter> filters) {
final Builder queryBuilder = new BooleanQuery.Builder().add(keywordsQuery, BooleanClause.Occur.MUST);
final StandardQueryParser queryParser = new StandardQueryParser(queryAnalyser);
for (final ListFilter filter : filters) {
try {
queryBuilder.add(queryParser.parse(filter.getFilterValue(), null), isExclusion(filter) ? BooleanClause.Occur.MUST_NOT : BooleanClause.Occur.MUST);
} catch (final QueryNodeException e) {
throw WrappedException.wrap(e, "Erreur lors de la création du filtrage de la requete");
}
}
return queryBuilder.build();
}
use of org.apache.lucene.queryparser.flexible.standard.StandardQueryParser in project Anserini by castorini.
the class SearchCollection method searchBackgroundLinking.
public <K> ScoredDocuments searchBackgroundLinking(IndexSearcher searcher, K qid, String docid, RerankerCascade cascade) throws IOException {
// Extract a list of analyzed terms from the document to compose a query.
List<String> terms = BackgroundLinkingTopicReader.extractTerms(reader, docid, args.backgroundlinking_k, analyzer);
// Since the terms are already analyzed, we just join them together and use the StandardQueryParser.
Query docQuery;
try {
docQuery = new StandardQueryParser().parse(StringUtils.join(terms, " "), IndexArgs.CONTENTS);
} catch (QueryNodeException e) {
throw new RuntimeException("Unable to create a Lucene query comprised of terms extracted from query document!");
}
// Per track guidelines, no opinion or editorials. Filter out articles of these types.
Query filter = new TermInSetQuery(WashingtonPostGenerator.WashingtonPostField.KICKER.name, new BytesRef("Opinions"), new BytesRef("Letters to the Editor"), new BytesRef("The Post's View"));
BooleanQuery.Builder builder = new BooleanQuery.Builder();
builder.add(filter, BooleanClause.Occur.MUST_NOT);
builder.add(docQuery, BooleanClause.Occur.MUST);
Query query = builder.build();
// Search using constructed query.
TopDocs rs;
if (args.arbitraryScoreTieBreak) {
rs = searcher.search(query, (isRerank && args.rf_qrels == null) ? args.rerankcutoff : args.hits);
} else {
rs = searcher.search(query, (isRerank && args.rf_qrels == null) ? args.rerankcutoff : args.hits, BREAK_SCORE_TIES_BY_DOCID, true);
}
RerankerContext context = new RerankerContext<>(searcher, qid, query, docid, StringUtils.join(", ", terms), terms, null, args);
// Run the existing cascade.
ScoredDocuments docs = cascade.run(ScoredDocuments.fromTopDocs(rs, searcher), context);
// Perform post-processing (e.g., date filter, dedupping, etc.) as a final step.
return new NewsBackgroundLinkingReranker().rerank(docs, context);
}
Aggregations