List of usage examples for org.apache.lucene.queryparser.flexible.core.nodes QueryNode toQueryString
public CharSequence toQueryString(EscapeQuerySyntax escapeSyntaxParser);
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 a 2 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.nodes.NodeBooleanQueryNode.java
License:Open Source License
@Override public CharSequence toQueryString(final EscapeQuerySyntax escapeSyntaxParser) { if (this.getChildren() == null || this.getChildren().size() == 0) return ""; final StringBuilder sb = new StringBuilder(); String filler = ""; for (final QueryNode child : this.getChildren()) { sb.append(filler).append(child.toQueryString(escapeSyntaxParser)); filler = " "; }// w w w .j a v a 2s .c o m // in case is root or the parent is a group node avoid parenthesis if ((this.getParent() != null && this.getParent() instanceof GroupQueryNode) || this.isRoot()) return sb.toString(); else return "( " + sb.toString() + " )"; }
From source file:com.sindicetech.siren.qparser.keyword.nodes.TwigQueryNode.java
License:Open Source License
@Override public CharSequence toQueryString(final EscapeQuerySyntax escapeSyntaxParser) { if (this.getChildren() == null || this.getChildren().size() == 0) return ""; final StringBuilder sb = new StringBuilder(); final QueryNode root = this.getRoot(); final QueryNode child = this.getChild(); if (root instanceof WildcardNodeQueryNode) { sb.append("* : "); } else {/*from w ww.j av a2 s . c o m*/ sb.append(root.toQueryString(escapeSyntaxParser)).append(" : "); } if (child instanceof WildcardNodeQueryNode) { sb.append("*"); } else { sb.append(child.toQueryString(escapeSyntaxParser)); } // in case is root or the parent is a group node avoid parenthesis if ((this.getParent() != null && this.getParent() instanceof GroupQueryNode) || this.isRoot()) { return sb.toString(); } else { return "( " + sb.toString() + " )"; } }
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()))); }/* w w w . ja v a 2 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()))); }/* ww w.ja v a 2 s .c o 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 av a 2s.c om 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 www. jav 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: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 w w w . j a va 2 s . c o m*/ 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.keyword.builders.MatchNoDocsQueryNodeBuilder.java
License:Apache License
public NodeBooleanQuery build(final QueryNode queryNode) throws QueryNodeException { // validates node if (!(queryNode instanceof MatchNoDocsQueryNode)) { throw new QueryNodeException(new MessageImpl(QueryParserMessages.LUCENE_QUERY_CONVERSION_ERROR, queryNode.toQueryString(new EscapeQuerySyntaxImpl()), queryNode.getClass().getName())); }// w ww .j a va 2 s.c o m return new NodeBooleanQuery(); }
From source file:org.sindice.siren.qparser.keyword.processors.AllowTwigProcessor.java
License:Apache 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 ww w . j a v a 2s.c o m*/ } else { throw new IllegalArgumentException( "KeywordConfigurationKeys.ALLOW_TWIG should be set on the KeywordQueryConfigHandler"); } } return node; }