我正在为我的用户开发一个JavaScript工具,以便使用预定义的值检索搜索结果。其中一个预定义值包含一个包含"与"符号的短语。我不知道如何格式化字符串,以便查询web服务返回一个值。
var eventCat = "Conference & Events";
var dateQ = "(DateStart>='" + startDate + "' AND DateStart<='" + endDate + "') AND ";
var eventQ = " EventCategory='" + eventCat + "' AND ";
var q = "SELECT Title,Path,Description,Write,Rank,Size,DateStart,DateEnd,EventCategory,GroupOnly FROM SCOPE() WHERE ";
q += dateQ + eventQ + " GroupOnly=false AND ("SCOPE"='Sales Marketing & Excellence Events')";
var queryText = makeQuery(q);
CCD_ 1创建查询web服务所需的XML<至<以及>到>。
<QueryPacket xmlns='urn:Microsoft.Search.Query' Revision='1000'>
<Query>
<Context>
<QueryText language='en-US' type='MSSQLFT'>
SELECT
Title,Path,Description,Write,Rank,Size,DateStart,DateEnd,EventCategory,GroupOnly
FROM
SCOPE()
WHERE
(DateStart>='2014-09-28T00:00:00Z' AND DateStart<='2014-11-09T23:59:59Z') AND
EventCategory='Conference & Events' AND
GroupOnly=false AND
("SCOPE"='Sales Marketing & Excellence Events')
</QueryText>
</Context>
<IncludeSpecialTermResults>true</IncludeSpecialTermResults>
</Query>
</QueryPacket>
当eventCat具有其他值(如All)时,这可以正常工作,但当我发送上面的查询时,SharePoint返回一个错误:An error occurred while parsing EntityName
。
我试着用各种替代品代替安培数,但我所做的一切都不起作用。发送的正确格式是什么?
我想明白了。我在查询周围添加了<[CDATA[
。
<QueryPacket xmlns='urn:Microsoft.Search.Query' Revision='1000'>
<Query>
<Context>
<QueryText language='en-US' type='MSSQLFT'><[CDATA[
SELECT
Title,Path,Description,Write,Rank,Size,DateStart,DateEnd,EventCategory,GroupOnly
FROM
SCOPE()
WHERE
(DateStart>='2014-09-28T00:00:00Z' AND DateStart<='2014-11-09T23:59:59Z') AND
EventCategory='Conference & Events' AND
GroupOnly=false AND
("SCOPE"='Sales Marketing & Excellence Events')
]]></QueryText>
</Context>
<IncludeSpecialTermResults>true</IncludeSpecialTermResults>
</Query>
</QueryPacket>