You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Fabián Mandelbaum <fm...@gmail.com> on 2010/10/22 15:53:47 UTC

Searching for file names (nt:file node names) with JR 1.6.x

Hello there,

I'm using JackRabbit 1.6.2 on my project and I was wondering which
would be the query to execute (either XPath or SQL) to be able to
search for a given string in a file name (search in file names). I've
tried all examples I've found on the web and none is working. I've
tried things like this:

SELECT * FROM nt:file WHERE jcr:path LIKE '/workspaces/W1/content/Samba[%]/%'

SELECT * FROM nt:file WHERE jcr:path LIKE '/workspaces/W1/content/Samba%'

There are nt:file nodes named Samba{1,2,3}.xml inside the
/workspaces/W1/content nt:folder node, but even so the query returns
empty.

If I specify the full file name, like this:

SELECT * FROM nt:file WHERE jcr:path LIKE '/workspaces/W1/content/Samba1.xml%'

then the query does succeed returning the expected node, but of course
this is not what I need.

Before I have to change my repo storage structure adding a property
with the file's name (which would be redundant since the node's name
is the file name already), and I have to write a tool for our users to
migrate their production repos adding the property in question, do you
have any ideas on how I may solve this problem?

-- 
Fabián Mandelbaum
IS Engineer

Re: Searching for file names (nt:file node names) with JR 1.6.x

Posted by Fabián Mandelbaum <fm...@gmail.com>.
Thanks Neil and Alex for your answers.

So, I've added the cco_fname property to my repository and wrote the
migration tool (so old repos will be filename-searchable too). Search
looks to be working now, as you can see below:

fabman@monster:~$ curl -i -uadmin@calenco.com:admin
http://localhost:9000/workspaces/Test/content/searchresult?q=calenco\&lang=en\&classif=C1
HTTP/1.1 200 OK
Content-Length: 461
Content-Type: text/plain; charset=UTF-8
Date: Fri, 29 Oct 2010 14:55:12 GMT
Accept-Ranges: bytes
Server: Restlet-Framework/2.0.1

Full Text Query:/jcr:root/workspaces/Test/content/en/*[@jcr:primaryType='nt:file'
and jcr:contains(jcr:content, 'calenco')]
Search Result: 1 node(s).
Filename Query:/jcr:root/workspaces/Test/properties/en/*[@jcr:primaryType='nt:unstructured'
and jcr:like(@cco_fname, '%calenco%')]
Search Result: 0 node(s).
Classifs Query:/jcr:root/workspaces/Test/associations/*[@kind='isClassifiedOnto'
and @to='/workspaces/Test/classifications/C1']
Search Result: 0 node(s).

fabman@monster:~$ curl -i -uadmin@calenco.com:admin
http://localhost:9000/workspaces/Test/content/searchresult?q=Calenco\&lang=en\&classif=C1
HTTP/1.1 200 OK
Content-Length: 461
Content-Type: text/plain; charset=UTF-8
Date: Fri, 29 Oct 2010 14:55:19 GMT
Accept-Ranges: bytes
Server: Restlet-Framework/2.0.1

Full Text Query:/jcr:root/workspaces/Test/content/en/*[@jcr:primaryType='nt:file'
and jcr:contains(jcr:content, 'Calenco')]
Search Result: 1 node(s).
Filename Query:/jcr:root/workspaces/Test/properties/en/*[@jcr:primaryType='nt:unstructured'
and jcr:like(@cco_fname, '%Calenco%')]
Search Result: 1 node(s).
Classifs Query:/jcr:root/workspaces/Test/associations/*[@kind='isClassifiedOnto'
and @to='/workspaces/Test/classifications/C1']
Search Result: 0 node(s).
fabman@monster:~$

However, it seems like jcr:like is case sensitive (because the 1st
filename query doesn't match). Is there any way I can make it case
un-sensitive? Some query parameter? Some index configuration?

Thanks in advance for your answers.

On Fri, Oct 22, 2010 at 2:41 PM, Alexander Klimetschek <ak...@day.com> wrote:
> On Fri, Oct 22, 2010 at 19:35, Neil Corbet
> <nc...@towerhillservices.com> wrote:
>> Fabián Mandelbaum <fmandelbaum <at> gmail.com> writes:
>>> I'm using JackRabbit 1.6.2 on my project and I was wondering which
>>> would be the query to execute (either XPath or SQL) to be able to
>>> search for a given string in a file name (search in file names).
>>
>> I think you may want to use the fn:name() function in the query. Something like:
>> " fn:name() LIKE 'Samba' " you could include the "jcr:path LIKE
>> '/workspaces/W1/content/%'" to help guide it down the right path and use
>> fn:name() to narrow it down to a set of names.
>
> No, fn:name() in jcr-sql (the one from jcr 1.0, in Jackrabbit 1.x)
> does not support wildcards.
>
> Wild card search on node names is only possible since Jackrabbit 2.0
> using JCR-SQL2. See
> http://jackrabbit.markmail.org/thread/xvoo5afksxtyplhw
>
> Regards,
> Alex
>
> --
> Alexander Klimetschek
> alexander.klimetschek@day.com
>



-- 
Fabián Mandelbaum
IS Engineer

Re: Searching for file names (nt:file node names) with JR 1.6.x

Posted by Alexander Klimetschek <ak...@day.com>.
On Fri, Oct 22, 2010 at 19:35, Neil Corbet
<nc...@towerhillservices.com> wrote:
> Fabián Mandelbaum <fmandelbaum <at> gmail.com> writes:
>> I'm using JackRabbit 1.6.2 on my project and I was wondering which
>> would be the query to execute (either XPath or SQL) to be able to
>> search for a given string in a file name (search in file names).
>
> I think you may want to use the fn:name() function in the query. Something like:
> " fn:name() LIKE 'Samba' " you could include the "jcr:path LIKE
> '/workspaces/W1/content/%'" to help guide it down the right path and use
> fn:name() to narrow it down to a set of names.

No, fn:name() in jcr-sql (the one from jcr 1.0, in Jackrabbit 1.x)
does not support wildcards.

Wild card search on node names is only possible since Jackrabbit 2.0
using JCR-SQL2. See
http://jackrabbit.markmail.org/thread/xvoo5afksxtyplhw

Regards,
Alex

-- 
Alexander Klimetschek
alexander.klimetschek@day.com

Re: Searching for file names (nt:file node names) with JR 1.6.x

Posted by Neil Corbet <nc...@towerhillservices.com>.
Fabián Mandelbaum <fmandelbaum <at> gmail.com> writes:

> 
> Hello there,
> 
> I'm using JackRabbit 1.6.2 on my project and I was wondering which
> would be the query to execute (either XPath or SQL) to be able to
> search for a given string in a file name (search in file names). I've
> tried all examples I've found on the web and none is working. I've
> tried things like this:
> 
> SELECT * FROM nt:file WHERE jcr:path LIKE '/workspaces/W1/content/Samba[%]/%'
> 
> SELECT * FROM nt:file WHERE jcr:path LIKE '/workspaces/W1/content/Samba%'
>.....

I think you may want to use the fn:name() function in the query. Something like:
" fn:name() LIKE 'Samba' " you could include the "jcr:path LIKE 
'/workspaces/W1/content/%'" to help guide it down the right path and use 
fn:name() to narrow it down to a set of names.