XRANK in SharePoint Search REST API

I work with SharePoint Search from some time now. Since many clients need assistance on Search optimization KQL is one of my best mates. Especially XRANK is very powerful function that leverage KQL capabilities but also enlarge its complexity. Anyway I feel quite sure about what we can achieve using KQL and how. However last week a colleague of mine asked me about what is proper syntax of XRANK in REST search query…and I was like “emmm…”.

There are many not obvious questions – which characters need to be encoded? Is the syntax the same as in common KQL query?

I did quick documentation check as well as googling for an answer but there was no satisfying results at all (if there is no answer in Stack Overflow the web contains no answer).

So this post is about clarification for XRANK syntax in REST API calls.

Use Search Query Tool

The old sentence says “Do not break open doors”. That’s why I did not investigate topic by myself trying different REST queries to SP Search. Instead I used great great great tool called Search Query Tool. It really makes your work with search easier and faster. You can build any kind of KQL query in it and it will be translated to REST query because it uses it to communicate with SharePoint.

So for instance if you want to execute following KQL query

*  XRANK(cb=1) Position:Manager

Its REST equivalent will be:

<SearchEndpointURL>?querytext=’*+XRANK(cb%3d1)+Position:Manager’

As you can see syntax is the same as in common KQL query however ‘=’ character has been encoded to URI format in order to be properly understood by browser and endpoint and any spaces has been replaced by “+”.

Complex XRANK queries

Remember that in order to build you must remember about proper use of parenthesis. For instance if you want to make multiple XRANK boosts you need to arrange them in following way:

(SearchQuery XRANK(cb=1) condition1) XRANK(cb=1) condition2

In other words, if you want to add boosting for position AND for date freshness your KQL will look like below:

(* XRANK(cb=1) Position:Manager) XRANK(cb=0.5) LastModifiedTime>{Today-365}

and your REST query text will be like following:

querytext='(*+XRANK(cb%3d1)+Position:Manager)+XRANK(cb%3d0.5)+LastModifiedTime>{Today-30}’

which gives you following results:

  • results older than 30 days and for person that position does not contain “Manager” in its name will get 0 ranking points
  • results modified less than 30 days ago and for person that position does contain “Manager” in its name will get 0.5 ranking points
  • results older than 30 days and for person that position does contain “Manager” in its name will get 1 ranking points
  • results modified less than 30 days ago and for person that position does not contain “Manager” in its name will get 1.5 ranking points

 

Hope it helps you in using XRANK and KQL in REST API queries.

 

Thanks & have a great day!

How to execute ANY SharePoint powershell command programmatically using C#

In one of my projects my team faced following challenges:

  • How to add query rules programmatically using C#
  • How to update thesaurus programmatically using C#

I tried to find information in official documentation but it was not very helpful neither was googling.

Powershell cmdlets to c# assembly mapping

In my team we were thinking what to do in this situation and one of my colleagues came with brilliant idea – he searched for PowerShell cmdlet in file explorer with searching in files content option turned on.

Result? What he found was exactly what we were looking for.

In location “C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\CONFIG\PowerShell\Registration” there is file named OSSSearchCmdlets.xml.

What it contains is xml structure with following structure:

       <ps:Cmdlet>

            <ps:VerbName>Get-SPEnterpriseSearchCrawlContentSource</ps:VerbName>

            <ps:ClassName>Microsoft.Office.Server.Search.Cmdlet.GetSearchCrawlContentSource</ps:ClassName>

            <ps:HelpFile>Microsoft.Office.Server.Search.dll-help.xml</ps:HelpFile>

        </ps:Cmdlet>

 

My eyes see this just as below:

       <PowershellToAssembllyMapping>

            <PowerShellCmdName>What-I-Have</PowerShellCmdName>

            <C#NameAndLocation>What-I-Am-Looking-For</C#NameAndLocation>

            <Whatever>Whatever.xml</Whatever>

        </PowershellToAssembllyMapping>

Maps for Search, WSS and many more

OSSSearchCmdlets.xml file contains ps cmdlets to .NET assemblies mapping only for SharePoint Search.

But in the same location there is also another file called WSSCmdlet.xml that contains all kind of cmdlets mapping like

  • Enable-SPFeature
  • New-SPContentDatabase
  • Get-SPFarm
  • Etc.

Shortly everything that you can do with SharePoint Application using PowerShell.

 

If you just want to quickly check what those files contains I’ve uploaded them to my github. I put there also more files like for Reporting Services, Workflows etc. You can check it here.

Have you found useful this tip? Maybe you know alternative way? Share it in comments!

Thanks & Have a great day! 🙂

 

How to map user profile to ECT field

Last week I encountered a problem related to External Content Type (ECT). I had a SQL table that contains article information: title, content and author. I wanted to search in that table using SharePoint 2016 search (on-prem). In order to do that I’ve created an External Content Type with above data, create content source and crawl it. Then I’ve mapped all crawled props to managed props in search. I was able to see articles data from SQL in my search results. 

