Friday, January 25, 2008

Creating Custom Properties in MOSS 2007 for People Search and Using CAML Queries for Searching

This is an acticle for Creating Custom Properties and Using the QueryEx method in the Search .ASMX webservice to retrieve the results.


The following Web Service was used to retrieve the Employee Details from the Profiler Database.
The above Web Service has a Web Method “QueryEx” which upon execution retrieves the results of the Employees from the Profiler Database.

QueryEx Method:

Input: SqlQuery

Output: Dataset of the People Results from the Profiler Database.

Sample Query:

string QueryXMLString= "<QueryPacket xmlns=\"urn:Microsoft.Search.Query\" Revision=\"1000\"><Query domain=\"QDomain\"><SupportedFormats><Format>urn:Microsoft.Search.Response.Document.Document</Format></SupportedFormats><Context><QueryText language=\"en-US\" type=\"MSSQLFT\">"; QueryXMLString += "<![CDATA[ SELECT FirstName,LastName,Path,OfficeNumber,AccountName,MailStation,CostCenter,JobTitle,WorkEmail,WorkPhone,WorkCountry,Department, SupervisorName,SupervisorID FROM portal..scope() WHERE "; QueryXMLString += "FirstName like '" + '%' + sFirstName + '%' + "' AND LastName like '" + '%' + sLastName + '%' + "' AND"; QueryXMLString += "( (\"SCOPE\" = 'Phone Book') ) ]]></QueryText></Context><Range><StartAt>1</StartAt><Count>100</Count></Range></Query></QueryPacket>";

The above Query returns the results with all the properties(Built-in and Custom) from the Profiler Database.

To make the Custom Propeties Searchable and used in the SQl Statement we have to make the following changes below should be in the Profiler Database.

First Click Sharepoint Service Provider(SSP)under the Sharepoint Services Administration
1) Click on User Pofile and Properties
2) Click View Profile Properties under the section “User Profile and Peoperties”.
3) Click on “New Property” and Create the new Custom Property.

--> First when we create the “Custom Properties” in the Profiler Database we should check the option “Indexed” in the Search Settings Section of the Custom Property.

--> Also in the “Policy Settings” Section Please select the Default Privacy Settings “Everyone”.

--> The run the “Full Crawl” in the Search Settings of the “SSP”.

--> This will enable the Custom Properties Searchable by the Web Services provided by the Sharepoint.

--> We can check the Properties available for Searching by following the below steps.
First Click Sharepoint Service Provider(SSP) under the Sharepoint Services Administration

--> Click the “Search Settings” under the Search Section.
Click on the “Managed Properties” under the Crawl Settings Section.
We will be able to see the “Custom Properties” like “MailStation” etc. on the “Managed Properties” under the Crawl Settings Section.