Sitecore的快速查询 - 如何搜索包含特殊字符(如撇号)的文本? [英] Sitecore Fast Query - How to search for text containing special characters (such as an apostrophe)?

查看:218
本文介绍了Sitecore的快速查询 - 如何搜索包含特殊字符(如撇号)的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

示例应用程序code:

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

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

  

]预计将在67位。

     

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

     

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

解决方案

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

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

编辑:在逃避快速查询,添加链接CoolMcGrr引用和它的局限性。<一个href="http://sdn.sitecore.net/upload/sdn5/developer/using%20sitecore%20fast%20query/using%20sitecore%20fast%20query001.pdf"相对=nofollow>这里

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

这篇关于Sitecore的快速查询 - 如何搜索包含特殊字符(如撇号)的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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