Hi, I encountered a problem filtering an attribute using the Like Filter.

I use the method below to get the number of features from a map layer, where the text attribute given by an index contains a given string.
Index of the layer, of the attribute and the string are passed as arguments. Everything works fine, but the pattern is case sensitive.

If the attribute of a feature is "My House", I would like the method to return it whenever I type "my house" or "HOUSE", etc..

I know that I need to modify the setPattern() method somehow with the (?i) marker, but I don't know how. The whole setPattern() method is a bit confusing for  me.
If somebody could help me with this I would be very grateful.

/********************************************/

public static int relate(int layerIndex, int attribute, String text) throws Exception {

       FilterFactory ff = FilterFactory.createFilterFactory();

        MapLayer a  = MyMap.getLayer(layerIndex);
        
        FeatureSource features = a.getFeatureSource();

        LikeFilter filter = null;
       
        filter = ff.createLikeFilter();

        FeatureType featureType = features.getFeatures().getSchema();
            
        String attributeName = featureType.getAttributeType(attribute).getName();
            
        filter.setPattern(".*"+text+".*", ".*", ".", "\\n");       // works fine but is case sensitive !!!

        filter.setValue(ff.createAttributeExpression(featureType, attributeName));

        col = features.getFeatures(filter).collection();
        
        return col.size();
}

/********************************************/

Thanks in advance,
Wojtek

Reply via email to