Search in sources :

Example 1 with QueryNodeException

use of org.apache.lucene.queryparser.flexible.core.QueryNodeException in project lucene-solr by apache.

the class AnyQueryNodeBuilder method build.

@Override
public BooleanQuery build(QueryNode queryNode) throws QueryNodeException {
    AnyQueryNode andNode = (AnyQueryNode) queryNode;
    BooleanQuery.Builder bQuery = new BooleanQuery.Builder();
    List<QueryNode> children = andNode.getChildren();
    if (children != null) {
        for (QueryNode child : children) {
            Object obj = child.getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);
            if (obj != null) {
                Query query = (Query) obj;
                try {
                    bQuery.add(query, BooleanClause.Occur.SHOULD);
                } catch (TooManyClauses ex) {
                    throw new QueryNodeException(new MessageImpl(/*
             * IQQQ.Q0028E_TOO_MANY_BOOLEAN_CLAUSES,
             * BooleanQuery.getMaxClauseCount()
             */
                    QueryParserMessages.EMPTY_MESSAGE), ex);
                }
            }
        }
    }
    bQuery.setMinimumNumberShouldMatch(andNode.getMinimumMatchingElements());
    return bQuery.build();
}
Also used : QueryNodeException(org.apache.lucene.queryparser.flexible.core.QueryNodeException) BooleanQuery(org.apache.lucene.search.BooleanQuery) Query(org.apache.lucene.search.Query) BooleanQuery(org.apache.lucene.search.BooleanQuery) QueryNode(org.apache.lucene.queryparser.flexible.core.nodes.QueryNode) AnyQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.AnyQueryNode) QueryTreeBuilder(org.apache.lucene.queryparser.flexible.core.builders.QueryTreeBuilder) TooManyClauses(org.apache.lucene.search.BooleanQuery.TooManyClauses) AnyQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.AnyQueryNode) MessageImpl(org.apache.lucene.queryparser.flexible.messages.MessageImpl)

Example 2 with QueryNodeException

use of org.apache.lucene.queryparser.flexible.core.QueryNodeException in project lucene-solr by apache.

the class BooleanQueryNodeBuilder method build.

@Override
public BooleanQuery build(QueryNode queryNode) throws QueryNodeException {
    BooleanQueryNode booleanNode = (BooleanQueryNode) queryNode;
    BooleanQuery.Builder bQuery = new BooleanQuery.Builder();
    List<QueryNode> children = booleanNode.getChildren();
    if (children != null) {
        for (QueryNode child : children) {
            Object obj = child.getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);
            if (obj != null) {
                Query query = (Query) obj;
                try {
                    bQuery.add(query, getModifierValue(child));
                } catch (TooManyClauses ex) {
                    throw new QueryNodeException(new MessageImpl(QueryParserMessages.TOO_MANY_BOOLEAN_CLAUSES, BooleanQuery.getMaxClauseCount(), queryNode.toQueryString(new EscapeQuerySyntaxImpl())), ex);
                }
            }
        }
    }
    return bQuery.build();
}
Also used : QueryNodeException(org.apache.lucene.queryparser.flexible.core.QueryNodeException) BooleanQuery(org.apache.lucene.search.BooleanQuery) Query(org.apache.lucene.search.Query) BooleanQuery(org.apache.lucene.search.BooleanQuery) BooleanQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.BooleanQueryNode) ModifierQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.ModifierQueryNode) QueryNode(org.apache.lucene.queryparser.flexible.core.nodes.QueryNode) QueryTreeBuilder(org.apache.lucene.queryparser.flexible.core.builders.QueryTreeBuilder) BooleanQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.BooleanQueryNode) TooManyClauses(org.apache.lucene.search.BooleanQuery.TooManyClauses) MessageImpl(org.apache.lucene.queryparser.flexible.messages.MessageImpl) EscapeQuerySyntaxImpl(org.apache.lucene.queryparser.flexible.standard.parser.EscapeQuerySyntaxImpl)

Example 3 with QueryNodeException

use of org.apache.lucene.queryparser.flexible.core.QueryNodeException in project lucene-solr by apache.

the class PointRangeQueryNodeBuilder method build.

