如何使用 sql2 查询执行以下操作:
要求:
小路:/content/consumer
- 转到一个节点级别,例如:/content/consumer/en-us
- 搜索在“/content/consumer/en-us”等路径字段中创作的字符串
- 如果
(current Node != Pathfield)
然后显示它。
重复从 1 到 3 的所有其他语言环境(en-ca、fr-fr、de-de 等)的步骤。
这是我尝试过的:
SELECT parent.* FROM [nt:unstructured] AS parent INNER JOIN [nt:unstructured] AS child ON ISDESCENDANTNODE(child,parent) WHERE ISDESCENDANTNODE(parent, [/content/consumer/en-us/]) AND child.[*] = '/content/consumer/%'
The query read or traversed more than 100000 nodes. To avoid affecting other tasks, processing was stopped.
如果我运行:
SELECT * FROM [nt:unstructured] AS s WHERE ISDESCENDANTNODE('/content/consumer/en-us/ip') and s.* LIKE '/content/consumer/%'
这将显示所有路径,而与本地无关。我正在寻找的是:/content/consumer/[^en-us]%(即不像 en-us)。
这是我到目前为止所做的:
Resource resource = request.getResourceResolver().getResource(path);
Node node = resource.adaptTo(Node.class);
ResourceResolver resourceResolver = request.getResourceResolver();
try {
NodeIterator list = node.getNodes();
while (list.hasNext()) {
Node currentSubNode = list.nextNode();
subNodeName = currentSubNode.getPath();
culture = extractCultureNodeName(subNodeName);
fullTextPath = path + culture;
Map<String, String> map = new HashMap<String, String>();
map.put("type", "nt:base");
map.put("path", subNodeName);
map.put("fulltext", fullTextPath);
if (StringUtils.isNotBlank(culture)) {
Query query = queryBuilder.createQuery(PredicateGroup.create(map),
resourceResolver.adaptTo(Session.class));
SearchResult result = query.getResult();
for (Hit hit : result.getHits()) {
String output = hit.getPath();
LOG.info("HITs: " + hit.getPath());
}
}
}
问题出在查询生成器中,我得到的命中数远远少于 crxde 中的裸 xpath 查询:
/jcr:root/content/consumer/en-us//element(*, nt:base)
[
(jcr:contains(., ‘/content/consumer/en-us’))
]