Friday, May 20, 2016

Appending query terms to a search URL

image

I have written about appending query terms before without having them in the search box, and I’ve missed out at the best approach for this until now. Sometimes it takes years for the obvious solution to step forward.

In SharePoint 2010 you could add a= to a query and the terms on the a parameter would be included in the query as a hidden constraint. So how best to do something similar in SharePoint 2013/2016 or SharePoint Online? You modify the query template!!

A simple query template like {searchboxquery} {?{QueryString.a}} will take the value of the a parameter and append it to the query. Problem solved, and you can keep existing code if you migrated even.

Craft a query like: https://contoso.sharepoint.com/search?k=foo&a=title:bar and the query will filter to items where title includes the term bar, but not show it in the search box.

No comments:

Post a Comment