@Override
public Query build(QueryNode queryNode) throws QueryNodeException {
    PointRangeQueryNode numericRangeNode = (PointRangeQueryNode) queryNode;
    PointQueryNode lowerNumericNode = numericRangeNode.getLowerBound();
    PointQueryNode upperNumericNode = numericRangeNode.getUpperBound();
    Number lowerNumber = lowerNumericNode.getValue();
    Number upperNumber = upperNumericNode.getValue();
    PointsConfig pointsConfig = numericRangeNode.getPointsConfig();
    Class<? extends Number> numberType = pointsConfig.getType();
    String field = StringUtils.toString(numericRangeNode.getField());
    boolean minInclusive = numericRangeNode.isLowerInclusive();
    boolean maxInclusive = numericRangeNode.isUpperInclusive();
    // TODO: push down cleaning up of crazy nulls and inclusive/exclusive elsewhere
    if (Integer.class.equals(numberType)) {
        Integer lower = (Integer) lowerNumber;
        if (lower == null) {
            lower = Integer.MIN_VALUE;
        }
        if (minInclusive == false) {
            lower = lower + 1;
        }
        Integer upper = (Integer) upperNumber;
        if (upper == null) {
            upper = Integer.MAX_VALUE;
        }
        if (maxInclusive == false) {
            upper = upper - 1;
        }
        return IntPoint.newRangeQuery(field, lower, upper);
    } else if (Long.class.equals(numberType)) {
        Long lower = (Long) lowerNumber;
        if (lower == null) {
            lower = Long.MIN_VALUE;
        }
        if (minInclusive == false) {
            lower = lower + 1;
        }
        Long upper = (Long) upperNumber;
        if (upper == null) {
            upper = Long.MAX_VALUE;
        }
        if (maxInclusive == false) {
            upper = upper - 1;
        }
        return LongPoint.newRangeQuery(field, lower, upper);
    } else if (Float.class.equals(numberType)) {
        Float lower = (Float) lowerNumber;
        if (lower == null) {
            lower = Float.NEGATIVE_INFINITY;
        }
        if (minInclusive == false) {
            lower = Math.nextUp(lower);
        }
        Float upper = (Float) upperNumber;
        if (upper == null) {
            upper = Float.POSITIVE_INFINITY;
        }
        if (maxInclusive == false) {
            upper = Math.nextDown(upper);
        }
        return FloatPoint.newRangeQuery(field, lower, upper);
    } else if (Double.class.equals(numberType)) {
        Double lower = (Double) lowerNumber;
        if (lower == null) {
            lower = Double.NEGATIVE_INFINITY;
        }
        if (minInclusive == false) {
            lower = Math.nextUp(lower);
        }
        Double upper = (Double) upperNumber;
        if (upper == null) {
            upper = Double.POSITIVE_INFINITY;
        }
        if (maxInclusive == false) {
            upper = Math.nextDown(upper);
        }
        return DoublePoint.newRangeQuery(field, lower, upper);
    } else {
        throw new QueryNodeException(new MessageImpl(QueryParserMessages.UNSUPPORTED_NUMERIC_DATA_TYPE, numberType));
    }
}
Also used : QueryNodeException(org.apache.lucene.queryparser.flexible.core.QueryNodeException) PointsConfig(org.apache.lucene.queryparser.flexible.standard.config.PointsConfig) PointRangeQueryNode(org.apache.lucene.queryparser.flexible.standard.nodes.PointRangeQueryNode) MessageImpl(org.apache.lucene.queryparser.flexible.messages.MessageImpl) PointQueryNode(org.apache.lucene.queryparser.flexible.standard.nodes.PointQueryNode)

Example 4 with QueryNodeException

use of org.apache.lucene.queryparser.flexible.core.QueryNodeException 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;
}
Also used : QueryNodeException(org.apache.lucene.queryparser.flexible.core.QueryNodeException) LuceneQueryException(org.apache.geode.cache.lucene.LuceneQueryException) StandardQueryParser(org.apache.lucene.queryparser.flexible.standard.StandardQueryParser)

Example 5 with QueryNodeException

use of org.apache.lucene.queryparser.flexible.core.QueryNodeException 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);
    }
}
Also used : QueryNodeException(org.apache.lucene.queryparser.flexible.core.QueryNodeException) StandardQueryParser(org.apache.lucene.queryparser.flexible.standard.StandardQueryParser)

Aggregations

QueryNodeException (org.apache.lucene.queryparser.flexible.core.QueryNodeException)9 StandardQueryParser (org.apache.lucene.queryparser.flexible.standard.StandardQueryParser)5 BooleanQuery (org.apache.lucene.search.BooleanQuery)5 MessageImpl (org.apache.lucene.queryparser.flexible.messages.MessageImpl)3 Query (org.apache.lucene.search.Query)3 ListFilter (io.vertigo.dynamo.collections.ListFilter)2 QueryTreeBuilder (org.apache.lucene.queryparser.flexible.core.builders.QueryTreeBuilder)2 QueryNode (org.apache.lucene.queryparser.flexible.core.nodes.QueryNode)2 Builder (org.apache.lucene.search.BooleanQuery.Builder)2 TooManyClauses (org.apache.lucene.search.BooleanQuery.TooManyClauses)2 RerankerContext (io.anserini.rerank.RerankerContext)1 ScoredDocuments (io.anserini.rerank.ScoredDocuments)1 NewsBackgroundLinkingReranker (io.anserini.rerank.lib.NewsBackgroundLinkingReranker)1 DateFormat (java.text.DateFormat)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 Locale (java.util.Locale)1 TimeZone (java.util.TimeZone)1 LuceneQueryException (org.apache.geode.cache.lucene.LuceneQueryException)1 Analyzer (org.apache.lucene.analysis.Analyzer)1