SharePoint 2013: How to Create Custom Result Blocks using Query Rules

In this article we are going to explore SharePoint Search Custom Result Blocks configured using Query Rules.

What are Results Block?

A Result Block is set of filtered results that are combined with core search results and displayed on top of the core search results as a block or can be ranked with in the Core Search Results depending on how you configure it to be.

It is not required to have results for Result Blocks from Local Search index only. A Result Block can use any of the result source from the below list:

  1. Local SharePoint farm
  2. Remote SharePoint farm
  3. OpenSearch
  4. Exchange

In order to setup this demo, I have prepared the system with some test User Profile data as described below:

I have setup three User Profiles with different job titles as shown below:

User 1 : SP\Administrator

1

User 2 : SP\Guest

2

User 3 : SP\SPDeveloper

3

In order to configure Result Block, we need to start it with Query Rules configuration by using the following steps:

Go To Site Settings

4

Under Search, Click Query Rules

5

Choose Result Source as applicable, here I am working on Local SharePoint Search Results

Click on New Query Rule

6

Under General Information, Enter Rule Name

Under Query Conditions,

  1. Select Query Options as needed, here Advanced Query Text Match works for me
  2. Select phrases which you want to be included while matching query text issued by the user

7

Click on Add Result Block

8

Enter Block Title, this title will be added as Header with the Result Block displayed on Search Result Page.

Click on “Launch Query Builder” Button

Select the number of items to be displayed inside the result block from Items Dropdown as shown below, here I will go with 4 items to be displayed inside Result Block.

9

Configure the Query as shown below:

  1. Select a Result Source to as target for the query, here I am using “Local People Results” as I have setup test data in User Profiles.
  2. Choose suitable property to filter on from Property Filter Drop Down
  3. Choose suitable Operator
  4. Choose suitable value type
  5. Choose suitable value as shown below
  6. Click on Add property Filter
  7. This will add the query filter to the Query Text box
  8. Click on the Test Query Button, to validate the query you have just created
  9. Search Result Preview Section will show few of the total search results returned by the query just configured in the previous steps
  10. Click OK to close Query Builder Dialog

10

Always Choose the setting as shown below, if you want to have Result Block Displayed on top of Core Search Results as a separate block.

You can also choose to display “More” Items link, in case you want to show case the complete result set retuned based on the Query Rule. For this to happen you have to have a separate page configured with the same query to show all the results. I am choosing here not to display it.

11

And That’s it.

We are all done with the configuration work for the result block and now it is time to test the results returned based on the configuration we did above.

Final Configuration would look like as shown below:

12

In order to test the scenario, Enter “MOSS” or “sps” or “wss” as Search Term, remember we added “MOSS, sps, wss”in the search phrases while configuring Query Rules.

Since we got the search term “MOSS” or “sps” or “wss” as a Query issued by user, SharePoint Search System identifies a suitable query rule by matching this term with the phrases we specified while configuring Query Rules above and filter out the results based on the query we specified, in this case it was “JobTitle:SharePoint”, which mean finds any Profiles for which Job Title Property contains the word “SharePoint” .

Based on the query treatment as mentioned above we got two profiles “User 1 : SP\Administrator” with Job Title “SharePoint Administrator” and “User 2 : SP\Guest” with Job Title “SharePoint UI Designer”, displayed as valid results inside Results Block.

On the other hand we do not get “User 3 : SP\SPDeveloper” listed in the Result Block as Job Title Property for this profile is blank, due to this “JobTitle:SharePoint” match gets failed and this result get filtered out as shown below.

13

14

15

Hope this will help someone in need…

SharePoint 2013 : Promoted Search Results

In this post we will explore another cool SharePoint Search Feature commonly known as “Promoted Results”.

Before diving deep into implementation details, let’s have some background on this new cool feature of SharePoint 2013 Search.

What are Promoted Results?

Since the SharePoint 2013 Search System is built up from scratch by absorbing all great features from its predecessors, one of such features is known as “Best Bets” in SharePoint 2010 Enterprise Search, “Visual Best Bets” if we are using Fast Search and now “Promoted Results” in SharePoint 2013 Search Environment.

Promoted Results are triggered by one or the other conditions specified while defining the Promoted Results as we will see next in this post.

In order to define the Promoted Results we will proceed as follows:

