SharePointPortalServer Query service提供了一个WebService,http://servername/_vti_bin/search.asmx,主要有两个方法:
QueryEx
Query
两个方法的参数相同,都是一个XML结构的字符串。只是返回结果不同,QueryEx返回结果是DataSet,Query返回的是一个XML结构的字符串。
主要使用了两种查询类型:KeyWord、MSSQLFT.
KeyWord参数格式如下:
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
<?xml version="1.0" encoding="utf-16"?>
<QueryPacket xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
revision="1000" xmlns="urn:Microsoft.Search.Query">
<Query domain="QDomain">
<SupportedFormats>
<Format revision="1">urn:Microsoft.Search.Response.Content:Content</Format>
<Format revision="1">urn:Microsoft.Search.Response.Document:Document</Format>
<Format revision="1">urn:Microsoft.Search.Response.Form:Form</Format>
</SupportedFormats>
<Context>
<QueryText language="en-US" >
keyword
</QueryText>
</Context>
<Range>
<Count>1000</Count>
</Range>
</Query>
</QueryPacket>
keyword就是要查询的内容,一个普通的字符串,但是需要注意一点是不能只有一个字母,这样会报错!
MSSQLFT参数格式如下:
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
<?xml version="1.0" encoding="utf-16"?>
<QueryPacket xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
revision="1000" xmlns="urn:Microsoft.Search.Query">
<Query domain="QDomain">
<SupportedFormats>
<Format revision="1">urn:Microsoft.Search.Response.Content:Content</Format>
<Format revision="1">urn:Microsoft.Search.Response.Document:Document</Format>
<Format revision="1">urn:Microsoft.Search.Response.Form:Form</Format>
</SupportedFormats>
<Context>
<QueryText language="en-US" type="MSSQLFT">
SELECT "DAV:displayname",
"urn:schemas.microsoft.com:fulltextqueryinfo:displaytitle",
"urn:schemas.microsoft.com:fulltextqueryinfo:description",
"DAV:contentclass",
"DAV:href"
FROM ( Table Portal_Content..Scope() UNION ALL Table Non_Portal_Content..Scope())
</QueryText>
</Context>
<Range>
<Count>1000</Count>
</Range>
</Query>
</QueryPacket>
这些可以也可以通过对象模型来构建,添加对Microsoft.Search.dll的引用就可以了。
返回的DataSet中的DataTable包含"DAV:displayname","urn:schemas.microsoft.com:fulltextqueryinfo:displaytitle","urn:schemas.microsoft.com:fulltextqueryinfo:d
escription","DAV:contentclass", "DAV:href"Column,需要注意的是":"转换为"%3a","#"转换为"%23".
返回的XML结构如下:
无结果:
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
<?xml version="1.0" encoding="utf-16"?>
<ResponsePacket xmlns="urn:Microsoft.Search.Response">
<Response domain="QDomain">
<Copyright>Microsoft (c) Office SharePoint (tm) Portal Server 2003</Copyright>
<Range>
<Results />
</Range>
<Status>ERROR_NO_RESULTS_FOUND</Status>
</Response>
</ResponsePacket>
有结果:
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
<?xml version="1.0" encoding="utf-8" ?>
<ResponsePacket xmlns="urn:Microsoft.Search.Response">
<Response domain="QDomain">
<Copyright>Microsoft (c) Office SharePoint (tm) Portal Server 2003</Copyright>
<Range>
<StartAt>1</StartAt>
<Count>40</Count>
<TotalAvailable>3</TotalAvailable>
<Results>
<Document type="People" xmlns="urn:Microsoft.Search.Response.Document">
<Title>
.</Title>
<Action>
<LinkUrl fileExt="aspx">url</LinkUrl>
</Action>
<Description>
![](https://www.cnblogs.com/Images/dot.gif)
![](https://www.cnblogs.com/Images/dot.gif)
![](https://www.cnblogs.com/Images/dot.gif)
![](https://www.cnblogs.com/Images/dot.gif)
![](https://www.cnblogs.com/Images/dot.gif)
![](https://www.cnblogs.com/Images/dot.gif)
</Description>
<Properties xmlns="urn:Microsoft.MSSearch.Response.Document.Document">
<Property>
<Name>DAV:displayname</Name>
<Type>String</Type>
<Value>
.</Value>
</Property>
<Property>
<Name>urn:schemas.microsoft.com:fulltextqueryinfo:displaytitle</Name>
<Type>String</Type>
<Value>
.</Value>
</Property>
<Property>
<Name>urn:schemas.microsoft.com:fulltextqueryinfo:description</Name>
<Type>String</Type>
<Value>
![](https://www.cnblogs.com/Images/dot.gif)
![](https://www.cnblogs.com/Images/dot.gif)
</Value>
</Property>
<Property>
<Name>DAV:contentclass</Name>
<Type>String</Type>
<Value>
.</Value>
</Property>
<Property>
<Name>DAV:href</Name>
<Type>String</Type>
<Value>
.</Value>
</Property>
</Properties>
</Document>
<Document type="People" xmlns="urn:Microsoft.Search.Response.Document">
<Title>
.</Title>
<Action>
<LinkUrl fileExt="aspx">url</LinkUrl>
</Action>
<Description>
![](https://www.cnblogs.com/Images/dot.gif)
![](https://www.cnblogs.com/Images/dot.gif)
![](https://www.cnblogs.com/Images/dot.gif)
![](https://www.cnblogs.com/Images/dot.gif)
![](https://www.cnblogs.com/Images/dot.gif)
![](https://www.cnblogs.com/Images/dot.gif)
</Description>
<Properties xmlns="urn:Microsoft.MSSearch.Response.Document.Document">
<Property>
<Name>DAV:displayname</Name>
<Type>String</Type>
<Value>
.</Value>
</Property>
<Property>
<Name>urn:schemas.microsoft.com:fulltextqueryinfo:displaytitle</Name>
<Type>String</Type>
<Value>
.</Value>
</Property>
<Property>
<Name>urn:schemas.microsoft.com:fulltextqueryinfo:description</Name>
<Type>String</Type>
<Value>
![](https://www.cnblogs.com/Images/dot.gif)
![](https://www.cnblogs.com/Images/dot.gif)
</Value>
</Property>
<Property>
<Name>DAV:contentclass</Name>
<Type>String</Type>
<Value>
.</Value>
</Property>
<Property>
<Name>DAV:href</Name>
<Type>String</Type>
<Value>
.</Value>
</Property>
</Properties>
</Document>
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/dot.gif)
![](https://www.cnblogs.com/Images/dot.gif)
![](https://www.cnblogs.com/Images/dot.gif)
![](https://www.cnblogs.com/Images/dot.gif)
![](https://www.cnblogs.com/Images/dot.gif)
..
</Results>
</Range>
<Status>SUCCESS</Status>
</Response>
</ResponsePacket>
每个Document/Properties下的Property才是真正的结果,有几条记录就有几个Document.