Wednesday, 28 November 2007

SharePoint - Search Customizations

Warning: we have drifted slightly from our initial aim of using only OOB functionality. We are actually writing code which uses the SharePoint object model. The Object model is too sweet to resist ;) and with small changes you can deliver fabulous results. The following is a post about using the KeyWord Query class to customize sharepoint search

KeywordQuery class:

This class offers quite an extensive range of functionality.

It is useful when you need to build advanced custom search webparts e.g. you have want the user to limit their searches to certain metadata only. To do this you create property mappings in the SharedServices search settings which map to the metadata you want to use in your search.

Then using the KeywordQuery class you can limit your search to certain properties only:

KeywordQuery query= new KeywordQuery("http://yourmosssite/");

Then using a dropdownlist or checkboxes with your lists of metadata you can create a search which limits the result to properties you have used. Let's say you want to limit to Author property

query.QueryText=textSearchBox.Text + "Author:'"+dropDownList.SelectedItem.Value+"'";

Another option is that you can create your own custom scopes, and then use these scopes to limit the search results:
query.HiddenConstraints="scope:" + "\"Customers\"";

Combining all the above options and creating a webpart with dropdowns and checkboxes you'l get very nicely customized searching in SharePoint focused exactly on your needs.