Go to “Site Settings -> Query Rules” as shown below:

1

2

On Manage Query Rules Page, Select the appropriate Result Source suited to your needs, then click “New Query Rule” Link as shown below:

3

On the “Add Query Rule” Page

  1. Specify the Rule Name
  2. Specify Query Conditions

Please note the Keyword “SharePoint” that we specified in the below configuration, this will ensure that whenever Search Query contains the Keyword “SharePoint” this Promotion will be served as a part of the search results retuned as a response to this query.

4

Then click on “Add Promoted Results” Link

5

On the “Add Promoted Result” Page,

  1. Specify the Title : Any Valid Title
  2. Specify the URL: Any valid URL of the .aspx Page with valid HTML inside it.

Check the “Render the URL as banner instead of as a hyperlink” checkbox, this will ensure that Promotional Content will be displayed in HTML View instead as a hyperlink.
Click Save to save the changes.

6

Under the “Publishing” Section,

  1. Select “Is Active” Checkbox to enable this Timeline Driven Promotion.
  2. Specify “Start Date” & “End Date” to specify the Timelines for this Promotion to be visible on top of the search results.

7

And that’s it with the Configuration of New “Promoted Result”.

Final configurations would look like as shown below:

8

Now it is the time to Test the “Promoted Result”.

Visit Global Search Center Site and specify the Keyword “SharePoint” as query as shown below.

And sure enough we will get the Promotional Result at the very top of the search results.

9

So we can see how easy is to implement Promoted Results in SharePoint 2013.

Hope this will help someone in need…

SharePoint 2013: How to Develop Custom Content Enrichment Service

In this article we are going to explore one of the Advanced Features of new SharePoint 2013 Search Architecture.

With the evolution of new SharePoint 2013 Search Architecture, SharePoint allows developers to intercept the Content Source Crawl Engine Processing by adding a Custom Step in the Content Processing Mechanism.

If we closely monitor the Content Processing Mechanism, we can identify easily the step where we can hook up the Custom Content Enrichment Service for supporting and extending Content Enrichment process.

1.1

Under the hood, this Custom Content Enrichment Service is implementing an interface “IContentProcessingEnrichmentService”, which is having method that can deal with the incoming Items.

We can utilize Custom Content Enrichment Service in the following scenarios:

  1. If need to push new Managed Properties based on the Content Source being Crawled
  2. If need to push new Managed Properties based on existing Managed Properties associated with the Content Source being Crawled.
  3. If we need to normalize the Managed Properties values when we are dealing with Heterogeneous Content Sources.

So in this walkthrough we will see Scenario 2 where we can push new Managed Properties based on values present in existing properties.

In order to setup the test scenario we need a List with two columns “DemoCompany” and “DemoCompanySymbol” as shown below:

2

Once we got the list ready with columns and data, we have to initiate a full crawl so that the respective Crawled Properties based on these columns are created by the crawling process.

3

4

Now once we are done with setting up the content source, next thing is to create Managed Properties we are going to employ in this demo.

We have two types of Managed Properties which we should consider in this Demo:

  1. Input Properties: These are the Properties which will be supplied to the Custom Content Enrichment Service as Input.

In this case we have DemoCompany, DemoCompanySymbol as Input Properties.

  1. Output Properties: These are the Properties which will be returned back to SharePoint Crawl from Custom Content Enrichment Service after the Properties are nourished with updated data.

In this case we have DemoCompanyWithSymbol as Output Properties.

Only Input properties must be mapped with the respective crawled properties and Output properties must remain unmapped as they will be updated by the Custom Content Enrichment Service.

Also all these properties should be marked as “Queryable”,”Searchable”,” Retrievable” shown below:

5

Also pay attention on the Data Type of these properties, as this information will be needed at the time of retrieving their values in our Custom Content Enrichment Service.

With this we are all done with Content Source Definition, Managed Metadata Properties Configuration.

Now the next thing is to start with the Development of Custom Content Enrichment Service as shown below:

  1. Launch Visual Studio
  2. Create a new Project of type “WCF Service Application”

6

7

Add a reference to “microsoft.office.server.search.contentprocessingenrichment.dll” which can be located at “C:\Program Files\Microsoft Office Servers\15.0\Search\Applications\External”

8

9

10

Add following using statement to your service class:

