Exercise 2: Creating a Custom Ranking Model

Custom Ranking Models allow you to change the weights that are used by SharePoint search to rank results. In this exercise you will create a custom ranking model for tasks and use it with the search web parts.

  1. Launch Visual Studio 2010.
  2. In Visual Studio create a new XML file.
  3. Add the following code to create a custom ranking model that emphasizes task priority (you’ll
  4. find this file here: c:\student\Labs\11_Search\StarterFiles\Ranking Models\Important_Tasks_priority.xml):

    XML

    <?xml version=‘1.0’ encoding=‘utf-8’?> <rankingModel name=‘Important Tasks Priority’ id=‘c978ef2b-300a-444b-af9a-d51261294587’ description = ‘Ranking Model for Tasks’ xmlns=‘https://schemas.microsoft.com/office/2009/rankingModel’> <queryDependentFeatures> <queryDependentFeature name=‘Title’ pid=‘2’ weight=‘0’ lengthNormalization=‘10.0000000000’/> <queryDependentFeature name=‘Status’ pid=‘359’ weight=‘0’ lengthNormalization=‘5.0000000000’/> <queryDependentFeature name=‘DueDate’ pid=‘400’ weight=‘0’ lengthNormalization=‘2.5000000000’ /> <queryDependentFeature name=‘QueryLogClickedText’ pid=‘100’ weight=‘0’ lengthNormalization=‘20.0000000000’/> </queryDependentFeatures> <queryIndependentFeatures> <queryIndependentFeature name=‘DistanceFromAuthority’ pid=‘96’ default=‘5’ weight=‘0.0000000000’> <transformInvRational k=‘0.1359244473’/> </queryIndependentFeature> <queryIndependentFeature name=‘URLdepth’ pid=‘303’ default=‘3’ weight=‘0.0000000000’> <transformRational k=‘1.2170868558’/> </queryIndependentFeature> <queryIndependentFeature name=‘DocumentPopularity’ pid=‘306’ default=‘0’ weight=‘0.0000000000’> <transformRational k=‘1.2170868558’/> </queryIndependentFeature> <queryIndependentFeature name=‘DocumentUnpopularity’ pid=‘307’ default=‘0’ weight=‘0.0000000000’> <transformRational k=‘0.7333557072’/> </queryIndependentFeature> <categoryFeature name=‘Priority’ pid=‘347’ default=‘0’> <category name=‘Low’ value=‘3’ weight=‘25.0000000000’/> <category name=‘Medium’ value=‘2’ weight=‘50.0000000000’/> <category name=‘High’ value=‘1’ weight=‘100.0000000000’/> </categoryFeature> <languageFeature name=‘Language’ pid=‘5’ default=‘1’ weight=‘1.0000000000’/> </queryIndependentFeatures> </rankingModel>
  5. To work with custom relevance rankings, you use PowerShell. Start PowerShell by selecting Start » All Programs » Microsoft SharePoint 2010 Products » SharePoint 2010 Management Shell.
  6. Execute the following PowerShell cmdlet to list all of the Managed Properties in SharePoint Search:

    PowerShell

    Get-SPEnterpriseSearchServiceApplication | Get-SPEnterpriseSearchMetadataManagedProperty
  7. Using the information about the Managed Properties, carefully replace the property IDs (pid) in your XML file with the values given by the cmdlet.
    Note:
    Most of the PID’s are correct… just verify none of the names and PIDs are mismatched. Some in the XML file will not be listed in the Managed Properties list reported by the PowerShell command. Ignore these.
  8. Using PowerShell, you can add a new ranking model by simply copying the XML. Use the following cmdlet to add your custom ranking model to SharePoint -OR-

    PowerShell

    Get-SPEnterpriseSearchServiceApplication | New-SPEnterpriseSearchRankingModel –RankingModelXML ‘{YOUR XML PASTED AS A STRING}’
  9. To make things easier, you can run a preconfigured PowerShell script that will install a new ranking model for you. Execute the following batch file that will call the associated PowerShell script: c:\Student\Labs\11_Search\StarterFiles\Ranking Models\Add_Ranking_Models.bat.
  10. After you have added the custom ranking model, run the following cmdlet to list the available ranking models and verify that yours is present.

    PowerShell

    Get-SPEnterpriseSearchServiceApplication|Get-SPEnterpriseSearchRankingModel
  11. (Note:If you need to delete the model, use the following cmdlet)

    PowerShell

    Remove-SPEnterpriseSearchRankingModel -Identity ‘c978ef2b-300a-444b-af9a-d51261294587’ -SearchApplication Get-SPEnterpriseSearchServiceApplication
    Note:
    In this exercise you created a custom ranking model and installed it into SharePoint search.