Пример #1
0
  @Override
  protected QueryNode postProcessNode(QueryNode node) throws QueryNodeException {

    if (node instanceof AqpANTLRNode && ((AqpANTLRNode) node).getTokenLabel().equals("TMODIFIER")) {

      List<QueryNode> children = node.getChildren();

      if (children.size() == 1) {
        return children.get(0);
      }

      QueryNode masterChild = null;
      QueryNode currentChild;
      List<QueryNode> currentChildren;

      for (int i = 0; i < children.size(); i++) {
        currentChild = children.get(i);
        if (currentChild.isLeaf()) {
          continue;
        }
        if (masterChild == null) {
          masterChild = currentChild;
          node = masterChild;
          continue;
        }
        currentChildren = masterChild.getChildren();
        currentChildren.add(currentChild);
        masterChild.set(currentChildren);
        masterChild = children.get(i);
      }

      return node;
    }
    return node;
  }
  @Override
  protected QueryNode postProcessNode(QueryNode node) throws QueryNodeException {

    if (node instanceof BooleanQueryNode) {
      List<QueryNode> children = node.getChildren();

      if (children != null && children.size() == 1) {
        QueryNode child = children.get(0);

        if (child instanceof ModifierQueryNode) {
          ModifierQueryNode modNode = (ModifierQueryNode) child;

          if (modNode instanceof BooleanModifierNode
              || modNode.getModifier() == Modifier.MOD_NONE) {

            return child;
          }

        } else {
          return child;
        }
      }
    }

    return node;
  }
Пример #3
0
  @Override
  protected QueryNode preProcessNode(QueryNode node) throws QueryNodeException {
    final QueryConfigHandler conf = this.getQueryConfigHandler();

    // If the current node is a datatype query node, validate the datatype and assign it to its
    // child
    if (node instanceof DatatypeQueryNode) {
      final Map<String, Analyzer> dtAnalyzers =
          conf.get(KeywordConfigurationKeys.DATATYPES_ANALYZERS);
      final DatatypeQueryNode dt = (DatatypeQueryNode) node;
      String datatype = dt.getDatatype();

      // check if the datatype is correctly registered
      if (dtAnalyzers == null) {
        throw new IllegalArgumentException(
            "KeywordConfigurationKeys.DATAYPES_ANALYZERS "
                + "should be set on the ExtendedKeywordQueryConfigHandler");
      }
      if (!dtAnalyzers.containsKey(datatype)) {
        throw new IllegalArgumentException("Unknown datatype: [" + datatype + "]");
      }
      if (dtAnalyzers.get(datatype) == null) {
        throw new IllegalArgumentException(
            "Analyzer of datatype [" + datatype + "] cannot be null.");
      }

      // transfer the datatype to its child
      dt.getChild().setTag(DatatypeQueryNode.DATATYPE_TAGID, datatype);
    }
    // If the current node is a twig query node, assign the json:field datatype to the root, and
    // assign the default
    // or the tagged datatype to the child
    else if (node instanceof TwigQueryNode) {
      final TwigQueryNode twig = (TwigQueryNode) node;
      if (twig.getTag(DatatypeQueryNode.DATATYPE_TAGID) == null) {
        twig.getChild().setTag(DatatypeQueryNode.DATATYPE_TAGID, this.getDefaultDatatype(conf));
      } else {
        twig.getChild().setTag(DatatypeQueryNode.DATATYPE_TAGID, this.getDatatype(conf, node));
      }
      twig.getRoot().setTag(DatatypeQueryNode.DATATYPE_TAGID, JSONDatatype.JSON_FIELD);
    }
    // in any other cases, if the node is not a leaf node, transfer the datatype to its children
    else if (!node.isLeaf()) {
      for (final QueryNode child : node.getChildren()) {
        child.setTag(DatatypeQueryNode.DATATYPE_TAGID, this.getDatatype(conf, node));
      }
    }

    return node;
  }