11

In order to understand the working of this code let’s run Code DNA Test as mention below:

12

  1. Inherit the Service Class with the interface IContentProcessingEnrichmentService
  2. Preparing a variable processedItemHolder of type ProcessedItem to hold the incoming item after processing.
  3. Implement ProcessItem(Item item) Method of IContentProcessingEnrichmentService Interface to deal with incoming Item.
  4. Defining OutPut Managed Property as “DemoCompanyWithSymbol” which we need to create before start writing the code for this service as we have already done above.
  5. Retrieving Input Property DemoCompany, by type casting it as per the Data Type of the Managed Property, like in this case we have a Text type Managed Property so the we are using Type Casting as Property<string>.
  6. Retrieving Input Property DemoCompanySymbol, by type casting it as per the Data Type of the Managed Property, like in this case we have a Text type Managed Property so the we are using Type Casting as Property<string>.
  7. Add the new Property to existing set of properties by using ItemProperties.Add(demoCompanyWithSymbol)
  8. Then finally return the item back to the Crawler for indexing with new set of properties.

In this case we have initialized the “DemoCompanyWithSymbol” Managed Property with the combination of DemoCompany and DemoCompanySymbol properties as

demoCompanyWithSymbol.Value = string.Format(“Company {0} has a symbol {1}.”, companyProperty.Value.First(), symbolProperty.Value);

Once we are done with the code, hit F5 to run the Custom Content Enrichment Service in Debug Mode, so that we can test the logic and debug the issues if we get any.

As soon as you hit F5 you will get a WCF Test Client Application Launches, on this application page copy the URL of the service as shown below:

13

Paste it in the Browser to validate if it is running fine.

14

Ok now when we have got our Custom Content Enrichment Service up and running we can let SharePoint know about this service.

This Service Extension can be registered with SharePoint using PowerShell as shown below:

15

And in case you need to remove this registration later on you can use the following PowerShell command:

19

16

Now once the registration is done, we need to initiate the Full Crawl in order to re-process all the Crawled Items as per the logic written in the Custom Content Enrichment Service.

This is the time when you can put break point in your code and expect it to hit when the Full Crawl sends the first and any subsequent item to Custom Content Enrichment Service for Processing.

At this time you can intercept the code execution to inspect the incoming Items.

17

Once full crawl is done, execute the Search Query directly in browser to see if the new Property DemoCompanyWithSymbol contains the value provided by our Custom Content Enrichment Service.

We can build the search query shown below:

http://<Server Name>/_api/search/query?querytext=’DemoCompanySymbol:DC01110’&selectproperties=’DemoCompany,DemoCompanySymbol,DemoCompanyWithSymbol’&sourceid='<Result Source ID>

Execute the Query and analyze the response to see for DemoCompanyWithSymbol property and sure enough we should get the DemoCompanyWithSymbol property updated with new values as shown below:

18

This implementation could be really effective in cases where we are dealing with Heterogeneous Content Sources or where we are lacking with lesser amount of Metadata information than expected.

Hope this will help someone in need…

SharePoint 2013 : Execute SharePoint Search Queries using CSOM

In this article we will explore the method of executing Search Queries using SharePoint Client Side Object Model. The code sample used in this article can be used in any kind of solution (Farm, Sandbox) or any kind of App (SharePoint Hosted, Cloud Hosted) executing in context of SharePoint.

Prerequisites:

  1. Fiddler Web Proxy should be installed. You can get Fiddler from http://www.telerik.com/download/fiddler

Like in other of the earlier articles we will start with creating new SharePoint Hosted App.

1

The next thing is to provide a simple UI for our implementation which allows the users to specify the Search Terms & execute the queries.

In order to keep the story simple we will take one input box to specify the Search Terms & one button to execute the query as shown below.

2 3

Now once we are done with the UI of the App, the next thing is to prepare a module that will execute the Search Queries and receive the response.

4

Following is the detail inspection of the above code snippet

  1. Initialize SharePoint Context variable (Step 1) then we need to
  2. Initialize the Query Object (Step 2) using the context variable created in Step 1.
  3. Set the Query Text (Step 3). This query text has been specified in the input box by the user executing the query.
  4. Initialize the Search Executor Object (Step 4) using the context variable created in Step 1. This object is solely responsible to execute Search Queries. This object contains a method “executeQuery” which takes query text as its parameter.

