Microsoft Office SharePoint Server 2007 provides two ways to enable search in your application
1. Query object model
2. Query web service
You can learn about them from here
What is the need of Dynamic Web reference ?
In one of my project, we are using SharePoint and we have enabled search in our application. We are using SharePoint Search web service for Search functionality. While development we add the web reference of the Search Service from our own machine( In my case MOSS 2007 is installed on my machine) i.e. http://
1.After adding the Web reference of the Search.asmx in your application, change the “URL behavior” property to “Dynamic”.
2.Create the instance of the QueryService class.
3.Change the URL property of the QueryService class to the your actual Service location.
Code Snippet:
public DataSet GetSearchResult()
{
string qXMLString = "<QueryPacket xmlns='urn:Microsoft.Search.Query'><Query><SupportedFormats><Format revision='1'>urn:Microsoft.Search.Response.Document:Document</Format></SupportedFormats><Context><QueryText language='en-us' type='MSSQLFT'>SELECT Title,Path,SiteName,ITEMID FROM Scope() WHERE FREETEXT(DEFAULTPROPERTIES,'SearchText') ORDER BY Rank </QueryText></Context><Range><StartAt>1</StartAt><Count>5000</Count></Range></Query></QueryPacket>"// SearchService is the Web Reference Name
SearchService.QueryService Search = new SearchService.QueryService();
Search.Url = "http://ServerName:portName
// You can also pick above search reference from your web config file in
// order to make it flexible.
DataSet SearchResult = Search.QueryEx(qXMLString);
return SearchResult;
}
No comments:
Post a Comment