List of usage examples for org.apache.lucene.queryparser.flexible.standard.parser EscapeQuerySyntaxImpl EscapeQuerySyntaxImpl
EscapeQuerySyntaxImpl
From source file:com.sindicetech.siren.qparser.keyword.builders.BooleanQueryNodeBuilder.java
License:Open Source License
public Query build(final QueryNode queryNode) throws QueryNodeException { final BooleanQueryNode booleanNode = (BooleanQueryNode) queryNode; final BooleanQuery bQuery = new BooleanQuery(); final List<QueryNode> children = booleanNode.getChildren(); if (children != null) { for (final QueryNode child : children) { final Object obj = child.getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID); if (obj != null) { final Query query = (Query) obj; try { final QueryNode mod; if (child instanceof DatatypeQueryNode) { mod = ((DatatypeQueryNode) child).getChild(); } else { mod = child;//w w w .j a v a2 s. c o m } bQuery.add(query, getModifierValue(mod)); } catch (final TooManyClauses ex) { throw new QueryNodeException(new MessageImpl(QueryParserMessages.TOO_MANY_BOOLEAN_CLAUSES, BooleanQuery.getMaxClauseCount(), queryNode.toQueryString(new EscapeQuerySyntaxImpl())), ex); } } } } return bQuery; }
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 . com 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()))); }//w ww . j ava2s.co m } else { throw new IllegalArgumentException( "KeywordConfigurationKeys.ALLOW_TWIG should be set on the ExtendedKeywordQueryConfigHandler"); } } 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 w w w .j ava 2s.c o 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 . j a v a 2 s . c o m 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.builders.BooleanQueryNodeBuilder.java
License:Open Source License
private final BooleanSpanQuery buildBooleanSpanQuery(BooleanQueryNode booleanNode) throws QueryNodeException { // check if the node has a slop int slop = this.DEFAULT_SLOP; if (booleanNode.getTag(SlopPropertyParser.SLOP_PROPERTY) != null) { slop = (Integer) booleanNode.getTag(SlopPropertyParser.SLOP_PROPERTY); }/*from w ww . ja va2 s . c om*/ // check if the node has a inOrder flag boolean inOrder = this.DEFAULT_INORDER; if (booleanNode.getTag(InOrderPropertyParser.IN_ORDER_PROPERTY) != null) { int tag = (Integer) booleanNode.getTag(InOrderPropertyParser.IN_ORDER_PROPERTY); inOrder = tag == 0 ? false : true; } // build the query and add clauses final BooleanSpanQuery bsq = new BooleanSpanQuery(slop, inOrder); for (final QueryNode child : booleanNode.getChildren()) { final Object obj = child.getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID); try { bsq.add(new NodeSpanQuery((NodeQuery) obj), this.getNodeModifierValue(child)); } catch (final BooleanQuery.TooManyClauses ex) { throw new QueryNodeException(new MessageImpl(QueryParserMessages.TOO_MANY_BOOLEAN_CLAUSES, BooleanQuery.getMaxClauseCount(), booleanNode.toQueryString(new EscapeQuerySyntaxImpl())), ex); } } // check if the node has a node range constraint if (booleanNode.getTag(RangePropertyParser.RANGE_PROPERTY) != null) { final int[] range = (int[]) booleanNode.getTag(RangePropertyParser.RANGE_PROPERTY); bsq.setNodeConstraint(range[0], range[1]); } return bsq; }
From source file:com.sindicetech.siren.qparser.tree.builders.BooleanQueryNodeBuilder.java
License:Open Source License
private final BooleanQuery buildBooleanQuery(BooleanQueryNode booleanNode) throws QueryNodeException { // build the query and add clauses final BooleanQuery bq = new BooleanQuery(true); for (final QueryNode child : booleanNode.getChildren()) { final Object obj = child.getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID); try {//from w ww . j a v a 2 s. co m Query q = (Query) obj; if (obj instanceof NodeQuery) { // wrap the query into a LuceneProxyNodeQuery q = new LuceneProxyNodeQuery((NodeQuery) q); } bq.add(q, this.getLuceneModifierValue(child)); } catch (final BooleanQuery.TooManyClauses ex) { throw new QueryNodeException(new MessageImpl(QueryParserMessages.TOO_MANY_BOOLEAN_CLAUSES, BooleanQuery.getMaxClauseCount(), booleanNode.toQueryString(new EscapeQuerySyntaxImpl())), ex); } } return bq; }
From source file:com.sindicetech.siren.qparser.tree.builders.TwigQueryNodeBuilder.java
License:Open Source License
@Override public TwigQuery build(final QueryNode queryNode) throws QueryNodeException { final TwigQueryNode twigNode = (TwigQueryNode) queryNode; final List<QueryNode> children = twigNode.getChildren(); final TwigQuery query = new TwigQuery(); // check if the node has a level constraint if (twigNode.getTag(LevelPropertyParser.LEVEL_PROPERTY) != null) { query.setLevelConstraint((Integer) twigNode.getTag(LevelPropertyParser.LEVEL_PROPERTY)); }//from w ww . j ava 2 s . c om // check if the node has a node range constraint if (twigNode.getTag(RangePropertyParser.RANGE_PROPERTY) != null) { final int[] range = (int[]) twigNode.getTag(RangePropertyParser.RANGE_PROPERTY); query.setNodeConstraint(range[0], range[1]); } // process root query this.processRoot(twigNode, query); // process child and descendant queries try { this.processChildren(children, query); } catch (final TooManyClauses ex) { throw new QueryNodeException(new MessageImpl(QueryParserMessages.TOO_MANY_BOOLEAN_CLAUSES, BooleanQuery.getMaxClauseCount(), twigNode.toQueryString(new EscapeQuerySyntaxImpl())), ex); } return query; }
From source file:org.sindice.siren.qparser.json.builders.BooleanQueryNodeBuilder.java
License:Apache License
public BooleanQuery build(final QueryNode queryNode) throws QueryNodeException { final BooleanQueryNode booleanNode = (BooleanQueryNode) queryNode; final BooleanQuery bQuery = new BooleanQuery(true); final List<QueryNode> children = booleanNode.getChildren(); for (final QueryNode child : children) { final Object obj = child.getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID); // wrap the query into a LuceneProxyNodeQuery final Query query = new LuceneProxyNodeQuery((NodeQuery) obj); try {/*from ww w . ja v a 2 s .c om*/ bQuery.add(query, getModifierValue(child)); } catch (final TooManyClauses ex) { throw new QueryNodeException(new MessageImpl(QueryParserMessages.TOO_MANY_BOOLEAN_CLAUSES, BooleanQuery.getMaxClauseCount(), queryNode.toQueryString(new EscapeQuerySyntaxImpl())), ex); } } return bQuery; }
From source file:org.sindice.siren.qparser.json.builders.TwigQueryNodeBuilder.java
License:Apache License
@Override public TwigQuery build(final QueryNode queryNode) throws QueryNodeException { final TwigQueryNode twigNode = (TwigQueryNode) queryNode; final List<QueryNode> children = twigNode.getChildren(); final TwigQuery query = new TwigQuery(); // check if the node has a level constraint if (twigNode.getTag(LevelPropertyParser.LEVEL_PROPERTY) != null) { query.setLevelConstraint((Integer) twigNode.getTag(LevelPropertyParser.LEVEL_PROPERTY)); }//from w w w. j a va2 s. co m // check if the node has a node range constraint if (twigNode.getTag(RangePropertyParser.RANGE_PROPERTY) != null) { final int[] range = (int[]) twigNode.getTag(RangePropertyParser.RANGE_PROPERTY); query.setNodeConstraint(range[0], range[1]); } // process root query if (twigNode.hasRoot()) { final String rootExpr = twigNode.getRoot().toString(); final String field = twigNode.getField().toString(); query.addRoot((NodeQuery) keywordParser.parse(rootExpr, field)); } // process child and descendant queries try { processChildren(children, query); } catch (final TooManyClauses ex) { throw new QueryNodeException(new MessageImpl(QueryParserMessages.TOO_MANY_BOOLEAN_CLAUSES, BooleanQuery.getMaxClauseCount(), twigNode.toQueryString(new EscapeQuerySyntaxImpl())), ex); } return query; }