Jackrabbit Running Queries against UUID

假如想象 提交于 2019-12-02 04:17:43

问题


I am using Jackrabbit and I am trying to query for an existing node which has a UUID. My code is shown below. The problem is that UUID for referenceNode is of the form "'90be246a-a17c-445e-a5ad-81b064de0bee'" and it seems that the XPATH engine used in Jackrabbit (Lucene) has problems dealing with hyphens.

If I run query2, everything is fine and referenceNode is printed. If I run query1 (with the UUID) inside Eclipse, nothing is returned. HOWEVER, if I run query1 inside Jackrabbit Viewer, the query runs fine.

It seems like I have to escape the hyphens in my queryString but I tried adding double-backslashes and I get the same result. What is the proper way to run queries against UUID's?

  // Set up Nodes
  rootNode = session.getRootNode();

  Node referenceNode = rootNode.addNode("referenceNode");
  Node referencingNode = rootNode.addNode("referencingNode");

  referenceNode.addMixin("mix:referenceable");
  referencingNode.setProperty("pointer", new ReferenceValue(referenceNode));

  // Query
  String uuid = referenceNode.getUUID();
  QueryManager qm = ws.getQueryManager();

  String queryString1 = "//*[@jcr:uuid='"+uuid+"']";
  String queryString2 = "//referenceNode";

  Query q = qm.createQuery(queryString1, Query.XPATH);

  QueryResult result = q.execute();

  NodeIterator it = result.getNodes();

  while(it.hasNext()) {
   Node node = it.nextNode();
   System.out.println( node.getName());
  }

回答1:


The problem might be that the node is not saved yet. As written in the search documentation, "Node names and property values are indexed as soon as the data is saved or as soon as the transaction is committed."

In this case, I guess you could use Session.getNodeByIdentifier(String id) instead of using a query. It should be much faster as well.



来源:https://stackoverflow.com/questions/4683817/jackrabbit-running-queries-against-uuid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!