Wednesday, 19 March 2008

How to include custom columns in SharePoint Search

SharePoint search has few default columns already mapped. In case you are creating your own List and added few columns and you want SharePoint Search engine to include that column in Search result, you have to do following settings.

  1. Go to Central Administration.
  2. Under Shared Services Administration click on your SSP name.
  3. Go to Search -> Search Settings
  4. On "Configure Search Settings" page click on the "Metadata property mappings" settings.
  5. Click on "New managed Property"
  6. Choose the data type of your column in the List (Text/Integer/Decimal/Date Time/YesNo)
  7. Click on the Add mapping and Give few characters of your column name so that SharePoint can search that particular column.
  8. Now choose the column and click Ok.
  9. Now you can find your column in "Managed Properties View" and you can use this Mapped name in your select query.

Note: I had faced one problem while performing above steps. In step 7 while adding the column I was not able to find my column and after struggling a lot I found the solution for the same. Actually when you add any column in the List and if that column doesn't have any data In step 7 that column will not be found so to overcome this issue , before doing above steps make sure you have some data in the field you are interested in mapping in search also make sure after adding the data you have ran the "Full crawl" the site once.

Thursday, 13 March 2008

Using dynamic web reference in sharepoint Search Web service

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:///_vti_bin/search.asmx and search proxy class will use this information only. So the search will work on my machine but it fails on Production machine/server since it couldn’t find this used machine name ie <> . So to avoid this situation we can have something called dynamic Web reference and we can pass this information (http:///vti_bin/search.asmx) dynamically to our proxy class . Following are few very simple steps –

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/_vti_bin/search.asmx";
// 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;

}

Query List/Document Library in Specific Folder

To query SharePoint List or Document Library in specific Folder “ FolderServerRelativeUrl ” as part of the CAML Query Code Snippet ...