Now the next challenge is to identify how to code the next step, as it is dependent on response coming from the SharePoint REST End Point in return of the request executed in Step 4.

So the trick to first reviews the response coming from SharePoint using any Web Proxy. Being a big fan of Fiddler I must insist to make use of it to the purpose.

Below image is showing some sample data present in one of the lists called “Customer”.

5

For the sake of demo let’s pick “ALFKI” as Search Term. On clicking the “Executing Search using CSOM” , the Search Query gets issued to SharePoint End Point and if it is a success we will get the response for sure.

6

If we investigate the response in Fiddler we can see the data structure returned as a part of the response.

7

Based on this observation, we can read the data as shown in Step 5 above.

Once we receive the search results, it is just the matter of choice on how to display it. For the sake of this demo I am just displaying the search results in a div already added to the App UI.

8

And that’s it. We are all done here.

Though the scenario I mentioned here is quite simple, but the presence of Client Side Search APIs in SharePoint 2013 is proved to be very powerful and could be utilized to cater complex business requirements without using any custom code.

Hope this will help someone in need…

 

SharePoint 2013 : How to Create Custom Intent Based Results Blocks Using Query Rules

In this post we will explore a new mechanism of Searching data based on Custom User Intents and serve them as Result Blocks on top of the Search Results.

What is Custom User Intent?

Custom User Intent means matching a Search Term specified by the end user with the Phrases defined using Query Rules. For example, PowerPoint Slides are also known as Decks. So if the business user specified a Search Term as “SharePoint Deck”, it was really intended to search all the PowerPoint Slides which contains “SharePoint” as shown in the image below.

1

Hope the above example suffices to clarify the Custom User Intent.

Business Scenario

For the sake of this demo, I have setup an imaginary scenario, where in my organization business users refer all types of videos as “Small Medium Sized Video” or “SMV”. As the matter of habit all users make use of keyword “SMV” in order to search for video files in SharePoint System.

In order to implement the Custom User Intent based on above scenario we have to follow the below steps:

  • Go To “Site Settings”

2

  • Under “Search” section Click on “Query Rules”

3

  • Create & Configure Query Rule
  1. Select the required “Result Source”, in our case we can go with “Local SharePoint Search Results”.
  2. Click on “New Query Rule” in order to create a new Query Rule.
  3. Specify rule name as “Custom Video Intent”
  4. Under “Query Conditions” “Query Contains Action Term” and specify the phrases you want to match to identify the User Intent, like we specified as “smv;smvs”.
  5. Click on “Add Result Block” to specify the query based on which Result Block will be rendered.

4

5

6

  • Configure Result Block
  1. Specify the “Block Title” as shown below
  2. Click on “Launch Query Builder” button to configure the query

7

  • Configure query
  1. Select result source “Local Video Results”
  2. Click on “Test Query” button to test the query based result source selected in Step 1
  3. “Search Result Preview” Section on the right will show the results returned as a part of the query specified earlier.
  4. Click “OK” to save the Query Changes.

8

  • Configure Display Template

Choose suitable Display Template from “Item Display Template” dropdown list.

9

10

And that’s it. We are all done with our new Query Rule defining Custom User Intent.

 

11

Now it is time to see the Query Rule in Action. In order to test it go to Search Center and enter “SharePoint smv” as search term and click Search Icon. You will see the Search Results Block “Video Results for SharePoint” containing items which contains “SharePoint” in their Title or Description.

12

Hope this will help someone in need…

SharePoint 2013: How To Create Custom Display Templates For SharePoint Search

What are Display Templates?

Display Template is a new technique introduced in SharePoint 2013 in order to modify the look and feel of the search results by making use of HTML & JavaScript instead of XSLT modifications as we did in the earlier versions.

With this new rendering technique or rather framework, SharePoint offers some of the most compelling advantages as mentioned below:

  1. Display Templates Support HTML & JavaScript instead of XSLT (which is often quite cumbersome to work with).
  2. Display Templates based configurations supports a broader scope of execution than XSLT based configurations. (As Display Templates should be defined at Site or Site Collection Scope while XSLT based Templates could only be defined at the WebPart Scope).
  3. Display Template applies Per Item Basis and not Per Result Set Basis (Provides us with the Context of the Current Item which is under execution, so that we can make use of any Managed Metadata Property associated with the Search Result Item and render it as per needs)
  4. As the Display Templates are scoped to Site or Site Collection, they can be used for all kind of results, can be used with in Content Search Web Part, Refiners and so on.

