0

We are using apache jackrabbit to store content (html,image,pdfs) as follows:

    /folder1 (nt:unstructured)
        /content1(nt:unstructured)
           /file(nt:folder)
               /test.html(nt:file)
               /test.html-contents (nt:resource)

In the UI, we want to display all content that can be sorted by name, file size, file type etc. To achieve that, I tried XPath to retrieve content nodes.

  1. Is it possible to sort on node name? I tried some thing like

    "/element(*,nt:base) order by @name ascending"

but that does not work. It works on other properties of content, but not the name. 2. Is it possible to sort on file size? Since files are child nodes of content, is there some way I can query for content based on its file size? (someway to query by jcr:data).length?)

As a workaround, I am retrieving all content via node iterator and doing in-memory sorting/pagination. I was hoping there is a better way to do this.

sfbay
  • 23
  • 1
  • 8

1 Answers1

0

Sorting by name is not available with JCR Xpath queries as far as I know. However with SQL it is supported. This might depends on the version of Jackrabbit though.

With SQL the query above is:

select * from nt:base order by jcr:name ASC

Sorting on the length of a resource is not supported as well. You might want to consider setting an extra property on the node for sorting purposes. You can do this when handling the upload to Jackrabbit.

Depending on the amount of nodes sorting in memory might become a big burdon.

Jeroen
  • 3,076
  • 1
  • 17
  • 16
  • I tried using the SQL above, but it does not return the nodes in sorted order. Changing order by to ASC DESC has no effect. – sfbay May 08 '12 at 21:46
  • Which JCR implementation and version are you using? Are you using JBoss Modeshape or Apache Jackrabbit? – Jeroen May 09 '12 at 15:36
  • I am using Apache Jackrabbit. Thanks. – sfbay May 10 '12 at 00:18
  • And which version are you using? I'm running with Jackrabbit 2.2.10 and it is working. – Jeroen May 10 '12 at 08:27
  • I'm using Jackrabbit 2.4. Let me try out my example with 2.2.10. Thanks – sfbay May 14 '12 at 16:24
  • This works with a simple folder structure where all nodes are at same level. But this does not work in my case. For eg. if i have folder1 and aFolder2 which are unstructured nodes at same level having child folders and file nodes. But the sort does not return them in sorted order. The result I am expecting is (aFolder2, folder1) but the actual result is (folder1,aFolder2). – sfbay May 15 '12 at 17:17