SharePoint 2010 Creating Custom Ranking Model – with Example –Part 1
SharePoint Enterprise Search using the Ranking Model called BM25 algorithm. This ranking models uses the field weightage on the managed properties. By default below are the built-in ranking models available in the SharePoint 2010 Search. We cannot modify these existing ranking models instead we can create my ranking model and attach.
Let us jump in to an example.
I have a custom site column “EmpName” which is mapped with a Document Content Type “Employees”. This Content type is associated with the Document Library. For each employees we will have a supporting document associated with him along with the other metadata fields like EmpID, DOB, DOJ and Work Location. The Employee name will be placed in the document associated to the user. And also a particular employee name will be mentioned in other user document as Reporting to/Reporters. So when I do a Keyword Search using the Employee name SharePoint will not bring the exact Employee record first (i…e based on EmpName metadata) instead it bring based on the name placed inside the document.
This is because my search using the default ranking model “MainResultsDefaultRankingModel” in which the weightage is given to body,title,Author respectively. Here my custom column EmpName is not there so when I did a Search I get the results as below.
Let us create a new Ranking model to fix this. Before that I have created the below.
- Created site columns and associated to a Document Content type “Employees”
- Associate the Employees content type to a document library.
- Added some sample documents with metadata values.
- Initiate the Full Crawl in the Search Service application
- Created the Managed Property for the Site Columns crawl property.
Custom Ranking Model Schema: Custom Ranking Model has a XML Schema where we need to specify the custom managed Property along with the weight-age. We can find the syntax here
Below is my Custom Ranking Model Example.
Here in the XML we need to specify the PID number of the managed property. This can be identified using the below PowerShell.
Next step is we need to upload the new ranking model to SharePoint. I have placed my xml file in my local drive and used the below PowerShell command to create a new Ranking model.
$rankingModel=Get-Content C:\Maran\EmpRankingModel.xml $rankingModel=[string]$rankingModel $ssa = Get-SPEnterpriseSearchServiceApplication -Identity "Search Service Application" New-SPEnterpriseSearchRankingModel -SearchApplication $ssa -RankingModelXML $rankingModel
We can check our new Ranking model added to the SharePoint using the below query.
In the part 2 we will use the Keyword query to get the results.