I recommend you to follow this MSDN Article on Display Templates to get an in depth understanding on the topic.

By now we got a fairly good Idea on “What are Display Templates?” and now it is time to see them in action.

Business Scenario:

  1. Additional User Profile Property should be added to User Profile Page which will hold the User’s LinkedIn Profile URL.
  2. There should be a provision to adjust the display position of this Property in Core Search Result Web Part.

Prerequisites:

  1. User Profile Service should be up and running
  2. User Profile Synchronization should be configured
  3. Search Service Application Instance should be configured appropriately
  4. Search Center Site Collection should be configured appropriately

In order to see Display Templates in Action, we need to perform following steps:

  1. Create User Profile Property
  2. Start Full Crawl of Content Source for the User Profiles
  3. Create, Map and Configure Managed Property
  4. Start Full Crawl of Content Source for the User Profiles
  5. Create Display Template
  6. Create Result Type with Custom Display Template
  7. Test Display Template

Create User Profile Property

Go To Central Admin >> Manage Service Applications

1

Click on User Profile Service Application

2

Click on Manage User Properties

3

Click on New Property

4

Enter Name, Display Name, Type & Length for the User Property as needed.

5

Make sure Default Privacy Setting must be set to Everyone

6

Make sure Indexed must be selected under Search Settings Section, else this property will be skipped by Search Crawler and it won’t be available to use later.

7

Once done with it click OK to add the User Property

8

Once added you can find the new property under Custom Properties Section

9

Go to Manage User Profiles

10

Find the required User Profiles and Edit their Profiles by selecting Edit My Profile from ECB Menu

11

On the User Profile Page, locate the LinkedIn Profile Property

Enter the URL to LinkedIn Profile of the User and Save the User Profile Properties

12

13

With this we are all done with the Creation of User Profile Property.

Start Full Crawl of Content Source for the User Profiles

Now in order to generate the Crawled Property corresponding to the User Profile Property we need to run the Full Crawl on the People Content Source

Go to Search Service Application

14

Click on Content Sources

15

Click on People Search and select Start Full Crawl from ECB

16

Wait till the Crawl Status become Idle

Create, Map and Configure Managed Property

Go to Search Schema

17

Click on Crawled Properties Link

18

We should verify if the Crawl Property corresponding to our User Profile Property has been created successfully or not

Find the Crawled Property by entering Search Term in Crawled Properties Textbox and click on the Image button with Green Arrow image.

Make sure you should be able to see the Crawled Property which is created during the Full Crawl Process as shown below

19

New we need to create a new Managed Property and Map it with the crawled property shown in earlier step

Click on Managed Properties Link

Click on New Managed Property Link

20

Enter Name, Description, Data Type for the Managed Property

21

Select Searchable, Queryable, Retrievable, Sortable, Refinable and Safe as appropriate

22

23

Click on Add Mapping Button

24

On the Crawled Property Selection Screen

  1. Enter Property Name
  2. Click Find Button
  3. Select appropriate Crawled Property
  4. Click OK

25

Save the Managed Property Definition

26

In order to verify newly Created Managed Property

  1. Enter Property Name
  2. Click Image Button

You should be able to see Managed Property with all the settings you specified earlier.

27

With this we are done with the creation of require Managed Property corresponding to the Crawled Property

Start Full Crawl of Content Source for the User Profiles

Now in order to fill the Managed property with the value stored with in Crawled Property based on the mapping, we need to run the Full Crawl again as we did before.

28

Create Display Template

Once we are done with the Creation and Configuration of required Managed Property, it is time now to create a new Display Template which will include this Managed Property

We need to launch Design Manager from the Standard Menu as shown below

29

Click on Upload Design Files

30

Click on Location URL as shown below

31

Click on Display Templates Folder

32

Click on Search Folder

33

Since we need to modify the template for People Search Results, we need to modify the template Item_Person

34

Point of Caution: As a part of recommended SharePoint Practices, we should never edit and existing template, instead we should make a copy of it, rename it and then modify it as per our needs.

35

