List of usage examples for org.apache.lucene.queryparser.flexible.core.messages QueryParserMessages EMPTY_MESSAGE
String EMPTY_MESSAGE
To view the source code for org.apache.lucene.queryparser.flexible.core.messages QueryParserMessages EMPTY_MESSAGE.
Click Source Link
From source file:com.sindicetech.siren.qparser.keyword.builders.AnyQueryNodeBuilder.java
License:Open Source License
public BooleanQuery build(QueryNode queryNode) throws QueryNodeException { AnyQueryNode andNode = (AnyQueryNode) queryNode; BooleanQuery bQuery = new BooleanQuery(); 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() *//* w ww.j ava2 s.c om*/ QueryParserMessages.EMPTY_MESSAGE), ex); } } } } bQuery.setMinimumNumberShouldMatch(andNode.getMinimumMatchingElements()); return bQuery; }
From source file:com.sindicetech.siren.qparser.keyword.builders.TwigQueryNodeBuilder.java
License:Open Source License
@Override public Query build(final QueryNode queryNode) throws QueryNodeException { final TwigQueryNode tqn = (TwigQueryNode) queryNode; final QueryNode root = tqn.getRoot(); final QueryNode child = tqn.getChild(); final TwigQuery twigQuery; final int rootLevel = tqn.getRootLevel(); if (root == null && child == null) { throw new QueryNodeException(new MessageImpl(QueryParserMessages.EMPTY_MESSAGE)); }/* w w w . j av a2s . co m*/ if (tqn.getChildren().size() != 2) { throw new IllegalArgumentException( "A TwigQueryNode cannot have more " + "than 2 children:\n" + tqn.getChildren().toString()); } if (child instanceof WildcardNodeQueryNode && root instanceof WildcardNodeQueryNode) { throw new QueryNodeException( new MessageImpl("Twig with both root and " + "child empty is not allowed.")); } // Build the root operand if (root instanceof WildcardNodeQueryNode) { // Empty root query twigQuery = new TwigQuery(rootLevel); } else { final Object attQuery = root.getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID); if (attQuery != null) { twigQuery = new TwigQuery(rootLevel); twigQuery.addRoot((NodeQuery) attQuery); } else { throw new QueryNodeException(new MessageImpl(QueryParserMessages.INVALID_SYNTAX, "Unable to get the root of the Twig query")); } } if (!(child instanceof WildcardNodeQueryNode)) { // Build the child operand final Object v = child.getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID); if (v instanceof ArrayQuery) { // array of children nodes final ArrayQueryNode aqn = (ArrayQueryNode) child; final List<Query> children = ((ArrayQuery) v).getElements(); for (int i = 0; i < children.size(); i++) { twigQuery.addChild((NodeQuery) children.get(i), NodeQueryBuilderUtil .getModifierValue(aqn.getChildren().get(i), NodeBooleanClause.Occur.MUST)); } } else if (v instanceof Query) { final NodeQuery valQuery = (NodeQuery) v; twigQuery.addChild(valQuery, Occur.MUST); } else { throw new QueryNodeException(new MessageImpl(QueryParserMessages.INVALID_SYNTAX, "Unexpected class of a Twig Query clause: " + v == null ? "null" : v.getClass().getName())); } } return twigQuery; }