Keyword Query Language (KQL) in SharePoint 2013 Search

Ahamed Fazil Buhari
 
Senior Developer
June 24, 2017
 
Rate this article
 
Views
12400

Hello Everyone, in one of my earlier article we have seen how Crawling and Managed Properties are working in search and how they form the data schema, against which search will query. In this article we can see more about Keyword Query Language.

In SharePoint 2013, there are three different query languages.

1. Keyword Query Language (KQL)

2. FAST Query Language

3. SQL Query (Completely Removed from the SharePoint 2013 product)

Keyword Query Language or KQL is the major query language. if you’ve been using the FAST product in SharePoint 2010, then you may be aware of FAST query language or FQL. The FAST query language is still available in SharePoint 2013, but we don’t need it just because KQL has been given so much supremacy.

Construct Query

To construct a Query, there are several elements that we can use.

· Free Text Search (* Wildcard operator)

· Property Search (AND, OR, NOT, >, <, = etc…)

If we want to blindly search for a word without any restrictions, then we can utilize free text searches. As the name implies, Free text searches are used as the basis of a search. Free text supports the idea of a wildcard operator in SharePoint 2013, so that you can type part of a word like buhari, followed by the *, and then we’ll get hits on everything that begins with buhari, and has whatever characters following it.

image

Property searches are done against Managed Properties, so once the Managed Properties are set up, then they can be used in these property searches and they are powerful. For example, if want to filter only the Title field in SharePoint then we can give the query as follows, Title: “test”. To know more about KQL please refer this msdn.

image

Keyword query language is a very powerful query language that is going to allow us to ask a lot of questions of the search engine. Say for example, I want to search all the SharePoint List Items that has been created by specific owner on specific time. we can achieve this requirement with single line of query

image

 

ContentClass:”STS_ListItem” Author: “username” LastModifiedTime=05/12/2016

Let’s review this query, we have a set of property Content Class contains STS_ListItem, Author and LastModifiedTime. So, in our case, what we have done is we have three different properties searches here. When you do not specify a Boolean operator, then this property search is an AND. So, we’ve asked for ContentClass AND Author and LastModifiedTime.

ContentClass is available to you out of the box in SharePoint 2013, and it allows you to specify the exact type of thing that you’re looking for. To know more about ContentClass please refer this msdn blog

This KQL can also work in the URL, you can pass the query in the URL and you will get the result. Like shown below,

https://ahamedspsite.com/Pages/My_Search.aspx#k=ContentClass%3A%22STS_ListItem%22%20Author%3A%22ahamed%20fazil%22%20LastModifiedTime%3D05%2F12%2F2016#l=1033

 

 

Happy Coding

Ahamed

Category : Search, SharePoint

Author Info

Ahamed Fazil Buhari
 
Senior Developer
 
Rate this article
 
Ahamed is a Senior Developer and he has very good experience in the field of Microsoft Technologies, especially SharePoint, Azure, M365, SPFx, .NET and client side scripting - JavaScript, TypeScript, ...read more
 

Leave a comment