Open the Item_Person_LinkedIn Template file and make the following modifications

  1. Change the Title
  2. Added the Managed Property we created in earlier steps

36

Now you need to decide where exactly you want to place this Managed Property within the Display Template.

In our case I am going to place this below User Name

Find the Html Tag NameValue

Below this tag add the following code as shown below

  1. Check if LinkedInProfileUrl Managed Property is not Empty
  2. Add HTML snippet to display the value stored in LinkedInProfileUrl Managed Property
  3. Close the IF block

37

Save the file and copy it back to the same location

38

SharePoint generates a JS File corresponding to this HTML file automatically, and the JS file should not be modified by the users. This JS file will be maintained and modified by SharePoint system automatically based on the changes you have made in HTML File.

39

With this we are done with the development of new Display Template.

Create Result Type with Custom Display Template

Now the next step is to create a new Result Type, which will be using our new Display Template to display the Search Results

Go to Site Settings

40

Click on Result Types

41

Click on New Result Type

42

  1. Provide Name to the Result Type
  2. Select Result Source
  3. Select Display Template (the one we have just created)
  4. Save Result Type

43

44

We can see the newly created Result Type on Manage Result Type Page as shown below

45

With this we are all done with development of new Display Template, it is time to test it now.

Test Display Template

Search for the Users and sure enough you will find the new Property appears only for those User Profiles which contains a non-empty value for LinkedIn URL Property.

46

From the above walkthrough we can conclude the fact that Display Templates are simple but really powerfull mode of customizing Search Result Page as per custom needs.

Hope this help someone in need…

SharePoint 2013: How To Create Custom Search Verticals

What are Search Verticals:

In SharePoint 2013 Search Vertical are displayed in the Search Navigation Web Part on Search Center. SharePoint 2013 Provides us four Search Verticals OOTB namely Everything, People, Conversation, Videos. Each of these verticals mapped to a specific page to display the results returned by the queries and when Search Users click on any of these verticals they are navigating to the respective mapped pages with the vertical they clicked on.

3

For example: Search Vertical Everything uses Results.aspx page to display the results returned by the query. In the similar fashion People vertical uses PeopleResults.aspx, Conversation vertical uses ConversationResults.aspx, Video vertical uses VideoResults.aspx.

All these pages used by the different Search Verticals can be located under Page Library on Search Center Site

1

Each of these vertical pages uses following four Web Parts to render results returned by the user queries:

  1. Refinement Web Part
  2. Search Box Web Part
  3. Search Navigation Web Part
  4. Search Results Web Part

2

I hope by now you got a fairly good idea on “What are Search Verticals?”

In this article we are going to create new Search Vertical for our Search Center that will be showing all the documents (Only Documents) Authored or Co-Authored by me.

Business Scenario:

  1. Search must be able to show all the documents Authored or Co-Authored by me
  2. All the search results must be shown under different vertical on the Search Center
  3. Only documents must be included in the search results

Prerequisites:

  1. Search Service Application Instance must be created and configured
  2. Content Sources must be created as required
  3. Full Crawl must be executed once at least on each of the Content Source
  4. Search Center Site must be created & configured as required

On the similar lines we can create our own Search Verticals.

We need to perform following steps to get a new Search Vertical Up and Running.

  1. Create Result Sources (One per vertical)
  2. Create new Search Vertical page to display results
  3. Configure Search Navigation

We will start our journey by creating the required Result Source for the new search vertical

Go to Site Settings

4

Go to Search >> Result Sources

5

Create new Result Source by clicking New Result Source link

6

Enter Name and Description.

Choose Local SharePoint as Protocol

Click in Launch Query Builder Button to launch Query Builder screen where we can specify the relevant query for the Result Source

7

8

Choose Property Filter as needed, based on the business scenario we have we will choose Property Filter as Author and Value as Name of the user who run the query then Property Filter as IsDocument and Value as 1.

Setting IsDocument Property Filter to 1 is a must if you want to display only documents as the part of the search results for this newly created vertical.

9

Click Add property filter Button to add the properties to the Query Text.

Once we are done with configuring the Query we need to test the Query by clicking Test Query Button

Search Result Preview Panel on the left will display all the results returned by the query we just configured.

10

Click OK

11

With this we are done with the creation of Result Source for the new Search Vertical

