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();
}
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();
}
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));
}
}
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;
}
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);
}
}
Aggregations