Examples of TwigQueryNode


Examples of org.sindice.siren.qparser.json.nodes.TwigQueryNode

    this.keywordParser = keywordParser;
  }

  @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));
    }

    // 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;
  }
View Full Code Here

Examples of org.sindice.siren.qparser.json.nodes.TwigQueryNode

    return TWIG_PROPERTY;
  }

  @Override
  TwigQueryNode parse() throws ParseException {
    final TwigQueryNode twigNode = new TwigQueryNode();
    twigNode.setField(field);

    final JsonNode objectNode = node.path(this.getProperty());

    final RootPropertyParser rootParser = new RootPropertyParser(objectNode, field);
    rootParser.setOptional(true);
    if (rootParser.isPropertyDefined()) {
      twigNode.setRoot(rootParser.parse());
    }

    final LevelPropertyParser levelParser = new LevelPropertyParser(objectNode, field);
    levelParser.setOptional(true);
    if (levelParser.isPropertyDefined()) {
      twigNode.setTag(levelParser.getProperty(), levelParser.parse());
    }

    final RangePropertyParser rangeParser = new RangePropertyParser(objectNode, field);
    rangeParser.setOptional(true);
    if (rangeParser.isPropertyDefined()) {
      twigNode.setTag(rangeParser.getProperty(), rangeParser.parse());
    }

    final ChildPropertyParser childParser = new ChildPropertyParser(objectNode, field);
    childParser.setOptional(true);
    if (childParser.isPropertyDefined()) {
      final ArrayQueryNode arrayNode = childParser.parse();
      twigNode.add(arrayNode.getChildren());
    }

    final DescendantPropertyParser descendantParser = new DescendantPropertyParser(objectNode, field);
    descendantParser.setOptional(true);
    if (descendantParser.isPropertyDefined()) {
      final ArrayQueryNode arrayNode = descendantParser.parse();
      twigNode.add(arrayNode.getChildren());
    }

    return twigNode;
  }
View Full Code Here

Examples of org.sindice.siren.qparser.keyword.nodes.TwigQueryNode

  }

  @Test
  public void testTwigQueryNodeParent()
  throws Exception {
    final TwigQueryNode twig = new TwigQueryNode(new WildcardNodeQueryNode(),
                                                 new WildcardNodeQueryNode());
    final FieldQueryNode term = new FieldQueryNode("field", "term", 0, 4);
    assertTrue(term.getParent() == null);
    assertEquals(twig, twig.getRoot().getParent());
    assertEquals(twig, twig.getChild().getParent());
    twig.setRoot(term);
    twig.setChild(term);
    assertEquals(twig, twig.getRoot().getParent());
    assertEquals(twig, twig.getChild().getParent());
  }
View Full Code Here

Examples of org.sindice.siren.qparser.keyword.nodes.TwigQueryNode

  @Override
  protected QueryNode postProcessNode(final QueryNode node)
  throws QueryNodeException {
    if (node instanceof TwigQueryNode) {
      final TwigQueryNode twig = (TwigQueryNode) node;
      if (twig.getChild() instanceof WildcardNodeQueryNode &&
          twig.getRoot() instanceof WildcardNodeQueryNode) {
        throw new QueryNodeException(new MessageImpl("Twig with both root and child empty is not allowed."));
      }
    }
    return node;
  }
View Full Code Here

Examples of org.sindice.siren.qparser.keyword.nodes.TwigQueryNode

      this.queryNodeList = actualQueryNodeList;
      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;
    }
View Full Code Here

Examples of org.sindice.siren.qparser.keyword.nodes.TwigQueryNode

    // parent twig query
    else if (node instanceof TwigQueryNode) {
      nbTwigs++;
      if (nbTwigs == 1) {
        // Set the json:field datatype on the top level node only
        final TwigQueryNode twig = (TwigQueryNode) node;
        twig.getRoot().setTag(DatatypeQueryNode.DATATYPE_TAGID, JSONDatatype.JSON_FIELD);
      }
    }
    // A datatype is being used
    else if (datatype != null) {
      node.setTag(DatatypeQueryNode.DATATYPE_TAGID, datatype);
View Full Code Here

Examples of org.sindice.siren.qparser.keyword.nodes.TwigQueryNode

      // Set the ROOT level of the query
      /*
       * When adding nested TwigQueries, their root level is set to the current
       * Twig level + 1. See {@link TwigQuery#addChild}.
       */
      final TwigQueryNode twigNode = (TwigQueryNode) node;
      twigNode.setRootLevel(root);
    }
    return node;
  }
View Full Code Here

Examples of org.sindice.siren.qparser.keyword.nodes.TwigQueryNode

  public TwigQueryNodeBuilder() {}

  @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."));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.