Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
SDK Documentation
Web Services
Search Web Service
QueryService Class
 Query Method

  Switch on low bandwidth view
Community Content
In this section
Statistics Annotations (0)
QueryService.Query Method (Search)
Returns an XML string containing the search results set for the specified query.

Web Service: SearchWeb Reference: http://<Site>/_vti_bin/spsearch.asmx
Visual Basic (Declaration)
<SoapDocumentMethodAttribute("urn:Microsoft.Search/Query", RequestNamespace:="urn:Microsoft.Search", ResponseNamespace:="urn:Microsoft.Search", Use:=SoapBindingUse.Literal, ParameterStyle:=SoapParameterStyle.Wrapped)> _
Public Function Query ( _
    queryXml As String _
) As String
Visual Basic (Usage)
Dim instance As QueryService
Dim queryXml As String
Dim returnValue As String

returnValue = instance.Query(queryXml)
C#
[SoapDocumentMethodAttribute("urn:Microsoft.Search/Query", RequestNamespace="urn:Microsoft.Search", ResponseNamespace="urn:Microsoft.Search", Use=SoapBindingUse.Literal, ParameterStyle=SoapParameterStyle.Wrapped)] 
public string Query (
    string queryXml
)

Parameters

queryXml

A string specifying the search query XML. The XML format is defined by the Microsoft.Search.Query Schema for Windows SharePoint Services Search.

Return Value

A string that contains the query response using elements described by the Microsoft.Search.Response.Document Schema for Windows SharePoint Services Search.

For queries containing a simple list of search terms, set the type attribute for the QueryText element of the Microsoft.Search.Query schema to 'STRING'.

For SQL syntax queries, set the type attribute to 'MSSQLFT'.

If anonymous access is disabled for the Query web service's Windows SharePoint Services web application you must specify the credentials for the web service request using the Credentials property. The search results are trimmed based on the credentials of the current context of the request.

The default sort order is relevance rank. Only relevant results are returned; best bets are not included in the result set. If you want best bets included in the result set, use the QueryEx method.

Using elements from the Microsoft.Search.Query schema, you can specify the following for the result set returned by the Query web method:

  • Properties for sorting the results and the sort order direction, using the SortByProperty element.

  • Whether stemming is enabled, using the EnableStemming element.

  • Whether duplicates are collapsed, using the TrimDuplicates element.

  • Whether noise words are ignored, using the IgnoreAllNoiseQuery element.

The following code example shows how to invoke the Query method. This example assumes the following:

You have referenced the web service proxy class, here called QueryWebServiceProxy, in your code.

You have instantiated a string variable, queryXMLString, and set the value of this variable to the XML string containing the search query.

C#
QueryWebServiceProxy.QueryService queryService = new QueryWebServiceProxy.QueryService();
queryService.Credentials = System.Net.CredentialCache.DefaultCredentials;
string queryResultsString = queryService.Query(queryXMLString);
NoteNote:

Setting the proxy class Credentials property to the DefaultCredentials property of the System.Net.CredentialCache class allows you to use the credentials for the identity that the client application is running under for the web service request.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker