Frage

My vcards have a CATEGORIES property that has a comma separated list of values. What I want is to get all the vcards that have the passed value somewhere in this comma separated list.

I'm trying to do a CardDAV REPORT request with a filter to accomplish this:

<C:filter test="allof"> 
<C:prop-filter name="CATEGORIES"  test="allof"> 
<C:text-match collation="i;unicode-casemap" 
match-type="contains" 
>searched_value</C:text-match> 
</C:prop-filter> 
</C:filter> 

The problem with this filter is that this will match the passed value in any place in the property, and this means that will also match the value inside another value, for example:

If I search for "friends" it will match in "work,friends,colleagues" but also in "work,football_friends,coleagues".

I can't find a way to use WebDAV filters to get only "full" values in my comma separated list.

War es hilfreich?

Lösung

I finally solved this using the different match-types:

<C:filter> 
<C:prop-filter name="CATEGORIES"  test="anyof"> 
<C:text-match collation="i;unicode-casemap" 
match-type="equals">value</C:text-match> 
<C:text-match collation="i;unicode-casemap" 
match-type="contains">,value,</C:text-match> 
<C:text-match collation="i;unicode-casemap" 
match-type="ends-with">,value</C:text-match> 
<C:text-match collation="i;unicode-casemap" 
match-type="starts-with">value,</C:text-match> 
</C:prop-filter> 
</C:filter> 

Detail:

Match if any of the contained text-matches is matching (Logic OR):

<C:prop-filter name="CATEGORIES"  test="anyof"> 

This text-match will match values exactly equal to the value (this is the value being the only value in the comma separated list):

<C:text-match collation="i;unicode-casemap" 
match-type="equals">value</C:text-match> 

This will match values containing the value between two commas (this is the value in some middle part of the comma separated list):

<C:text-match collation="i;unicode-casemap" 
match-type="contains">,value,</C:text-match> 

This will match values ending with a comma followed by the value (this is the value in the last position of the comma separated list):

<C:text-match collation="i;unicode-casemap" 
match-type="ends-with">,value</C:text-match> 

This will match values starting with the value followed by a comma (this is the value in the first position of the comma separated list):

<C:text-match collation="i;unicode-casemap" 
match-type="starts-with">value,</C:text-match> 

In this way this will only match full values in the comma separated list.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top