Perfect? Not really…

Continue reading “How to map user profile to ECT field”

How I speed up loading my SharePoint Online site component 6x – part 2

Last week I wrote a post about how I fix CSOM code in order to accelerate whole query execution. Final result was not that bad though still not good enough:

  • 0.8s for fetching ~500 subsites
  • 6.5s for fetching ~900 subsites recursively for whole subsites hierarchy

My aim is to fetch whole subsites hierarchy within time that is reasonable to wait (1-2s total).

In this post I show you how to achieve it – we can fetch whole subsites hierarchy in less than 2s!

Continue reading “How I speed up loading my SharePoint Online site component 6x – part 2”

How I speed up loading my SharePoint Online site component 6x – part 1

Intranet home page should contains all information that are needed in daily manner. In fact many companies use home page as a traffic node where everybody comes just to find a navigation link pointing to another part of intranet. In my current company, Findwise, we do that too. However one of our components that allows us to quickly navigate through intranet sites gets slower and slower year by year. Currently it’s loading time is almost 10 seconds! I decided to fix it or even rebuild it if needed. Especially that few weeks ago on ShareCon 365 conference I talked about SharePoint Framework in Search Driven Architecture where I described the customer case, PGNIG Termika, who saved about 600k PLN (~$165.000) per year thanks to their information accessibility improvements (information time access dropped from 5-10 minutes to 1-2 seconds). 

In this post I wanted to show you what was the problem, how I fixed it and how my fix cuts the component loading time 6 times!

Continue reading “How I speed up loading my SharePoint Online site component 6x – part 1”

Sharepoint Framework in SharePoint Search Driven Architecture

On 16.10.2017 I had a privilege to be one of speakers on ShareCon365. I had technical speech where I showed how to make Sharepoint Framework (SPFx) apps in Search Driven Architecture. If you were on my speech you are probably interested in materials which you can find here: My presentation materials.

If you were not…than keep reading 🙂 

Continue reading “Sharepoint Framework in SharePoint Search Driven Architecture”

How to connect SPO to AWS with AAD auth (checklist)

Not that long ago I’ve posted article about connecting from sharepoint online to azure web service using AAD authentication. I’ve checked it several times and every time I had a feeling “it’s too hard to easily follow it…”. And that’s how idea of checlist has born!
Following checklist will help you if you have any problems due to connecting from Sharepoint Online to Azure web service using Azure AD authentication.

If you’ll need life example check my code implementation here .

In this blog post I described a context for below checklist – read it if you fall into problems with CORS like:

XMLHttpRequest cannot load https://<App_URL>. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘https://<tenant_name>.sharepoint.com‘ is therefore not allowed access.  Continue reading “How to connect SPO to AWS with AAD auth (checklist)”

Sharepoint Online to Azure Web Service authenticated with AAD

Problem

You want to communicate from Sharepoint Online with your Azure Web Application authenticated with AAD using javascript.

You configured AAD, run some AJAX call to service and received:
XMLHttpRequest cannot load https://<App_URL>. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘https://<tenant_name>.sharepoint.com‘ is therefore not allowed access.
Continue reading “Sharepoint Online to Azure Web Service authenticated with AAD”

Developing Sharepoint without Sharepoint installed

Problem

There are times when you want to develop Sharepoint solutions without having Sharepoint environment installed – i.e. when you want to build solution for Sharepoint Online. So you open Visual Studio, pick Sharepoint solution template, hit ‘ok’ and…

 

Cannot connect to the targeted site. This error can occur if the specified site is not hosted on the local system. SharePoint solutions work only with locally-installed versions of Sharepoint Foundation or SharePoint Server. Remote development is supported only for SharePoint Add-ins

or
The required version of SharePoint Foundation or SharePoint Server is not installed on this system. The target version of the SharePoint project is 15.0

 

You may think: “Why would I even need SP environment for that? I just want to build a solution for SP Online, not SP On-prem”. And I must agree with you. Even though you can develop Sharepoint Apps (Add-ins) having only Office Development Tools installed (without whole SP server) there are many scenarios where SP Apps are not an option.  So what to do in such situation?

Solution

There are 2 solutions: Continue reading “Developing Sharepoint without Sharepoint installed”

Sharepoint solutions vs SPFx vs Sharepoint Apps

  • “I’m so confused with all this SharePoint Framework, apps, solutions…I just wanted to develop for Sharepoint!”
  • “What can I use SharePoint Framework (SPFx) for? Can I use it for branding?”
  • “When should I pick custom SharePoint solution over SharePoint Framework or SharePoint App?
  • “How can I make elevated privilages in sharepoint hosted app?”

During my years of experience in SharePoint development I’ve seen those questions many times. They were asked by IT devs of my clients, by users of tech blogs/forums, my colleagues and also by myself. Since you’re here I’m assuming assume that you are confused a little bit too but don’t worry. We know what you feel. That’s why we’ve created this post.

Continue reading “Sharepoint solutions vs SPFx vs Sharepoint Apps”