2

I have the following filter in OpenLayers 2.13

var filter_c = new OpenLayers.Filter.Comparison({
        type: OpenLayers.Filter.Comparison.LIKE,
        property: 'p_name', 
        value: '%'+document.getElementById("nm").value+'%'
})

I also use GeoServer 2.1.3 and PostgreSQL 9.1 / PostGIS 2.0.

This filter is case sensitive and is applied to a vector layer. I can provide more code if you want.

I try to use ILIKE instead of LIKE but no luck. What am I missing? How can I make this filter case insensitive?

Here is the complete, original code

var filter_c = new OpenLayers.Filter.Comparison({
    type: OpenLayers.Filter.Comparison.LIKE,
    property: 'p_name', 
    value: '%'+document.getElementById("nm").value+'%'
});

//pass the filter to the layer
var prot =  new OpenLayers.Protocol.WFS({
    url:  "/geoserver/wfs",
    featureType: "pins",
    featureNS: "http://www.mysite.gr",
    defaultFilter: filter_cl
});

var _CallBack = function(resp) {
    pins.addFeatures(resp.features)
    var cb = pins.features.length;
    if (cb == 0){alert("Nothing Found");}
};

var response = prot.read({callback: _CallBack});


//refresh to render POIs
pins.refresh({force:true});

The pins layer takes data from a table in postgreSQL/PostGIS. This table has id, name, geometry, category, etc.Names are in UTF8 and are in Greek, such as Ακρόπολη, Παρθενώναςetc.

I simply set it like pins = new OpenLayers.Layer.Vector("LayerTitle", {renderers: ["Canvas", "SVG", "VML"]}) and the I have the aforementioned code to search it

1 Answer 1

1

Since you are using GeoServer, you can use strToLowerCase() function, while passing the search term in lower case as well.

The following code should work:

var filter_c = new OpenLayers.Filter.Comparison({
        type: OpenLayers.Filter.Comparison.LIKE,
        property: 'strToLowerCase(p_name)', 
        value: '%'+String(document.getElementById("nm").value).toLowerCase()+'%'
})
2
  • I try your code. I dont get the message "Nothing Found", but the map zooms in a random place and I still see no features on the layer. Maybe I should provide more of my code?
    – slevin
    Commented Feb 6, 2014 at 14:31
  • That would be useful. What's the source of your vector layer? Commented Feb 6, 2014 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.