You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Simon Gaeremynck <ga...@gmail.com> on 2009/10/01 16:06:49 UTC

Doing a query based on partial nodenames.

Hi,

I am trying to do a query where I want to get a set of nodes by matching
their names to a string.
For example:
Repository:
/sites/mysite/_files/WeekI_Day1
/sites/mysite/_files/WeekI_Day2
/sites/mysite/_files/WeekII_Day1
/sites/mysite/_files/WeekII_Day2

I would like to be able to do a query so I can get the two WeekI nodes..

I have tried the following:
//sites/mysite/_files//*[fn:name()="WeekI*"] order by @jcr:created
descending
//sites/mysite/_files//*[jcr:name="WeekI*"] order by @jcr:created descending

These 2 only seem to work if I provide the full node name, which is not what
I want.

//sites/mysite/_files//*[jcr:contains(., "*WeekI*"] order by @jcr:created
descending
This one works fine for properties who contain WeekI but doesn't match the
node name.

Does anybody have any other suggestions?

Kind regards,

Simon

Re: Doing a query based on partial nodenames.

Posted by Simon Gaeremynck <ga...@gmail.com>.
Thank you for your input on this.
We have decided to write a listener that will set the properties once it it
is triggered.

Regards,
Simon


2009/10/5 Alexander Klimetschek <ak...@day.com>

> On Mon, Oct 5, 2009 at 12:14, Simon Gaeremynck <ga...@gmail.com>
> wrote:
> > I think jcr:contains(., 'week') only matches properties and not nodenames
> > which is how the spec defines it (I think?) so this is good.
>
> AFAIK Jackrabbit will index the node name as well.
>
> > Unfortunately, I can't set the filename as a property because these are
> > files that can be uploaded trough WebDAV.
>
> You can write an observation listener that does that (and maybe
> extracts other metadata as well).
>
> > So, there is no way to match a nodename trough an XPATH query?
>
> As I said, you can use fn:name() for exact matches on the node name,
> but not for wildcards.
>
> I think the new JQOM in JCR 2.0 supports that better, but I don't know
> how the query would like exactly.
>
> Regards,
> Alex
>
> --
> Alexander Klimetschek
> alexander.klimetschek@day.com
>

Re: Doing a query based on partial nodenames.

Posted by Alexander Klimetschek <ak...@day.com>.
On Mon, Oct 5, 2009 at 12:14, Simon Gaeremynck <ga...@gmail.com> wrote:
> I think jcr:contains(., 'week') only matches properties and not nodenames
> which is how the spec defines it (I think?) so this is good.

AFAIK Jackrabbit will index the node name as well.

> Unfortunately, I can't set the filename as a property because these are
> files that can be uploaded trough WebDAV.

You can write an observation listener that does that (and maybe
extracts other metadata as well).

> So, there is no way to match a nodename trough an XPATH query?

As I said, you can use fn:name() for exact matches on the node name,
but not for wildcards.

I think the new JQOM in JCR 2.0 supports that better, but I don't know
how the query would like exactly.

Regards,
Alex

-- 
Alexander Klimetschek
alexander.klimetschek@day.com

Re: Doing a query based on partial nodenames.

Posted by Simon Gaeremynck <ga...@gmail.com>.
I think jcr:contains(., 'week') only matches properties and not nodenames
which is how the spec defines it (I think?) so this is good.


> a) put the "week" stuff into properties and query via
> [jcr:like(@property, '%Week%')]
>

Unfortunately, I can't set the filename as a property because these are
files that can be uploaded trough WebDAV.
I can't really use

b) navigation: find the parent folder and then filter nodes by name
> using getNodes(String namePattern) [1]
>

This is also not a real solution since I don't know where the files are
located (exactly) in the repository and thus I don't even know the parent
folder.

So, there is no way to match a nodename trough an XPATH query?

Thank you for your help so far,

Simon


>
> Regards,
> Alex
>
> --
> Alexander Klimetschek
> alexander.klimetschek@day.com
>

Re: Doing a query based on partial nodenames.

Posted by Alexander Klimetschek <ak...@day.com>.
On Thu, Oct 1, 2009 at 16:06, Simon Gaeremynck <ga...@gmail.com> wrote:
> I am trying to do a query where I want to get a set of nodes by matching
> their names to a string.
> For example:
> Repository:
> /sites/mysite/_files/WeekI_Day1
> /sites/mysite/_files/WeekI_Day2
> /sites/mysite/_files/WeekII_Day1
> /sites/mysite/_files/WeekII_Day2
>
> I would like to be able to do a query so I can get the two WeekI nodes..
>
> I have tried the following:
> //sites/mysite/_files//*[fn:name()="WeekI*"] order by @jcr:created
> descending
> //sites/mysite/_files//*[jcr:name="WeekI*"] order by @jcr:created descending
>
> These 2 only seem to work if I provide the full node name, which is not what
> I want.

JCR 1.0 does not support a wildcard query for node names, ie.
fn:name() can only be used for exact matches.

> //sites/mysite/_files//*[jcr:contains(., "*WeekI*"] order by @jcr:created
> descending
> This one works fine for properties who contain WeekI but doesn't match the
> node name.

jcr:contains(., "Week") should include matches on the nodename, but it
will of course also include other full text matches, hence it is not
useful for distinctive search queries.

> Does anybody have any other suggestions?

a) put the "week" stuff into properties and query via
[jcr:like(@property, '%Week%')]
b) navigation: find the parent folder and then filter nodes by name
using getNodes(String namePattern) [1]

[1] http://www.day.com/maven/jsr170/javadocs/jcr-2.0/javax/jcr/Node.html#getNodes(java.lang.String)

Regards,
Alex

-- 
Alexander Klimetschek
alexander.klimetschek@day.com