List of usage examples for org.apache.lucene.queryparser.flexible.messages MessageImpl MessageImpl
public MessageImpl(String key, Object... args)
From source file:com.sindicetech.siren.qparser.keyword.builders.ArrayQueryNodeBuilder.java
License:Open Source License
@Override public Query build(final QueryNode queryNode) throws QueryNodeException { final ArrayQueryNode arrayNode = (ArrayQueryNode) queryNode; final List<QueryNode> children = arrayNode.getChildren(); final ArrayQuery arrayQuery = new ArrayQuery(); for (final QueryNode child : children) { final Object v = child.getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID); if (v == null) { // DummyNode such as the EmptyNodeQueryNode continue; }//from w w w . ja v a2 s. c o m if (v instanceof Query) { if (v instanceof ArrayQuery) { /* * Nested array query. It is transformed as a TwigQuery with empty root */ final TwigQuery twigQuery = new TwigQuery(); for (final Query qn : ((ArrayQuery) v).getElements()) { final NodeQuery valQuery = (NodeQuery) qn; twigQuery.addChild(valQuery, NodeQueryBuilderUtil.getModifierValue(child, NodeBooleanClause.Occur.MUST)); } arrayQuery.addElement(twigQuery); } else { arrayQuery.addElement((NodeQuery) v); } } else { throw new QueryNodeException(new MessageImpl(QueryParserMessages.INVALID_SYNTAX, "Unexpected class of a Twig Query clause: " + v == null ? "null" : v.getClass().getName())); } } return arrayQuery; }
From source file:com.sindicetech.siren.qparser.keyword.builders.concise.ConciseNodeNumericRangeQueryNodeBuilder.java
License:Open Source License
@Override protected NodeNumericRangeQuery newNodeNumericRangeQuery(final NumericType numberType, final String field, final int precisionStep, final Number lowerNumber, final Number upperNumber, final boolean minInclusive, final boolean maxInclusive) throws QueryNodeException { if (conf.has(ConciseKeywordQueryConfigHandler.ConciseKeywordConfigurationKeys.ATTRIBUTE)) { final String attribute = conf .get(ConciseKeywordQueryConfigHandler.ConciseKeywordConfigurationKeys.ATTRIBUTE); switch (numberType) { case LONG: return ConciseNodeNumericRangeQuery.newLongRange(field, attribute, precisionStep, (Long) lowerNumber, (Long) upperNumber, minInclusive, maxInclusive); case INT: return ConciseNodeNumericRangeQuery.newIntRange(field, attribute, precisionStep, (Integer) lowerNumber, (Integer) upperNumber, minInclusive, maxInclusive); case FLOAT: return ConciseNodeNumericRangeQuery.newFloatRange(field, attribute, precisionStep, (Float) lowerNumber, (Float) upperNumber, minInclusive, maxInclusive); case DOUBLE: return ConciseNodeNumericRangeQuery.newDoubleRange(field, attribute, precisionStep, (Double) lowerNumber, (Double) upperNumber, minInclusive, maxInclusive); default:/*from ww w . j a v a2 s. co m*/ throw new QueryNodeException( new MessageImpl(QueryParserMessages.UNSUPPORTED_NUMERIC_DATA_TYPE, numberType)); } } else { return super.newNodeNumericRangeQuery(numberType, field, precisionStep, lowerNumber, upperNumber, minInclusive, maxInclusive); } }
From source file:com.sindicetech.siren.qparser.keyword.builders.NodeNumericRangeQueryNodeBuilder.java
License:Open Source License
protected NodeNumericRangeQuery newNodeNumericRangeQuery(final NumericType numberType, final String field, final int precisionStep, final Number lowerNumber, final Number upperNumber, final boolean minInclusive, final boolean maxInclusive) throws QueryNodeException { switch (numberType) { case LONG:/*w ww . j a v a 2s .co m*/ return NodeNumericRangeQuery.newLongRange(field, precisionStep, (Long) lowerNumber, (Long) upperNumber, minInclusive, maxInclusive); case INT: return NodeNumericRangeQuery.newIntRange(field, precisionStep, (Integer) lowerNumber, (Integer) upperNumber, minInclusive, maxInclusive); case FLOAT: return NodeNumericRangeQuery.newFloatRange(field, precisionStep, (Float) lowerNumber, (Float) upperNumber, minInclusive, maxInclusive); case DOUBLE: return NodeNumericRangeQuery.newDoubleRange(field, precisionStep, (Double) lowerNumber, (Double) upperNumber, minInclusive, maxInclusive); default: throw new QueryNodeException( new MessageImpl(QueryParserMessages.UNSUPPORTED_NUMERIC_DATA_TYPE, numberType)); } }
From source file:com.sindicetech.siren.qparser.keyword.processors.AllowFuzzyAndWildcardProcessor.java
License:Open Source License
@Override protected QueryNode postProcessNode(final QueryNode node) throws QueryNodeException { if (node instanceof WildcardQueryNode) { throw new QueryNodeException( new MessageImpl("Wildcard not allowed", node.toQueryString(new EscapeQuerySyntaxImpl()))); }/*from w w w . j a v a2 s.c o m*/ if (node instanceof FuzzyQueryNode) { throw new QueryNodeException( new MessageImpl("Fuzzy not allowed", node.toQueryString(new EscapeQuerySyntaxImpl()))); } return node; }
From source file:com.sindicetech.siren.qparser.keyword.processors.AllowTwigProcessor.java
License:Open Source License
@Override protected QueryNode preProcessNode(final QueryNode node) throws QueryNodeException { if (node instanceof TwigQueryNode) { if (this.getQueryConfigHandler().has(KeywordConfigurationKeys.ALLOW_TWIG)) { if (!this.getQueryConfigHandler().get(KeywordConfigurationKeys.ALLOW_TWIG)) { throw new QueryNodeException(new MessageImpl("TwigQuery not allowed", node.toQueryString(new EscapeQuerySyntaxImpl()))); }//from w ww .j a v a 2s . com } else { throw new IllegalArgumentException( "KeywordConfigurationKeys.ALLOW_TWIG should be set on the ExtendedKeywordQueryConfigHandler"); } } return node; }
From source file:com.sindicetech.siren.qparser.keyword.processors.DatatypeAnalyzerProcessor.java
License:Open Source License
private Analyzer getAnalyzer(String datatype) throws QueryNodeException { final Analyzer analyzer = this.getQueryConfigHandler().get(KeywordConfigurationKeys.DATATYPES_ANALYZERS) .get(datatype);/*from ww w . j a v a2 s.c o m*/ if (analyzer == null) { throw new QueryNodeException( new MessageImpl(QueryParserMessages.INVALID_SYNTAX, "No analyzer associated with " + datatype)); } return analyzer; }
From source file:com.sindicetech.siren.qparser.keyword.processors.NodeNumericQueryNodeProcessor.java
License:Open Source License
@Override protected QueryNode postProcessNode(QueryNode node) throws QueryNodeException { if (node instanceof FieldQueryNode && !(node.getParent() instanceof RangeQueryNode)) { final FieldQueryNode fieldNode = (FieldQueryNode) node; String datatype = (String) DatatypeProcessor.getDatatype(this.getQueryConfigHandler(), node); final Map<String, Analyzer> dts = this.getQueryConfigHandler() .get(KeywordConfigurationKeys.DATATYPES_ANALYZERS); final Analyzer analyzer = dts.get(node.getTag(DatatypeQueryNode.DATATYPE_TAGID)); if (analyzer instanceof NumericAnalyzer) { final NumericAnalyzer na = (NumericAnalyzer) analyzer; final char[] text = fieldNode.getTextAsString().toCharArray(); final ReusableCharArrayReader textReader = new ReusableCharArrayReader(text); final Number number; try { number = na.getNumericParser().parse(textReader); } catch (final Exception e) { throw new QueryNodeParseException( new MessageImpl(QueryParserMessages.COULD_NOT_PARSE_NUMBER, text), e); }/*from w ww. jav a 2 s .c o m*/ final CharSequence field = fieldNode.getField(); final NodeNumericQueryNode lowerNode = new NodeNumericQueryNode(field, number); // assign datatype lowerNode.setTag(DatatypeQueryNode.DATATYPE_TAGID, datatype); final NodeNumericQueryNode upperNode = new NodeNumericQueryNode(field, number); // assign datatype upperNode.setTag(DatatypeQueryNode.DATATYPE_TAGID, datatype); // Create the NodeNumericRangeQueryNode node = new NodeNumericRangeQueryNode(lowerNode, upperNode, true, true, na); // assign datatype node.setTag(DatatypeQueryNode.DATATYPE_TAGID, datatype); } } return node; }
From source file:com.sindicetech.siren.qparser.keyword.processors.NotSupportedQueryProcessor.java
License:Open Source License
@Override protected QueryNode preProcessNode(final QueryNode node) throws QueryNodeException { if (node instanceof SlopQueryNode && ((SlopQueryNode) node).getValue() != 0) { throw new QueryNodeException(new MessageImpl("Slop queries are not supported", node.toQueryString(new EscapeQuerySyntaxImpl()))); } else if (node instanceof MultiPhraseQueryNode) { throw new QueryNodeException(new MessageImpl("Multi phrase queries are not supported", node.toQueryString(new EscapeQuerySyntaxImpl()))); } else if (node instanceof MatchAllDocsQueryNodeBuilder) { throw new QueryNodeException(new MessageImpl("MatchAllDocsQueries are not supported", node.toQueryString(new EscapeQuerySyntaxImpl()))); }//from ww w. ja va2 s .co m return node; }
From source file:com.sindicetech.siren.qparser.keyword.processors.QueryTypeProcessor.java
License:Open Source License
@Override protected QueryNode preProcessNode(QueryNode node) throws QueryNodeException { // If the current node is a group query node, check the query type and assign it to its children if (node instanceof GroupQueryNode) { GroupQueryNode groupQueryNode = (GroupQueryNode) node; String queryType = null;//from w w w . java 2s . c om if (node instanceof NodeGroupQueryNode) { queryType = NODE_QUERYTYPE; } else if (node instanceof SpanGroupQueryNode) { queryType = SPAN_QUERYTYPE; } else { throw new QueryNodeException(new MessageImpl("Invalid GroupQueryNode received", node.toQueryString(new EscapeQuerySyntaxImpl()))); } // transfer the query type to its child groupQueryNode.getChild().setTag(QUERYTYPE_TAG, queryType); } // in any other cases, if the node is not a leaf node, transfer the query type to its children else if (!node.isLeaf()) { if (node.getTag(QUERYTYPE_TAG) != null) { for (final QueryNode child : node.getChildren()) { child.setTag(QUERYTYPE_TAG, node.getTag(QUERYTYPE_TAG)); } } } return node; }
From source file:com.sindicetech.siren.qparser.tree.ParseException.java
License:Open Source License
public ParseException(final String message, final Throwable throwable) { super(new MessageImpl(QueryParserMessages.INVALID_SYNTAX, message), throwable); }