jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ard Schrijvers <a.schrijv...@onehippo.com>
Subject Re: Query contains question
Date Wed, 11 Aug 2010 13:07:06 GMT
On Wed, Aug 11, 2010 at 2:40 PM, Simon Gaeremynck <gaeremyncks@gmail.com> wrote:
> Hi all,
> I'm struggling a bit with the jcr:contains() function for xpath.
> I have the following nodes
> + foo
>   -  name = 'Anne-Sophie'
> + bar
>   -  name = 'Anne-Suzy'
> Now, I want to do a query that gets both when I type in 'Anne-S'
> I can't use jcr:like because I need to match any property, and not the @name one specifically.
> I thought the following would do, but it doesn't:
> //*[jcr:contains(., 'Anne-S*)
> According to the spec you have to escape the - character if you do not want it to be
interpreted as a negator. (
> //*[jcr:contains(., 'Anne\\-S*)
> That doesn't match them either.
> The following two do match them (a space between the - and the S)
> //*[jcr:contains(., 'Anne- S*)
> //*[jcr:contains(., 'Anne\\- S*)

For this thing you can use jcr:like or use
//*[jcr:contains(.,'"Anne-S*"')] although I am not completely sure if
the latter always works. The problem you have is that you cannot
search for terms starting with 'Anne-S' as there are no Lucene terms
starting with it! This is because the standard lucene analyzer
tokenizes on a dash, hence, there is for example the term 'Anne' and
'Sophie'. Check 'Ann*', that one will work! This might be
confusing..but it gets even much more complex when iso latin1 filters
and stemming is applied.

Anyway, back to the '"Anne-S*"'. When putting " " around it, it will
be treated as a Lucene PhraseQuery [1] which does the job for you (I
think/hope :) )

Regards Ard

[1] http://lucene.apache.org/java/2_4_0/api/org/apache/lucene/search/PhraseQuery.html

> But these would also match a name 'Anne- Soekie' (note the space between the - and the
> Am I doing something wrong? Is this a bug, or is it intended this way?
> Kind regards,
> Simon

View raw message