0
votes

Say I have nodes stored in Jackrabbit JCR repository where they have multiple 'tag' properties attached.

I want to perform an or query, where any nodes that have tags with any of the tags in the query are returned. But I want them ordered by number of matches. So a node with all OR conditions matching will be on top, and one matching just one will be last.

I guess this is same as this suggestion here: https://stackoverflow.com/a/3289152/303106

But AFAIK, we don't have CASE constructs in SQL2. Neither do I know of anything equivalent in XPATH.

So how do I achieve the same result (other then post processing at application level, which I'd prefer to avoid due to performance issues).

1

1 Answers

0
votes

I hope this will help you to execute the query:

public FolderListReturn listFolder(String parentNode, String userid, String password) {
    System.out.println("getting folders and files from = "+parentNode+" of user : "+userid);


    SessionWrapper sessions = JcrRepositoryUtils.login(userid, password);
    Session jcrsession = sessions.getSession();

    Assert.notNull(name);
    FolderListReturn folderList1 = new FolderListReturn();
    ArrayOfFolders folders = new ArrayOfFolders();
    try {
                javax.jcr.query.QueryManager queryManager;

                queryManager = jcrsession.getWorkspace().getQueryManager();
                **String expression = "select * from [nt:folder] AS s WHERE ISCHILDNODE(s,'"+name+"')and CONTAINS(s.[edms:owner],'*"+userid+"*')  ORDER BY s.["+Config.EDMS_Sorting_Parameter+"] ASC";**

                javax.jcr.query.Query query = queryManager.createQuery(expression, javax.jcr.query.Query.JCR_SQL2);
                javax.jcr.query.QueryResult result = query.execute();
                        for (NodeIterator nit = result.getNodes(); nit.hasNext();) {
                Node node = nit.nextNode();
                Folder folder = new Folder();
                folder=setProperties(node,folder,userid,password,jcrsession,name);
                folders.getFolderList().add(folder);
                }
        folderList1.setFolderListResult(folders);
        folderList1.setSuccess(true);

    } catch (Exception e) {
        e.printStackTrace();
    } finally{
        //JcrRepositoryUtils.logout(sessionId);
    }
    return folderList1;
}