querqy.elasticsearch.QuerqyProcessor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of querqy-elasticsearch Show documentation
Show all versions of querqy-elasticsearch Show documentation
Querqy library for query rewriting: Querqy for Elasticsearch
package querqy.elasticsearch;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.Query;
import org.elasticsearch.index.query.SearchExecutionContext;
import querqy.elasticsearch.infologging.LogPayloadType;
import querqy.elasticsearch.infologging.SingleSinkInfoLogging;
import querqy.elasticsearch.query.InfoLoggingSpec;
import querqy.elasticsearch.query.QuerqyQueryBuilder;
import querqy.elasticsearch.query.Rewriter;
import querqy.infologging.InfoLogging;
import querqy.infologging.Sink;
import querqy.lucene.LuceneQueries;
import querqy.lucene.LuceneSearchEngineRequestAdapter;
import querqy.lucene.QueryParsingController;
import querqy.rewrite.RewriteChain;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
public class QuerqyProcessor {
private static final RewriteChain EMPTY_REWRITE_CHAIN = new RewriteChain(Collections.emptyList());
private RewriterShardContexts rewriterShardContexts;
private Sink infoLoggingSink;
public QuerqyProcessor(final RewriterShardContexts rewriterShardContexts, final Sink infoLoggingSink) {
this.rewriterShardContexts = rewriterShardContexts;
this.infoLoggingSink = infoLoggingSink;
}
public Query parseQuery(final QuerqyQueryBuilder queryBuilder, final SearchExecutionContext context)
throws LuceneSearchEngineRequestAdapter.SyntaxException {
final List rewriters = queryBuilder.getRewriters();
final RewriteChain rewriteChain;
final Set rewritersEnabledForLogging;
if (rewriters == null || rewriters.isEmpty()) {
rewriteChain = EMPTY_REWRITE_CHAIN;
rewritersEnabledForLogging = Collections.emptySet();
} else {
final RewriteChainAndLogging rewriteChainAndLogging = rewriterShardContexts.getRewriteChain(
rewriters.stream().map(Rewriter::getName).collect(Collectors.toList()), context);
rewriteChain = rewriteChainAndLogging.rewriteChain;
final InfoLoggingSpec infoLoggingSpec = queryBuilder.getInfoLoggingSpec();
if ((infoLoggingSpec != null) && (infoLoggingSpec.getPayloadType() != LogPayloadType.NONE)
&& !infoLoggingSpec.isLogged()) {
infoLoggingSpec.setLogged(true);
rewritersEnabledForLogging = rewriteChainAndLogging.rewritersEnabledForLogging;
} else {
rewritersEnabledForLogging = Collections.emptySet();
}
}
final InfoLogging infoLogging = rewritersEnabledForLogging.isEmpty()
? null : new SingleSinkInfoLogging(infoLoggingSink, rewritersEnabledForLogging);
final DismaxSearchEngineRequestAdapter requestAdapter =
new DismaxSearchEngineRequestAdapter(queryBuilder, rewriteChain, context, infoLogging);
final QueryParsingController controller = new QueryParsingController(requestAdapter);
final LuceneQueries queries = controller.process();
// // TODO: make decos part of the general Querqy object model
// final Set
© 2015 - 2024 Weber Informatics LLC | Privacy Policy