User Centric Query Rules

Matthew McDermott

by Matthew McDermott on 9/21/2014

Share this:
Print

Article Details

Date Revised:
9/18/2014

Applies to:
KQL, query rules, Search, SharePoint 2013, User Profiles


In SharePoint 2010, anytime a client asked for a query that uses User Profile properties to drive the results, we had to develop and deploy a custom search solution. In SharePoint 2013, we can now access User Profile properties through the much-improved Keyword Query Language (KQL). I use one simple example of this in my Search Session demos. I call it “Your Documents.”

Your Documents query rule

  1. Create a new Query Rule on Local SharePoint Results.
  2. Give the new rule a name.
  3. Remove the Query Condition; this rule will fire on all queries.
  4. Click Add Result Block and formulate your query as follows:
    1. Block Title – Your Documents for “{subjectTerms}”
    2. Query – {subjectTerms} Author:{User.Name} IsDocument=1

    This query says to give me only documents containing my subjectTerms where the Author property contains the current user’s name.

  5. Click OK.
  6. Click Save.
  7. Return to your search center and try a query using a word contained in a document you authored. You should see something like this:

mcdermott_usercentric1

Using other profile properties

I work with many clients who use SharePoint for knowledge management. Many of them create a knowledgebase or FAQs and the like. A common request is to create a query rule for hits on the FAQ articles and then hope that it will efficiently solve issues for the users. Here is the result of a simple query rule that shows a FAQ hit on the term “password.”

mcdermott_usercentric2

The thing that is special about this FAQ is that some of the articles are tagged by the location to which they apply. Notice that I got two hits for “password” because the process for changing your password in Austin is different from San Antonio. What I would like is only one hit based on the location of the user who issued the query.

mcdermott_usercentric3

With query rules, this is easy.

  1. Create a new Query Rule on Local SharePoint Results.
  2. Give the new rule a name.
  3. Remove the Query Condition; this rule will fire on all queries.
  4. Click Add Result Block and formulate your query as follows:
    1. Block Title – FAQ Results for “{subjectTerms}” that apply to your office
    2. Query – {subjectTerms} {Location:User.Office} Path:http://intranet.doghousetoys.com/IT/Lists/FAQ contentclass=STS_ListItem_genericlist

      This query says to give me only list items from the FAQ list containing my subjectTerms where the Location property contains the current user’s office. (Note: I included the path and contentclass in the sample for completeness; ordinarily I would create a result source for the FAQ to make life easier.)

    3. Update: It occurred to me that some folks might want to use the term store and the Office Location property; you can do that too. Change the query to “{subjectTerms} owsTaxIdLocation:{User.SPS-Location}”
  5. Click OK.
  6. Click Save.
  7. Return to your search center and retry the query. Ruby is in the Austin office, so her results for “password” are now specific to her.

mcdermott_usercentric4

Finally…

I am amazed, over and over, at what we can do with these powerful features of query rules. Try this out and see how it works for you!

Matthew's original blog


Topic: SharePoint Search 2013

Sign in with

Or register