You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Brian Thompson <el...@gmail.com> on 2007/07/03 23:55:14 UTC
Pattern matching in queries
Hello, list:
I'm trying to implement a filtered search on a repository that has a
structure looking like
/folder/type alpha 1/node1
/folder/type alpha 1/node2
/folder/type beta 2/node3
/folder/type beta 2/node4
I tried the following, but it didn't work.
SELECT * FROM my:nodeType WHERE jcr:path LIKE '%type alpha%'
SELECT * FROM my:nodeType WHERE jcr:path LIKE '/%type alpha%/%'
SELECT * FROM my:nodeType WHERE jcr:path LIKE '%/type alpha%/%'
Due to the existing data in the repository, I can't easily come up with the
entire name at the "type alpha 1" level, so I'm trying to come up with a way
to match part of the name of the element at that level.
I've also tried some XPath queries like
//*/element(beta, my:nodeType)[1]
but I don't have any experience with XPath, so I'm not really sure how to
express what I'm looking for.
Is it even possible to do pattern matching on JCR path elements?
Thanks,
Brian
Re: Pattern matching in queries
Posted by Brian Thompson <el...@gmail.com>.
Thanks for the info, Marcel.
I managed to find a way to limit my search to my satisfaction by using XPath
syntax. The 'type' nodes from my example have a 'name' attribute which I do
have easily available, so I tried these two queries (both worked):
//element(*, my:typeNode)[jcr:contains(., 'type
name')]/element(*,my:dataNode)[jcr:contains(., 'data node search phrase')]
//element(*, my:typeNode)[@type:name = 'type
name']/element(*,my:dataNode)[jcr:contains(., 'data node search phrase')]
This works pretty well for my purposes.
-Brian
On 7/4/07, Marcel Reutegger <ma...@gmx.net> wrote:
>
> Brian Thompson wrote:
> > Is it even possible to do pattern matching on JCR path elements?
>
> no, it is not. but with the next minor release of jackrabbit (1.4) you can
> use
> the fn:name() function together with the equals operator.
>
> so, you can have:
>
> //element(*, nt:file)[fn:name() eq 'foo' or fn:name() eq 'bar']
>
> returns file nodes named foo or bar.
>
> regards
> marcel
>
Re: Pattern matching in queries
Posted by Marcel Reutegger <ma...@gmx.net>.
Brian Thompson wrote:
> Is it even possible to do pattern matching on JCR path elements?
no, it is not. but with the next minor release of jackrabbit (1.4) you can use
the fn:name() function together with the equals operator.
so, you can have:
//element(*, nt:file)[fn:name() eq 'foo' or fn:name() eq 'bar']
returns file nodes named foo or bar.
regards
marcel