Now we will create new Search Vertical Page to display results retuned by the Result Source that we have just created.

Go to Site Contents

12

Go to Pages Library

13

Click new item or Go to Files Tab >> New Document

Choose Page Template to create a new Search Page

14

15

Once the page is added, Edit the page

16

Locate Search Results Web Part and edit its properties

17

18

In Web Part Properties click on Change Query Button to launch a query builder

19

Choose My Documents Result Source from Select a query Dropdown box

20

Click Test Query Button to test the query translated by the Result Source selected under Select a query

Search Result Preview Panel on the left will display all the results returned by the query we just configured.

With this we are done with creation a new Search Result Page.

It is time now to Configure Search Navigation to include new Search Vertical on the Search Center

Go to Site Settings

Go to Search >> Search Settings

21

Click on Add Link under Configure Search Navigation

22

Enter Title as My Documents

Click on Browse Button

23

Select MyDocuments.aspx Page from Page Library

24

Click OK

This will create a new Search Vertical on the Search Center with name My Documents.

25

26

Finally we need to test this new Search Vertical.

Currently I am logged in as sp\spdeveloper

Go to Search Center

Enter Search Query in our case which is *.pdf to return all the documents with the extension .pdf.

Everything Search Vertical will show all the PDF documents returned by the query

27

But My Document Search Vertical will show only those PDF documents which are Authored or Co-Authored by me

28

29

Creating new Search Verticals can be helpful in the scenarios where business user needs to filter out the results returned by the queries under different names by limiting the results based on the Result Sources.

Hope this will help someone in need.

Sharepoint 2013: How To Develop Custom Search Refiners

There could be scenarios where we need to have additional Search Refiners apart from the refiners provided by SharePoint OOTB.

Business Scenario:

In this article we are going to take care of a scenario where :

  1.  We need to add one additional property to the User’s Profile with the name “Last Company”. This property will contain the name of the User’s Previous Organization.
  2.  This property must be mapped with one of the Term Sets created in Managed Term Store.
  3.  This property must be available as an additional Refiner for the People Search

Prerequisites:

  1. Managed Metadata Service Application Instance must be created & configured.
  2.  User Profile Service Application Instance must be created & configured.
  3.  Search Service Application Instance must be created & configured.
  4.  Content Source must be created for User Profiles. Full crawl must be executed once.
  5. Search Center Site Collection must be created.

Now let’s see Custom Refiners in action.

Go to Central Administration = > Manage Service Application

1
Select Managed Metadata Service Application Instance.

2

SharePoint provides three Terms Sets Department, Job Title, Location which is available OOTB and mapped to User Profile Properties.

3

Now let’s create a new Term Group “Companies”.

Under “Companies” create a new Term Set “My Past Companies”.

Under “My Past Companies” create new Terms as shown below. Each term should represent a single company that can be selected from within User’s Property Page using “Terms Picker”.

4

With this we are done with the Managed Term Store Configuration.

Now it is time to create a new User Property “Last Company” which is mapped to the Term Set “My Past Companies”.

Go to Central Administration = > Manage Service Application

Select User Profile Service Application Instance

5

Go to “Manage User Properties”

6

Click “New Property”

7

Enter Name, Display Name, Type and Choose Term Set as shown below:

8

Scroll down and make sure “Default Privacy Settings” must be set to “Everyone” else Search Crawler won’t be able to crawl this property.

9

Click OK.

This will create a new User Property under Custom Property Section as shown below.

10

Now go to “Manage User Profiles” to modify the User Property Page for the User.

11

Find the User and Edit its profile by selecting “Edit My Profile” from ECB as shown below

12

Scroll down and locate the “Last Company” property.

Enter the company name using “Term Picker” as shown below

13

14

Save and Close the User Property Page by clicking the “Save an Close” button.

15

With this we are all done with the creation and configuration of the Custom User Property.

Now it is time to trigger the Crawl on User Profiles so that this new property gets crawled and available for the search queries.

Go to Central Administration = > Manage Service Application

Select Search Service Application Instance

16

Click on “Content Sources” to open “Manage Content Sources” Page

17

Choose “People Search” Content Source and click “Start Full Crawl” using ECB as shown below:

18

Wait till the Crawl Status is “Idle”.

19

Go to Search Center and Click on “People” Vertical.

