Friday, August 1, 2014

SharePoint2013: Develop Search Based Pages/Applications that pull data based on Query String

Scenario: Develop search based applications or pages that pull data based on query string

Solution: In SharePoint2013 and SPO search based applications\solutions are in rise. On a single web page with minimal coding we can pull variety of data from multiple sources including different SiteCollections.

Consider below Query String that we can append to page URL
When we URL decode, it looks like below:-
OR ?k=Language="English" AND Language="Hindi"
OR ?k=Language:"English" OR Language:"Hindi"

On a single webpage we can add Script\Code, multiple CSWPs and other search related web parts and configure them to pull data related to above Query String parameter.

For example, I can add a CSWP on to a page and configure its query as below:-
{SearchBoxQuery} path:"" ContentClass:sts_web

The above query returns all the websites in a site collection specified in the "path" attribute. When user navigates to this page from a different page with above query string parameter, it only displays websites that are tagged with "Language = English"

On the same page we can also drag and drop Script Editor web part and using REST or JSOM we can pull data from a List Or Document library tagged with "Language = English".

In CSWP we can have below different type of query:-
path:"" (Language={QueryString.Language} OR RefinableString00={QueryString.RefinableString00} )

The above query shows all kinds of data including subsites, Documents etc. from Site Collection specified in the path. In the URL you can append query string like:-


It then show all types of content tagged with "English" Language.