Package org.apache.lucene.queryparser.flexible.core.nodes

Examples of org.apache.lucene.queryparser.flexible.core.nodes.QueryNode


  public TopLevelQueryNodeBuilder() {}

  @Override
  public Query build(final QueryNode queryNode) throws QueryNodeException {
    final TopLevelQueryNode topNode = (TopLevelQueryNode) queryNode;
    final QueryNode child = topNode.getChildren().get(0);
    final Object obj = child.getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);

    if (child instanceof BooleanQueryNode) {
      // no need to wrap the query object into a lucene proxy query
      return (Query) obj;
    }
View Full Code Here


      this.latestNodeVerified = false;
    }
    else if (node instanceof TwigQueryNode) {
      final ArrayList<QueryNode> actualQueryNodeList = this.queryNodeList;
      final TwigQueryNode twigNode = (TwigQueryNode) node;
      final QueryNode root = twigNode.getRoot();
      final QueryNode child = twigNode.getChild();
      if (!(root instanceof WildcardNodeQueryNode)) { // the root is not empty
        twigNode.setRoot(this.process(root));
      }
      if (!(child instanceof WildcardNodeQueryNode)) { // the child is not empty
        twigNode.setChild(this.process(child));
      }
      actualQueryNodeList.add(twigNode);
      this.queryNodeList = actualQueryNodeList;
      this.latestNodeVerified = false;
    }
    else if (node instanceof ArrayQueryNode) {
      final ArrayList<QueryNode> actualQueryNodeList = this.queryNodeList;
      final ArrayQueryNode arrayNode = (ArrayQueryNode) node;
      final List<QueryNode> children = arrayNode.getChildren();
      final List<QueryNode> newChildren = new ArrayList<QueryNode>();
      for (final QueryNode child : children) {
        // The unary modifier sets the occurrence of this value in the TwigQuery
        if (!(child instanceof ModifierQueryNode)) {
          newChildren.add(this.process(child));
        } else {
          newChildren.add(child);
        }
      }
      arrayNode.set(newChildren);
      actualQueryNodeList.add(arrayNode);
      this.queryNodeList = actualQueryNodeList;
      this.latestNodeVerified = false;
    }
    else if (node instanceof TopLevelQueryNode) {
      final ArrayList<QueryNode> actualQueryNodeList = this.queryNodeList;
      final TopLevelQueryNode topNode = (TopLevelQueryNode) node;
      final QueryNode child = topNode.getChildren().get(0);
      topNode.set(Arrays.asList(this.process(child)));
      actualQueryNodeList.add(topNode);
      this.queryNodeList = actualQueryNodeList;
      this.latestNodeVerified = false;
    }
    else if (node instanceof DatatypeQueryNode) {
      final ArrayList<QueryNode> actualQueryNodeList = this.queryNodeList;
      final DatatypeQueryNode dtNode = (DatatypeQueryNode) node;
      final QueryNode child = dtNode.getChild();
      dtNode.set(Arrays.asList(this.applyModifier(this.process(child), node.getParent())));
      actualQueryNodeList.add(dtNode);
      this.queryNodeList = actualQueryNodeList;
      this.latestNodeVerified = false;
    }
View Full Code Here

      if (occurParser.isPropertyDefined()) {
        mod = occurParser.parse();
      }

      // check if there is either a node or a twig property and parse it
      QueryNode queryNode = null;
      if (element.has(NodePropertyParser.NODE_PROPERTY)) {
        final NodePropertyParser nodeParser = new NodePropertyParser(element, field);
        queryNode = nodeParser.parse();
      }
      if (element.has(TwigPropertyParser.TWIG_PROPERTY)) {
View Full Code Here

      if (levelParser.isPropertyDefined()) {
        level = levelParser.parse();
      }

      // check if there is either a node or a twig property and parse it
      QueryNode queryNode = null;
      if (element.has(NodePropertyParser.NODE_PROPERTY)) {
        final NodePropertyParser nodeParser = new NodePropertyParser(element, field);
        queryNode = nodeParser.parse();
      }
      if (element.has(TwigPropertyParser.TWIG_PROPERTY)) {
View Full Code Here

    }
  }

  @Override
  public String toString() {
    final QueryNode att = this.getRoot();
    final QueryNode child = this.getChild();
    final String s = "<twig root=\"" + this.getRootLevel() + "\">\n" +
                 "<root>\n" + (att instanceof WildcardNodeQueryNode ? "" : att + "\n") + "</root>\n" +
                 "<child>\n" + (child instanceof WildcardNodeQueryNode ? "" : child + "\n") + "</child>\n" +
               "</twig>";
    return s;
View Full Code Here

  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 {
      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();
View Full Code Here

      if (occurParser.isPropertyDefined()) {
        mod = occurParser.parse();
      }

      // check if there is either a node or a twig property and parse it
      QueryNode queryNode = null;
      if (element.has(NodePropertyParser.NODE_PROPERTY)) {
        final NodePropertyParser nodeParser = new NodePropertyParser(element, field);
        queryNode = nodeParser.parse();
      }
      if (element.has(TwigPropertyParser.TWIG_PROPERTY)) {
View Full Code Here

    if (children.size() > 1) {
      for (final QueryNode child : children) {
        final Object obj = child.getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);
        if (obj != null) {
          if (obj instanceof NodeQuery) {
            final QueryNode mod;
            if (child instanceof DatatypeQueryNode) {
              mod = ((DatatypeQueryNode) child).getChild();
            } else {
              mod = child;
            }
View Full Code Here

*/
public class DatatypeQueryNodeBuilder implements KeywordQueryBuilder {

  public Query build(final QueryNode queryNode) throws QueryNodeException {
    final DatatypeQueryNode dtNode = (DatatypeQueryNode) queryNode;
    final QueryNode child = dtNode.getChild();

    assert queryNode.getChildren().size() == 1;

    final Query query = (Query) child.getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);
    this.setDatatype(child, dtNode.getDatatype());
    return query;
  }
View Full Code Here

  @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));
    }
    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),
View Full Code Here

TOP

Related Classes of org.apache.lucene.queryparser.flexible.core.nodes.QueryNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.