Using the Query Web Service
Applies to: SharePoint Server 2010
Accessing the Query Web Service
The Query Web service is located in the following path:
https://Server_Name/[sites/][Site_Name/]_vti_bin/search.asmx
You can use a development tool such as Microsoft Visual Studio to create a client application to access the Query Web service. In the Visual Studio development environment, you can automatically generate a proxy class to access the Query Web service by adding a Web reference to your client application. For step-by-step instructions about how to add a Web reference to the Query Web service with Microsoft Visual Studio 2010, see How to: Add a Web Reference to the Query Web Service.
Alternatively you can use the Web Services Description Language (WSDL) tool to generate a proxy for the Query Web service. For more information see Web Services Description Language Tool (Wsdl.exe) and Creating an XML Web Service Proxy. For more information about creating client applications that call Web services, see Building XML Web Service Clients.
Web Methods
The following table describes the Web methods available in the Query Web service.
Name |
Description |
---|---|
GetPortalSearchInfo() |
Returns a list of scopes. |
Returns a list of query suggestions, either pre-query suggestions, or post-query suggestions. |
|
Returns a list of managed properties and scopes. |
|
Returns a set of results in an XML string for the specified query. |
|
Returns a set of results in a DataSet for the specified query. |
|
Records information about the search query for query logging. |
|
Returns the name for a specified site. |
|
Status() |
Returns availability of the search service. |
Query Methods
The Query Web service includes two methods for retrieving search results: Query and QueryEx. Both methods accept the same input, a string that contains XML that specifies the search query parameters. However, the format of the returned results differs.
Choosing the Query Web Service Method
To return multiple result types—such as relevant, special term, and refinement result types—in the search results, you must use the QueryEx method.
Building the XML for the Search Query
The XML format for the search query is defined in the Microsoft.Search.Query Schema.
The actual search query is specified in the QueryText Element in Microsoft.Search.Query Schema. You specify the query syntax that is used in the QueryText element's type attribute. For the SharePoint Enterprise Search query syntax references, see Building Search Queries.
The following code example is sample XML for the QueryText element that specifies a search query by using SQL syntax.
<QueryText language=xml:lang type='MSSQLFT'>
SELECT Title, Path, Description, Write, Rank, Size FROM Scope() WHERE CONTAINS(Description,'SharePoint')
</QueryText>
Note
If you are using SQL syntax with the Query method, you must specify the following properties in the SELECT statement of the SQL query: Title, Path, Description, Write, Rank, and Size.
The following code example is sample XML for the QueryText element that specifies a search query by using Keyword syntax.
<QueryText language=xml:lang type='STRING'>
SharePoint
</QueryText>
Note
There are some differences in the XML, depending on whether you are using SharePoint Server search or FAST Search Server 2010 for SharePoint as the search provider. This is explicitly stated with an "applies to" clause for each element.
You can specify which properties to return for the keyword query by using the Property Element in Microsoft.Search.Query Schema element.
If you do not specify any properties in the query XML, there is a default set of properties that is returned.
Following are the default set of properties returned for the Query method:
Title
Description
Date
Relevance
Following are the default set of properties returned for the QueryEx method when using SharePoint Server search as the search provider:
WorkId
Rank
Title
Author
Size
Path
Description
Write
SiteName
CollapsingStatus
HitHighlightedSummary
HitHighlightedProperties
ContentClass
IsDocument
PictureThumbnailURL
Following are the default set of properties returned for the QueryEx method when using FAST Search Server 2010 for SharePoint as the search provider:
WorkId
Rank
Title
Author
Size
Path
Description
Write
SiteName
CollapsingStatus
HitHighlightedSummary
HitHighlightedProperties
ContentClass
IsDocument
PictureThumbnailURL
Url
ServerRedirectedUrl
FileExtension
SpSiteUrl
docvector
fcocount
fcoid
PictureWidth
PictureHeight
Returning the Search Results
The QueryEx method returns the search results in a DataSet object, and the Query method returns the search results in a string as XML.
Note
The only result type supported by the Query method is relevant results.
Query Method
The format for the XML returned by the Query method is defined by the Microsoft.Search.Response Schema and the Microsoft.Search.Response.Document Schema. The full set of search results is contained in the Results Element in Microsoft.Search.Response Schema, where each individual result is represented by a Document Element in Microsoft.Search.Response.Document Schema.
QueryEx Method
The DataSet object returned by the QueryEx method contains ExtendedProperties properties that provide additional information about the query. Table 1 describes the extended properties that are returned.
Table 1. Extended properties
Name |
Applies to |
Description |
---|---|---|
QueryModification |
FAST Search Server 2010 for SharePoint |
The query modification for the search query. If the original query returns zero results, FAST Search Server 2010 for SharePoint can modify the query according to the setting of the ResubmitFlags element of the Query XML in the query. |
Keyword |
SharePoint Server search |
The token that is defined in the Definition extended property. |
IgnoredNoiseWords |
SharePoint Server search |
The list of noise words ignored in the original query, if the original query contained any noise words. |
QueryTerms |
SharePoint Server search |
The terms in the original search query. For SharePoint Server search, the query terms are separated by a semicolon (";"). For FAST Search Server 2010 for SharePoint, the original query text is returned. |
ElapsedTime |
SharePoint Server search |
The time it took to execute the search query, in milliseconds. |
Definition |
SharePoint Server search |
The definition of the term specified in the Keyword extended property. |
SpellingSuggestion |
SharePoint Server search |
The spelling suggestion for the search query. |
Depending on the options specified in the QueryEx request, and the search provider, the dataset returned can contain up to five data tables, which are described in Table 2.
Table 2. Tables that are contained in returned dataset for QueryEx
DataTable Name |
Applies o |
Description |
---|---|---|
RelevantResults |
SharePoint Server search |
The main result set that contains search results from the content index that matches the query. This table contains one row for each search result, and one column for each requested managed property. |
HighConfidenceResults |
SharePoint Server search |
The result set that contains the results defined as high-confidence results for the search query. |
SpecialTermResults |
SharePoint Server search |
The set that contains Best Bets that match the search query. This table contains one row for each search result. The columns in the table are as follows:
|
RefinementResults |
FAST Search Server 2010 for SharePoint |
The query refinement information for the results that match the search query. The table contains one row per refinement bin, and contains the columns RefinerName, RefinementName, RefinementValue, RefinementCount, and RefinementToken. For more information, see ff394639(v=office.14).md. |
VisualBestBetsResults |
FAST Search Server 2010 for SharePoint |
The Visual Best Bets that match the search query. The table contains one row per visual best bet, and contains the columns Name, Uri, Description, Keyword, Teaser, and TeaserContentType. The columns contain the name of the Visual Best Bet, the URL that the Visual Best Bet links to, a human-readable description of the Visual Best Bet, a short teaser to display, and the content type of the teaser. |