Enter Search Term and Click Find Icon

As soon as the Search Results appear we can notice a new Refiner “Last Company” available on the Refiner Panel as shown below:

20

We can easily refine the incoming results by using “Last Company” Refiner as shown below:

21

By this simple walkthrough we can conclude that the capability of creating new Refiners is quite powerful and gives us enormous power to create different kind of refiners based on the incoming result sets.

Hope this will help someone in need…

SharePoint 2013 : How to develop Custom Search Apps Using REST API

In this article we are going to deal with Search Scenarios using enhanced REST API in SharePoint 2013. To make the story more interesting I am going to make use of new App Model offered by SharePoint 2013. Here we will be going to explore SharePoint Hosted App which is one of the three types of Apps offered under SharePoint 2013 App Model. In this article we will cover a simple scenario where we will create a Custom Search (SharePoint Hosted) App based on SharePoint 2013 Search and REST API provided by SharePoint 2013, that will perform search on Crawl Data aggregated by the Search Crawler.

Prerequisites

  1. App Development Environment must be configured properly.
  2. SharePoint 2013 Search Service Application must be created and configured.
  3. Sample Data Sources must be created with in the Scope targeted by the crawler.
  4. Full Crawl must be finished.
  5. Fiddler Web Proxy should be installed. You can get Fiddler from http://www.telerik.com/download/fiddler

Following are the steps involved in the development of Custom Search App using REST API:

Step-1 : Start Visual Studio 2012/2013 and Select “App for SharePoint 2013” project template as shown below

1

Step-2 : Modify the Default.aspx Page and add the UI Elements for Search App. For the sake of simplicity I am using basic HTML for the presentation but we can design the UI as compelling as it needs to be by making use of enhanced UI support from HTML5 & CSS3.

2

Step-3: Next thing is to hook up the “Click” event of the button “btnExecuteSearchREST” with an event handler function as shown below:

3

Step-4:   Now lets’ do the step wise analysis of the actual plumbing

6

  1. Get the Search Term entered by the user and stored it in the variable “queryText”.
  2. Define Request Headers for the Web Request, Please Note that we mention “odata=verbose” as a part of the value for “Accept” Property, this is a new convention for Web Requests using REST API in SharePoint 2013 and it must be followed else it would produce the following error :

4

  1. Set “url” property to the URL of the site which is hosting this App using “_spPageContextInfo.webAbsoluteUrl”, you must have to memorize this object as you have to use it on every single page in SharePoint where you want to use the SharePoint Context. This simple object provides you a lot of useful information to work on as shown below

5

  1. Specify the Search Query using new End Point (_api/search/query/<searchTerm>) provided by SharePoint 2013.
  2. Read the results from the response object and save it to “rows” variable, based on the data structure returned by the response object. We can identify the data structure by analyzing the response object using Fiddler Web Proxy as shown after few steps down the line.
  3. We need to loop through the result set to read the Values based on the Keys returned.
  4. Lastly we need to display the records as required.

Optional: At this point you can make use of some of the JavaScript Frameworks like “Knockout.js” which is based on MVVM Pattern and has an excellent feature of dependency tracking, which allows you to write complex UI logic with much Lesser & Cleaner Code. You can learn Knockout very easily by following the link http://learn.knockoutjs.com/.

Step-5: With this we are all done with the code, now it’s time to build & deploy the App and see it in action. In order to test the Custom Search App, first verify the Data Source which contains the data related to our search term. In our case it is “Customers” List with a Column “ContactTitle” containing the Search Term “Owner” as shown below

7

Now specify the search term in textbox provided as a part of App UI and click “Execute Search using REST API” as shown below:

8

Before going to the search result in the “Result Panel” (which is a div on App UI), we should spend a few minutes to analyze the response object to determine what exactly is returning from the server against our request. If we view the response object in Fiddler as shown below, we will see a complete JSON Object containing the data in terms of Key/Value Pairs. This information is very important as this will help us to navigate the result set that we are interested in. Please Note that we utilize this information under Step-4 Point 5, where we are saving the result set from response object to local variable.

9

10

Finally if we see to the Result Panel we should be able to get the results based on the search term “Owner”.

11

This simple demo helps you to grasp the notion of how can we employ REST API while working with Custom Search Apps/Solutions.

Hope this will help someone in need…