Export (0) Print
Expand All

Using the Query Web Service

SharePoint 2010

Last modified: July 20, 2010

Applies to: SharePoint Server 2010

The Query Web service is located in the following path:

http://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.

The following table describes the Web methods available in the Query Web service.

Name

Description

GetPortalSearchInfo()

Returns a list of scopes.

GetQuerySuggestions

Returns a list of query suggestions, either pre-query suggestions, or post-query suggestions.

GetSearchMetadata

Returns a list of managed properties and scopes.

Query

Returns a set of results in an XML string for the specified query.

QueryEx

Returns a set of results in a DataSet for the specified query.

RecordClick(String)

Records information about the search query for query logging.

Registration(String)

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>
NoteNote

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>
NoteNote

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 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
FAST Search Server 2010 for SharePoint

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
FAST Search Server 2010 for SharePoint

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
FAST Search Server 2010 for SharePoint

The time it took to execute the search query, in milliseconds.

Definition

SharePoint Server search
FAST Search Server 2010 for SharePoint

The definition of the term specified in the Keyword extended property.

SpellingSuggestion

SharePoint Server search
FAST Search Server 2010 for SharePoint

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
FAST Search Server 2010 for SharePoint

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
FAST Search Server 2010 for SharePoint

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:

  • Title  The Best Bet title.

  • Url  The URL for the link to the Best Bet.

  • Description  The description for the Best Bet.

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 http://msdn.microsoft.com/en-us/library/ff394639.aspx#refinement_data.

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.

Show:
© 2014 Microsoft