Sitecore的快速查询 - 如何搜索包含特殊字符(如撇号)的文本?特殊字符、文本、快速、Sitecore

2023-09-04 11:05:51 作者:认真且怂从一而终

也许我是盲目的,但我不能找到转义特殊字符Sitecore的快速查询的任何文档。

例如,我要搜索包含在他们的描述中的以下文本内容项目:热N'美味

注:我已经试过以下转义:

  VAR搜索关键词=热N''好吃; //认为可能需要进行转义为SQL
VAR搜索关键词=#hot N'好吃#; //你这是怎么做一些其他Sitecore的逃逸
VAR搜索关键词=热ñ\'好吃;
 

示例应用程序code:

  VAR搜索关键词=热N'好吃;
VAR的查询=的String.Format(快:/ Sitecore的/内容/首页/产品展示// * [@ ContentDescriptionText =%{0}%],搜索关键词);
变种项= Database.SelectItems(查询);
 
mongodb模糊查询包含特殊字符

目前,这是给我一个例外,所以我假设我需要做某种逃避的:

  

]预计将在67位。

     

说明:执行过程中发生未处理的异常   当前Web请求。请查看更多堆栈跟踪   有关错误信息它起源于code。

     

异常详细信息:Sitecore.Data.Query.ParseException:]预计将在   位置67。

解决方案

的这是一个后做你想要做什么。基本上,你必须使用一个转义双引号来包装包含引号的字段值。

  VAR搜索关键词=热N'好吃;
VAR的查询=的String.Format(快:/ Sitecore的/内容/首页/产品展示// * [@ ContentDescriptionText = \%{0}%\],搜索关键词);
变种项= Database.SelectItems(查询);
 

编辑:在逃避快速查询,添加链接CoolMcGrr引用和它的局限性。这里

Perhaps I'm blind but I can't find any documentation on escaping special characters for Sitecore's fast query.

For example, I want to search content items that contain the following text in their description: "hot n' tasty"

Note: I've tried the following escaping:

var searchTerm = "hot n'' tasty";  // thought it might need to be escaped for sql
var searchTerm = "#hot n' tasty#"; // this is how you do some other sitecore escaping
var searchTerm = "hot n\' tasty";

Sample application code:

var searchTerm = "hot n' tasty";
var query = string.Format("fast:/sitecore/content/Home/Products//*[@ContentDescriptionText='%{0}%']", searchTerm);
var items = Database.SelectItems(query);

Currently, this is giving me an exception so I'm assuming I need to do some sort of escaping:

"]" expected at position 67.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: Sitecore.Data.Query.ParseException: "]" expected at position 67.

解决方案

Here is a post doing exactly what you are trying to do. Basically you have to use an escaped double quote to wrap the field value that contains a quote.

var searchTerm = "hot n' tasty";
var query = string.Format("fast:/sitecore/content/Home/Products//*[@ContentDescriptionText=\"%{0}%\"]", searchTerm);
var items = Database.SelectItems(query);

EDIT: Added link CoolMcGrr references on escaping fast queries and it's limitations.. here