/** * This is a 'suitable replacement for extracting the expected field length of an attribute absed * on its "facets" (ie Filter describing type restrictions); * * <p>This code is copied from the ShapefileDataStore where it was written (probably by dzwiers). * Cholmes is providing documentation. * * @param type the AttributeType * @return an int indicating the max length of field in characters, or ANY_LENGTH */ public static int getFieldLength(PropertyDescriptor descriptor) { PropertyType type = descriptor.getType(); Integer length = null; while (type != null) { // TODO: We should really go through all the restrictions and find // the minimum of all the length restrictions; for now we assume an // override behavior. for (Filter f : type.getRestrictions()) { Integer filterLength = null; try { if (f == null) { continue; } if (f instanceof PropertyIsLessThan) { BinaryComparisonOperator cf = (BinaryComparisonOperator) f; if (cf.getExpression1() instanceof LengthFunction) { filterLength = cf.getExpression2().evaluate(null, Integer.class) - 1; } } else if (f instanceof PropertyIsLessThanOrEqualTo) { BinaryComparisonOperator cf = (BinaryComparisonOperator) f; if (cf.getExpression1() instanceof LengthFunction) { filterLength = cf.getExpression2().evaluate(null, Integer.class); } } else if (f instanceof PropertyIsGreaterThan) { BinaryComparisonOperator cf = (BinaryComparisonOperator) f; if (cf.getExpression2() instanceof LengthFunction) { filterLength = cf.getExpression1().evaluate(null, Integer.class) - 1; } } else if (f instanceof PropertyIsGreaterThanOrEqualTo) { BinaryComparisonOperator cf = (BinaryComparisonOperator) f; if (cf.getExpression2() instanceof LengthFunction) { filterLength = cf.getExpression1().evaluate(null, Integer.class); } } } catch (NullPointerException e) { // was not an integer eh? Continue, worst case we'll return ANY_LENGTH } if (filterLength != null) { if (length == null || filterLength < length) { length = filterLength; } } } type = type.getSuper(); } return length != null ? length : ANY_LENGTH; }
/* * Writes the SOLR query for binary comparison operator : EQUAL, NOT EQUAL * * @param filter binary comparison operator to encode */ private Object buildComparison(BinaryComparisonOperator filter, Object extraData) { StringWriter output = asStringWriter(extraData); if (filter instanceof PropertyIsNotEqualTo) { output.append("-"); } Expression[] expr = binaryFilterVisitorNormalizer(filter.getExpression1(), filter.getExpression2()); ExpressionToSolr visitor = new ExpressionToSolr(); expr[0].accept(visitor, output); output.append(":"); expr[1].accept(visitor, output); return output; }
private void visitBinaryComparisonOperator(BinaryComparisonOperator filter) { if (original == null) original = filter; // supports it as a group -- no need to check the type if (!fcs.supports(FilterCapabilities.SIMPLE_COMPARISONS_OPENGIS)) { postStack.push(filter); return; } int i = postStack.size(); Expression leftValue = filter.getExpression1(); Expression rightValue = filter.getExpression2(); if (leftValue == null || rightValue == null) { postStack.push(filter); return; } leftValue.accept(this, null); if (i < postStack.size()) { postStack.pop(); postStack.push(filter); return; } rightValue.accept(this, null); if (i < postStack.size()) { preStack.pop(); // left postStack.pop(); postStack.push(filter); return; } preStack.pop(); // left side preStack.pop(); // right side preStack.push(filter); }