Search in sources :

Example 1 with PrefixWildcardQueryNode

use of org.apache.lucene.queryparser.flexible.standard.nodes.PrefixWildcardQueryNode in project lucene-solr by apache.

the class WildcardQueryNodeProcessor method postProcessNode.

@Override
protected QueryNode postProcessNode(QueryNode node) throws QueryNodeException {
    // we do the same here, also ignore empty terms
    if (node instanceof FieldQueryNode || node instanceof FuzzyQueryNode) {
        FieldQueryNode fqn = (FieldQueryNode) node;
        CharSequence text = fqn.getText();
        // QuotedFieldQueryNode to reproduce the old parser behavior
        if (fqn.getParent() instanceof TermRangeQueryNode || fqn instanceof QuotedFieldQueryNode || text.length() <= 0) {
            // Ignore empty terms
            return node;
        }
        if (isWildcard(text)) {
            Analyzer analyzer = getQueryConfigHandler().get(ConfigurationKeys.ANALYZER);
            if (analyzer != null) {
                text = analyzeWildcard(analyzer, fqn.getFieldAsString(), text.toString());
            }
            if (isPrefixWildcard(text)) {
                return new PrefixWildcardQueryNode(fqn.getField(), text, fqn.getBegin(), fqn.getEnd());
            } else {
                return new WildcardQueryNode(fqn.getField(), text, fqn.getBegin(), fqn.getEnd());
            }
        }
    }
    return node;
}
Also used : FuzzyQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.FuzzyQueryNode) FieldQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.FieldQueryNode) QuotedFieldQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.QuotedFieldQueryNode) PrefixWildcardQueryNode(org.apache.lucene.queryparser.flexible.standard.nodes.PrefixWildcardQueryNode) WildcardQueryNode(org.apache.lucene.queryparser.flexible.standard.nodes.WildcardQueryNode) UnescapedCharSequence(org.apache.lucene.queryparser.flexible.core.util.UnescapedCharSequence) QuotedFieldQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.QuotedFieldQueryNode) PrefixWildcardQueryNode(org.apache.lucene.queryparser.flexible.standard.nodes.PrefixWildcardQueryNode) TermRangeQueryNode(org.apache.lucene.queryparser.flexible.standard.nodes.TermRangeQueryNode) Analyzer(org.apache.lucene.analysis.Analyzer)

Example 2 with PrefixWildcardQueryNode

use of org.apache.lucene.queryparser.flexible.standard.nodes.PrefixWildcardQueryNode in project lucene-solr by apache.

the class PrefixWildcardQueryNodeBuilder method build.

@Override
public PrefixQuery build(QueryNode queryNode) throws QueryNodeException {
    PrefixWildcardQueryNode wildcardNode = (PrefixWildcardQueryNode) queryNode;
    String text = wildcardNode.getText().subSequence(0, wildcardNode.getText().length() - 1).toString();
    PrefixQuery q = new PrefixQuery(new Term(wildcardNode.getFieldAsString(), text));
    MultiTermQuery.RewriteMethod method = (MultiTermQuery.RewriteMethod) queryNode.getTag(MultiTermRewriteMethodProcessor.TAG_ID);
    if (method != null) {
        q.setRewriteMethod(method);
    }
    return q;
}
Also used : MultiTermQuery(org.apache.lucene.search.MultiTermQuery) PrefixQuery(org.apache.lucene.search.PrefixQuery) PrefixWildcardQueryNode(org.apache.lucene.queryparser.flexible.standard.nodes.PrefixWildcardQueryNode) Term(org.apache.lucene.index.Term)

Aggregations

PrefixWildcardQueryNode (org.apache.lucene.queryparser.flexible.standard.nodes.PrefixWildcardQueryNode)2 Analyzer (org.apache.lucene.analysis.Analyzer)1 Term (org.apache.lucene.index.Term)1 FieldQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.FieldQueryNode)1 FuzzyQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.FuzzyQueryNode)1 QuotedFieldQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.QuotedFieldQueryNode)1 UnescapedCharSequence (org.apache.lucene.queryparser.flexible.core.util.UnescapedCharSequence)1 TermRangeQueryNode (org.apache.lucene.queryparser.flexible.standard.nodes.TermRangeQueryNode)1 WildcardQueryNode (org.apache.lucene.queryparser.flexible.standard.nodes.WildcardQueryNode)1 MultiTermQuery (org.apache.lucene.search.MultiTermQuery)1 PrefixQuery (org.apache.lucene.search.PrefixQuery)1