Query variables and search alerts

As pointed out in my last blog that contains the Session recap DIWUG Finding or Search Query Variables are pretty awesome. Using these query variables you can create personalized and dynamic queries for your users. When configuring a query you can use a few different query variables. All of them are described on TechNet – Query variables in SharePoint Server 2013.

On of the demo’s described on the session recap DIWUG finding or searching is on using the enterprise search to write a personalized search query based on a users department.

(ContentTypeId:0x010100C568DB52D9D0A14D9B2FDCC96666E9F2* And Path:https://schot001.sharepoint.com/sites/contoso) OR (SiteName:{User.Department} AND ContentTypeId:0x010100C568DB52D9D0A14D9B2FDCC96666E9F2*

While this is a great way to write a powerful queries where each user find relevant news. This without having to write a query ready for each department. There is a downside to this approach.

When writing queries that contain query variables the alert functionality is not working properly. Each alert that is created based on a query that contains a query variable fails to execute. Resulting in users never receiving any alerts. You will however receive a notification that the alert is created. Yet in the end you will never receive any updates even though new content is added (and indexed) and is showing up as search results. 

This most likely has to to with the fact that the processing of the alert does not understand Query Variables. For personalized queries that uses a DateTime or a User object it does make some sense. The processing job does not know who the ‘user’ was at the time of creating the alert. However it is slightly confusing for the end users as they get a notification that their alert has been created yet they will never receive any alerts for that query.

So when working with Query Variables make sure to disable the alert me functionality in the result part and notify your content editors on why this is.