JCR-SQL-包含功能不能转义特殊字符? [英] JCR-SQL - contains function doesn't escape special characters?

查看:127
本文介绍了JCR-SQL-包含功能不能转义特殊字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下查询字符串:

SELECT jcr:title, jcr:created, jcr:description FROM cq:PageContent WHERE jcr:path LIKE '/content/.../%' AND CONTAINS (., '*') ORDER BY date ASC

问题是,查询正在从给定路径返回所有节点,即使它们在任何属性中都没有星号也是如此.我想转义星号字符,但结果是相同的.我已经尝试过这样的事情:

The problem is that the query is returning all nodes from the given path even though they don't have asterisk in any proeprty. I wanted to escape the asterisk character, but the result is the same. I've tried something like this:

SELECT jcr:title, jcr:created, jcr:description FROM cq:PageContent WHERE jcr:path LIKE '/content/.../%' AND CONTAINS (., '\*') ORDER BY date ASC

甚至是这样的东西:

SELECT jcr:title, jcr:created, jcr:description FROM cq:PageContent WHERE jcr:path LIKE '/content/.../%' AND CONTAINS (., '\*\*\*\*\*\*\*\*\*\*\*') ORDER BY date ASC

在所有这些查询中,即使这些页面都没有包含星号字符(或其中的11个)的属性,结果也是相同的

In all these queries, the result is the same, even though none of these pages have property which contains the asterisk character (or 11 of them)

jcr的文档:包含功能说:

在searchexp文字实例中,单引号('"),双引号(")和连字符("-)必须使用反斜杠(" \)进行转义,因此,反斜杠本身也必须进行转义,最后以双反斜杠("\")结尾.

Within the searchexp literal instances of single quote ("'"), double quote (""") and hyphen ("-") must be escaped with a backslash ("\"). Backslash itself must therefore also be escaped, ending up as double backslash ("\").

未提及其他字符,例如*,因此即使没有转义(?),它也可以正常工作.请让我理解为什么我在这里得到这样的结果,以及如何正确地逃脱这些字符.

Other characters like * are not mentioned so it should work even without any escaping (?). Please let me understand why I'm getting such results here and how to properly escape such chars.

推荐答案

我不确定jcr:contains是否适合您.也许jcr:like是您想要的更好的方法.

I'm not sure, if jcr:contains is the right method for you. Maybe jcr:like is the better approach for what you want.

jcr:contains是全文搜索,并使用lucene索引.因此可能会产生一些意想不到的影响.它也不能轻易地与其他索引结合.

jcr:contains is a fulltext search, and uses a lucene index. So it might have some unexpected impacts. It also cannot so easily combined with other indexes.

jcr:like是通配符的属性比较.而且此通配符可以用反斜杠转义. ( https://docs.adobe.com/docs/zh-CN/spec/jcr/1.0/6.6.5.1_jcr_like_Function.html )

jcr:like is a attribute comparison with wildcards. And this wildcards can be escaped with a backslash. (https://docs.adobe.com/docs/en/spec/jcr/1.0/6.6.5.1_jcr_like_Function.html)

第一个SQL-2查询示例

在任何属性中搜索带有*的cq:PageContent节点. %(百分号)是通配符.搜索*.

Searches cq:PageContent nodes with an * in any attribute. The % (percent-sign) is the wildcard-symbol. The * is searched.

SELECT * FROM [cq:PageContent] AS content
WHERE ISDESCENDANTNODE('/content/myproject/...')
AND content.* LIKE '%*%'


第二个SQL-2查询示例

搜索cq:PageContent节点,该节点的任何属性中都包含%.因此百分号用\%转义(并用通配符%包围).

Searches cq:PageContent nodes with an % in any attribute. Therefore the percent-sign is escaped with \% (and surrounded by the wildcard %).

SELECT * FROM [cq:PageContent] AS content
WHERE ISDESCENDANTNODE('/content/myproject/...')
AND content.* LIKE '%\%%'


第三个示例XPath查询

几乎与最后一个相同,就像XPath查询一样.只有我不知道如何搜索任何属性.因此,此示例搜索jcr:title属性.

Almost the same as the last one, just as XPath query. Only I just don't know, how you can search for any attribute. So this example searches for jcr:title attributes.

/jcr:root/content/myproject/...//element(*, cq:PageContent)[jcr:like(@jcr:title, '%\%%')]

这篇关于JCR-SQL-包含功能不能转义特殊字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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