Search in sources :

Example 1 with CQLBooleanNode

use of org.z3950.zing.cql.CQLBooleanNode in project okapi by folio-org.

the class CQLUtil method reducer.

public static CQLNode reducer(CQLNode vn1, CQLTermNode tn, Comparator<CQLTermNode> cmp) {
    if (vn1 instanceof CQLBooleanNode) {
        return reduceBoolean((CQLBooleanNode) vn1, tn, cmp);
    } else if (vn1 instanceof CQLTermNode) {
        CQLTermNode n1 = (CQLTermNode) vn1;
        if (cmp != null && cmp.compare(n1, tn) == 0) {
            return null;
        }
        return new CQLTermNode(n1.getIndex(), n1.getRelation(), n1.getTerm());
    } else if (vn1 instanceof CQLSortNode) {
        CQLSortNode n1 = (CQLSortNode) vn1;
        CQLNode n2 = reducer(n1.getSubtree(), tn, cmp);
        if (n2 == null) {
            return null;
        } else {
            CQLSortNode sn = new CQLSortNode(n2);
            List<ModifierSet> mods = n1.getSortIndexes();
            for (ModifierSet mSet : mods) {
                sn.addSortIndex(mSet);
            }
            return sn;
        }
    } else if (vn1 instanceof CQLPrefixNode) {
        CQLPrefixNode n1 = (CQLPrefixNode) vn1;
        CQLNode n2 = reducer(n1.getSubtree(), tn, cmp);
        if (n2 == null) {
            return null;
        } else {
            CQLPrefix prefix = n1.getPrefix();
            return new CQLPrefixNode(prefix.getName(), prefix.getIdentifier(), n2);
        }
    } else {
        throw new IllegalArgumentException("unknown type for CQLNode: " + vn1.toString());
    }
}
Also used : CQLSortNode(org.z3950.zing.cql.CQLSortNode) CQLTermNode(org.z3950.zing.cql.CQLTermNode) CQLPrefixNode(org.z3950.zing.cql.CQLPrefixNode) CQLBooleanNode(org.z3950.zing.cql.CQLBooleanNode) CQLPrefix(org.z3950.zing.cql.CQLPrefix) CQLNode(org.z3950.zing.cql.CQLNode) ModifierSet(org.z3950.zing.cql.ModifierSet)

Example 2 with CQLBooleanNode

use of org.z3950.zing.cql.CQLBooleanNode in project raml-module-builder by folio-org.

the class CQL2PgJSON method pg.

private String pg(CQLBooleanNode node) throws QueryValidationException {
    String operator = sqlOperator(node);
    String isNotTrue = "";
    // typed in anything: title=* OR contributors*= OR identifier=*
    if ("OR".equals(operator) && node.getRightOperand().getClass() == CQLTermNode.class) {
        CQLTermNode r = (CQLTermNode) (node.getRightOperand());
        if ("*".equals(r.getTerm()) && "=".equals(r.getRelation().getBase())) {
            logger.log(Level.FINE, "pgFT(): Simplifying =* OR =* ");
            return pg(node.getLeftOperand());
        }
    }
    if ("AND NOT".equals(operator)) {
        operator = "AND (";
        isNotTrue = ") IS NOT TRUE";
    // NOT TRUE is (FALSE or NULL) to catch the NULL case when the field does not exist.
    // This completely inverts the right operand.
    }
    return "(" + pg(node.getLeftOperand()) + ") " + operator + " (" + pg(node.getRightOperand()) + isNotTrue + ")";
}
Also used : CQLTermNode(org.z3950.zing.cql.CQLTermNode)

Example 3 with CQLBooleanNode

use of org.z3950.zing.cql.CQLBooleanNode in project okapi by folio-org.

the class CQLUtil method reduceBoolean.

private static CQLNode reduceBoolean(CQLBooleanNode n1, CQLTermNode tn, Comparator<CQLTermNode> cmp) {
    CQLNode n2 = null;
    CQLNode left = reducer(n1.getLeftOperand(), tn, cmp);
    CQLNode right = reducer(n1.getRightOperand(), tn, cmp);
    ModifierSet mSet = new ModifierSet(n1.getOperator().toString().toLowerCase());
    List<Modifier> mods = n1.getModifiers();
    for (Modifier m : mods) {
        mSet.addModifier(m.getType(), m.getComparison(), m.getValue());
    }
    if (left == null) {
        n2 = right;
    } else if (right == null) {
        n2 = left;
    }
    switch(n1.getOperator()) {
        case AND:
            if (left != null && right != null) {
                n2 = new CQLAndNode(left, right, mSet);
            }
            break;
        case OR:
            if (left != null && right != null) {
                n2 = new CQLOrNode(left, right, mSet);
            }
            break;
        case NOT:
            if (left != null && right != null) {
                n2 = new CQLNotNode(left, right, mSet);
            }
            break;
        case PROX:
            if (left != null && right != null) {
                n2 = new CQLProxNode(left, right, mSet);
            }
            break;
    }
    return n2;
}
Also used : CQLAndNode(org.z3950.zing.cql.CQLAndNode) CQLNotNode(org.z3950.zing.cql.CQLNotNode) CQLProxNode(org.z3950.zing.cql.CQLProxNode) Modifier(org.z3950.zing.cql.Modifier) CQLNode(org.z3950.zing.cql.CQLNode) ModifierSet(org.z3950.zing.cql.ModifierSet) CQLOrNode(org.z3950.zing.cql.CQLOrNode)

Aggregations

CQLNode (org.z3950.zing.cql.CQLNode)2 CQLTermNode (org.z3950.zing.cql.CQLTermNode)2 ModifierSet (org.z3950.zing.cql.ModifierSet)2 CQLAndNode (org.z3950.zing.cql.CQLAndNode)1 CQLBooleanNode (org.z3950.zing.cql.CQLBooleanNode)1 CQLNotNode (org.z3950.zing.cql.CQLNotNode)1 CQLOrNode (org.z3950.zing.cql.CQLOrNode)1 CQLPrefix (org.z3950.zing.cql.CQLPrefix)1 CQLPrefixNode (org.z3950.zing.cql.CQLPrefixNode)1 CQLProxNode (org.z3950.zing.cql.CQLProxNode)1 CQLSortNode (org.z3950.zing.cql.CQLSortNode)1 Modifier (org.z3950.zing.cql.Modifier)1