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.

Ranking Models

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.

  1. Created site columns and associated to a Document Content type “Employees”
  2. Associate the Employees content type to a document library.
  3. Added some sample documents with metadata values.
  4. Initiate the Full Crawl in the Search Service application
  5. Created the Managed Property for the Site Columns crawl property.

Content Type:


Document Library:


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


$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.


Posted by: R Manimaran | October 15, 2014

SharePoint 2013 REST API: Search using HTTP POST

SharePoint 2013 REST API: Search using HTTP POST

SharePoint 2013 provides REST API to do Search. There are two flavors of REST API for Search.

  • One which uses the HTTP GET
  • Second which uses the HTTP POST

Below is the sample to call the Search using the HTTP GET


But the Limitation in using the GET method with querytext is the length of the query string. Max Query text length allowed by the Keyword query is 4096 characters.

In order to overcome this limitations we can use the HTTP Post method to do search.

Resource End Point Url for POST Query: /_api/search/postquery

Below is the syntax of our ajax call to Post query

///method: postquery resource: Microsoft.Office.Server.Search.REST.SearchService
'HitHighlightedProperties':{'results': ['']},
'StrArray':{'results': ['']},
'RefinementFilters':{'results': ['']},

'SelectProperties':{'results': ['']},

'success':function (data) {
       var d = data;
'error':function (err) {

In this example I have placed a textbox and button to do the search. In the button click I have called this REST API call to bring the results using the keyword type in the textbox.

function PostSearch() {
var headers = {
        "Accept": "application/json;odata=verbose",
        "content-Type": "application/json;odata=verbose",
        "X-RequestDigest": jQuery("#__REQUESTDIGEST").val()

var endPointUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/search/postquery";
var searchQuery = {
'request': {
'__metadata': { 'type': 'Microsoft.Office.Server.Search.REST.SearchRequest' },
'Querytext': "'" + $('#txtSearchText').val() + "'",// getting the user feed information from a TextBox
var call = jQuery.ajax({
      url: endPointUrl,
      type: "POST",
      data: JSON.stringify(searchQuery),
      headers: headers,
      dataType: 'json'

call.done(function (data, textStatus, jqXHR) {
var html=[];
var queryResults = data.d.postquery.PrimaryQueryResult.RelevantResults.Table.Rows.results;
   if (queryResults.length > 0) {
       for (var i = 0; i < queryResults.length; i++) {
           var r = queryResults[i];
           var cells = r.Cells;
           var title = '';
           var id = '';
            for (var x = 0; x < cells.results.length; x++) {
            var c = cells.results[x];
               case "LastModifiedTime": id = c.Value; break;
               case "Title": title = c.Value; break;

if (id != '' || title != '') {
else {
    alert("No Results Found");
}); (data) {
    alert("Failure" + JSON.stringify(data));
Posted by: R Manimaran | August 8, 2014

SharePoint 2013 Search: Sorry Something Went Wrong

SharePoint 2013 Search: Sorry Something went Wrong:

I have created a site collection in SharePoint 2013 and created some items in a list. I have enabled Continuous crawling in the Search service application.

When I did a search, I received the error “Sorry Something Went Wrong”. It also provided me a Correlation id.

When I did a search in the SharePoint 15 Hive Logs, I found an exception “EndPointNotFoundException” and the error message says “Could not connect to net.tcp://pwsp2013/A75505/QueryProcessingComponent1/ImsQueryInternal.”.

Then I found the service “SharePoint Search Host Controller” found to be not running. After I start the service, the Search worked

SharePoint 2013: REST API: Associate an existing content Type to a SharePoint List

I have created a List using the SharePoint REST API, but when I tried to associate an existing Site Content type to this list I found difficult in doing that. Below is the endpoint and method I have used to associate my content type.

Resource End Point Url: /_api/web/lists/getbytitle(‘<listname>’)/ContentTypes

Method Name: AddAvailableContentType

I have used the Jquery to do the REST operations. Below is the format.

'success':function (data) {
   var d = data;
'error':function (err) {

We need to pass the Content Type id to get associated with the List. Below is the example I have used to associate Employees content Type to Employees List.


function addContentType() {
var siteUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('Employees')/ContentTypes/AddAvailableContentType";
var call = jQuery.ajax({
    url: siteUrl,
    type: "POST",
    data: JSON.stringify({
	  "contentTypeId": "0x0100E5EC1FE6D284A74A972A1776FFFE2DA0"
	'accept': 'application/json;odata=verbose',
	"content-type": "application/json;odata=verbose",
	"X-RequestDigest": jQuery("#__REQUESTDIGEST").val()

call.done(function (data, textStatus, jqXHR) {
var message = jQuery("#message");
message.text("Added Content Type Successfully");
}); (data, errorcode, errormessage) {
alert("Could not enable content types: " + errormessage);


Cannot install drivers. No Intel® Adapters are present in this computer:

I was installing Windows Server 2012 R2 in my laptop Lenovo L440. The laptop come with Windows 7 and initially all my Network cards are working fine.

After installing Windows server 2012 the machine does not able to locate my Ethernet card. I have downloaded the drivers in the below URL.

When I install the exe file I got the below error

When I search around in internet I came across some blogs they have mentioned the same issue.

Below are the steps I have followed.

· In your device Manager page, R.Click the Ethernet adapter driver and select properties.

· Go to the Details tab and select Hardware Ids property in the dropdown.

· Note down the Id in a notepad.

· Now extract the file contents of the driver(PROWIN64.exe) in a local drive.

· Locate the hardware id’s mentioned files in the extracted folder.

You can use the PowerShell to identify the files.

GET-ChildItem –recurse |Select-String –pattern “<your Hardware Id noted in notepad>” | group path |select name

In my case I am getting the 3 files containing this text.

Open the e1d64x64.inf file in the notepad and do the following. I have copied my Hardware entries to the below section

Which is missing.

Took a copy of this modified file and keep it safe.

Now run the PROWIN64.exe(un-extracted copy). This will extract the files in your temp folder.


After the extraction completed a wizard will be shown to install. Before clicking install, go to the temp folder and locate the file you have

modified and replace the file with the updated .ini file you have.

Now click install. The installation went file and my driver are updated successfully.

Posted by: R Manimaran | March 17, 2014

Change Data Table column values using Lambda expression

Change Data Table column values using Lambda expression

I have a resulted Data Table in which I need to replace all the values in a column. After replacement I need to create the DataTable again.

I have used a SharePoint list for this example. I have a list Project Contacts which contains a country column and below are the values.

I need to change all the value in the Work Country to “India”. I have used below Lambda expression to change the values.

SPQuery query = new SPQuery();

query.ViewFields= @"<FieldRef Name='Title' /><FieldRef Name='WorkCountry' />";

DataTable dt = list.GetItems(query).GetDataTable();


In the other case, I need to change the relevant values based on the Country values.

SPQuery query = new SPQuery();
query.ViewFields= @"<FieldRef Name='Title' /><FieldRef Name='WorkCountry' />";
DataTable dt = list.GetItems(query).GetDataTable();
dt.Rows.Cast<DataRow>().ToList().ForEach(r => r.SetField("WorkCountry", GetCountry(r["WorkCountry"].ToString())));</span>

 //Method to return Country name
 public static string GetCountry(string twoletter)
 string country=string.Empty;
 if (!string.IsNullOrEmpty(twoletter))
 switch (twoletter)
 case "IN":
 country = "India";
 case "CA":
 country = "Canada";
 case "US":
 country = "United States";
 return country;

Posted by: R Manimaran | February 24, 2014

PowerShell: Copy SharePoint List Attachments to Document Library

I have a SharePoint List which contains huge number of items. Most of the items will have attachments associated to it. I want to copy all the attachments and upload it to a document Library in the same site collection.

PowerShell script made my req very simple. Below powershell script will loop through all the list items and process its attachment.

$web = $site.RootWeb<br />
$Lists = $Web.Lists[$ListName]
 $Library = $web.Lists[$LibName]
 foreach($listItem in $Lists.Items)
      if($listItem.Attachments.Count -gt 0)
           Write-Host "**************************************************"
           Write-Host $listItem.Attachments.Count"Attachment(s) available in the ListItem:" $listItem.Title
           Write-Host "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
           foreach($attachment in $listItem.Attachments)<br />
               Write-Host $i".Attachment Name:" $listItem.Attachments.UrlPrefix$attachment
               $file = $web.GetFile($listItem.Attachments.UrlPrefix+$attachment)
               Write-Host "Adding Files to Library:"$Library.Title
               $bytes = $file.OpenBinary()
               $path = $Library.RootFolder.Url+"/"+$attachment
               $disFile = $Library.RootFolder.Files.Add($path,$bytes,$true)
               Write-Host "Successfully Added"<br /> Write-Host "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
        Write-Host "**************************************************"

The powershell can be downloaded in the below location.

Click here to download

Posted by: R Manimaran | December 27, 2013

SharePoint 2013 Community Sites

SharePoint 2013 has introduced a new site template Community Site that provides advanced Discussion list features such as

· Community Tools (Tools for managing the site, like you were presented in blog posts),

· Reputation model (you can assign badges to users and give points for the activities,

· Social (Like & Rely) and more.

Below link will provide the basic understanding of creating community site and working on Community sites.

Posted by: R Manimaran | December 25, 2013

New Access Denied and Access Request Page in SharePoint 2013

New Access Denied and Access Request Page in SharePoint 2013

In SharePoint 2013 the Access denied page has been changed with an access request comments textbox.

In the comments the user can type the message which will be sent to the site collection administrator.

Below is the access request page.

The site collection administrator will receive this request information in the “Access requests and invitations” under Users and Permission in the site settings page.

Under Pending Requests, the request will be shown as below. Click the “Call-up menu” which allow the user to provide access as shown

The message typed by the user will be provided with the Approve and Decline option in the bottom.

All the permissions will be displayed in the dropdown.

The Site users are also type the message and send back to the user, who requests the access.

Again if the same user accesses the site, the user can able to view the reply from the Site Owner as below.

Once the access is granted, the user can able to login to the site.

Posted by: R Manimaran | December 24, 2013

SharePoint 2013 New Event Receivers

SharePoint 2013 New Event Receivers

SharePoint 2013 has some new set of event Receivers which is added top of SharePoint 2010 events.  Below are the new events which are added. This involves both Synchronous and Asynchronous events.


« Newer Posts - Older Posts »