Jackrabbit 针对 UUID 运行查询 [英] Jackrabbit Running Queries against UUID

查看:17
本文介绍了Jackrabbit 针对 UUID 运行查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Jackrabbit,我正在尝试查询具有 UUID 的现有节点.我的代码如下所示.问题是 referenceNode 的 UUID 的格式为'90be246a-a17c-445e-a5ad-81b064de0bee'",而且 Jackrabbit (Lucene) 中使用的 XPATH 引擎似乎在处理连字符时存在问题.

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.

如果我运行 query2,一切都很好,并且会打印 referenceNode.如果我在 Eclipse 中运行 query1(使用 UUID),则不会返回任何内容.但是,如果我在 Jackrabbit Viewer 中运行 query1,则查询运行良好.

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.

似乎我必须在我的 queryString 中转义连字符,但我尝试添加双反斜杠并得到相同的结果.针对 UUID 运行查询的正确方法是什么?

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());
  }

推荐答案

问题可能是节点还没有保存.正如搜索文档中所写,节点名称和属性值在数据被索引后立即被索引保存或在事务提交后立即保存."

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."

在这种情况下,我想您可以使用 Session.getNodeByIdentifier(String id) 而不是使用查询.它也应该更快.

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

这篇关于Jackrabbit 针对 UUID 运行查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