0

Is it possible, and if so how, to use multiple logical filters in a wfs request?

For example I have a attribute, type_id that should be 1, 2 or 3.

var wfsTypeFilters = [
    new OpenLayers.Filter.Comparison({
        type: OpenLayers.Filter.Comparison.EQUAL_TO,
        property: "type_id",
        value: 1
    }),
    new OpenLayers.Filter.Comparison({
        type: OpenLayers.Filter.Comparison.EQUAL_TO,
        property: "type_id",
        value: 2
    }),
    new OpenLayers.Filter.Comparison({
        type: OpenLayers.Filter.Comparison.EQUAL_TO,
        property: "type_id",
        value: 3
    })
];

And then I have an attribute called name that should not be empty

var wfsNameIsNotNullFilter = [
    new OpenLayers.Filter.Comparison({
        type: OpenLayers.Filter.Comparison.NOT_EQUAL_TO,
        property: "type_id",
        value :""
    }
)];  

After thtis I tried to create two different logical filters. And when combining them I get error: Uncaught Filter writing not supported for rule type: undefined

var parent_type_filter = new OpenLayers.Filter.Logical({
    type: OpenLayers.Filter.Logical.OR,
    filters: wfsTypeFilters
});


var parent_filter = new OpenLayers.Filter.Logical({
    type: OpenLayers.Filter.Logical.AND,
    filters: [parent_type_filter, wfsNameIsNotNullFilter]
});

If I would have written a sql query this would have been easy by using parentheses

WHERE (type_id = 1 OR type_id = 2 OR type_id = 3 ) AND (name != "")

Br Mike

0

First of all I would check if the attribut "name" is really an empty string or if it's a null value what you are looking for. In this case you would have to use

  new OpenLayers.Filter.Comparison({
        type: OpenLayers.Filter.Comparison.IS_NULL,
        property: "type_id"
    });

You can have a look at a combination of the filtertypes you are using in your example here:

http://jsfiddle.net/expedio/eef7n2sy/

Update1: Here one example for server-side filtering:

http://jsfiddle.net/expedio/4L9om0rc/

PS: i also encountered problems while using OL 2.11 . after switching to 2.13.1 the problem disappeared.

4
  • Hi and thanks for the response. Perhaps I wasn't to clear in my question. What I want is to filter the wfs request on the server. The example you posted uses Strategy.Filter and isn't that only filtering on the client? At least that's the only thing I manage to filter.
    – Mike001
    Sep 25 '15 at 14:11
  • 1
    right. I just added the jsfiddle with server side filtering while requesting the wfs ;) ( jsfiddle.net/expedio/4L9om0rc )
    – Thomas B
    Sep 25 '15 at 21:07
  • I'm not quite sure exactly what I did wrong in the beginning. But thanks to the code in your last fiddle example I now managed to get my code to work. Big thanks to you Thomas!
    – Mike001
    Sep 26 '15 at 12:37
  • your welcome ;) please don't forget to mark the question as answered so it does not appear in the unanswered section anymore
    – Thomas B
    Sep 28 '15 at 7:56

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .