Add Site Title in the Search Filters

In this article I will be covering the process of adding Sites’ Title in the Search Filter of a SharePoint 2013/2016 site. A client I am currently working with has a dozen of what they call “legacy” sites. They went ahead and created a dedicated Result Source to allow people in their organization to search only for content stored in these sites. What they want, is for a new “Site Title” section to show up under this ResultSource to allow people to filter their search result based on a specific site.

Scenario

The SharePoint site has a wildcard managed path named “Legacy” and has 3 site collections created:

  • /legacy/HR
  • /legacy/Finances
  • /legacy/Communications

I have a Search Center created at /sites/Search, and a Result Source defined within it that only search content of sites located under the Legacy managed path

Process

Create a New Managed Property

By default, searching for documents inside the Legacy Result Source will only provide me with the Time Range slider and Author list as Filters (see Figure below).

In order for us to add sites’ title as a filter, we first need to ensure it has an associated Search Managed Property. To do so, navigate to your Search Service Application in Central Administration and select Search Sources from the left navigation.

SharePoint Search Schema

SharePoint Search Schema

Once in there, search for a RefinableString property that is not yet mapped to any crawled properties. In my case, I will select RefinableString00.

On the managed property edit page, scroll to the bottom of the page, to the Mappings to crawled properties section. Click on Add a mapping.

On the Crawled property selection, search for and select the ows_SiteName property.

Back on the managed property screen, click OK to save the mapping. go back to the Search Administration page and initiate a Full Crawl of you content.

Configure the Filter Panel

Now that the information about our sites’ titles is available as a managed property within Search, we can go ahead and update the refinement (filter) webpart on our Legacy search page to include it as a refiner. To do so, navigate to your search page and edit the page. Click on the Refinement web part and select Edit Web Part.

In the Refinement properties panel on the right hand side, click on Choose Refiners….

In the Available refiners section, find the Refinablestring00 property we just modified, and click on Add > to add it to the Selected refiners section on the right. Once that is done, Change its Display name to Site Title and click OK.

Click OK in the web part properties panel on the right, and save (or check-in) your page. You should now be able to use your new refiner as shown in the Figure below.

Can’t Create a SharePoint Publishing Catalog Connection

I encountered a weird issue while working at a client’s site this week, where we were trying to update the catalog url of some SharePoint Publishing Catalog Connections after we restored the content database from a different farm. The client in question has three SharePoint environments: a Dev one, a Quality Assurance (QA) one and off course, a Production one. Each of these environments had been given a different url. Ex:

Development http://dev.sharepoint.contoso.com
Quality Assurance http://qa.sharepoint.contoso.com
Production http://prod.sharepoint.contoso.com

The client’s SharePoint environment is entirely based on Cross-Site Publishing to display content. They wanted to refresh their Dev environment with a copy of the content from production. So we went ahead and proceeded to refreshing their content database and their Managed Metadata Service database. Because the content was taken from a different environment, the Catalog connections listed still exhibited a Url that pointed to http://prod.sharepoint.contoso.com, so we needed to change this to reflect the dev url.

Connections

So to keep things simple, we decided to simply go and delete all existing Connections, and recreate them using PowerShell, but this time having them pointing to the dev.sharepoint.contoso.com url. Upon executing our PowerShell we got the following weird error:

Exception calling “Update” with “0” argument(s): “The object you are trying to create or modify has the same name as another object.

This error seemed to indicate that somehow there was already a catalog connection that existed and that had the same name as the one we were trying to create. However, there were no connections showing up on the Manage Connection page.

One thing I’ve learned from troubleshooting this issue is that SharePoint automatically creates a Search Results Source for every Catalog Connection you define. These Result Sources will be given the name of your Catalog Connection, followed by the word “Results”.
ResultSources

Normally, if you delete a catalog connection, its associated Result Source is also automatically deleted. However, in our case, when we brought back a copy of the production database, somehow a link got broken in the background, and when we deleted the Catalog Connection, the Result Source was still existing. So the solution to our problem was to go ahead and to delete the orphan Result Source at the Site Collection level using PowerShell.

$site = Get-SPSite "http://dev.contoso.com/"
$ssa = Get-SPEnterpriseSearchServiceApplication;
[void][Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.Search")
  
$fedManager = New-Object Microsoft.Office.Server.Search.Administration.Query.FederationManager($ssa)
$owner = New-Object Microsoft.Office.Server.Search.Administration.SearchObjectOwner([Microsoft.Office.Server.Search.Administration.SearchObjectLevel]::SPSite, $site.RootWeb)
$resultSource = $fedManager.GetSourceByName("Home - Products Results",$owner)
$fedManager.RemoveSource($resultSource)

* Credits for this PowerShell snippet goes to Sathish Nadarajan

Once the Result Source was properly deleted, we managed to execute our PowerShell to recreate the Catalog Connections without a problem.

Creating Custom Search Refiners in Office 365 using Term Sets

In this article we will cover how you can, in Office 365, create a custom column on a Document Library and use its values to define additional refiners in your search results. The idea for this blog post came after a client engagement of mine, where the organization I was working with wanted to tag their documents with a new managed metadata column named “Branch” which contained the name of the branch within their organization that was the owner of the document.

Step 1 – Define your Term Set
a) Navigate to the Office 365 Admin Center
Waffle

b) Navigate to the SharePoint Online Admin Center
SPAdminCenter

c) Navigate to the Term Store page
termstore

d) Click on the Taxonomy Home, and select New Group
NewGroup

e) Name your new group “Organization”
OrgTermMMS

f) Create a new term set and name it “Branches”
NewTermSet

g) Under the newly created “Branches” term set, enter several terms that would represent the names of the various branches in your organization
Branches

Step 2 – Create the new column in your Document Library
a) Create a new document library in any of your SharePoint Online sites and name it “Important Documents”
ImportantDocs

b) From the View All Site Contents page, click on the “…” icon for the newly created document library and click on Settings
ImpDocsSettings

c) Scroll down on the document library settings page and click on the “Create column” link
Createcolumn

d) Name the new column “Branch” and set its type to “Managed Metadata”
BranchField

e) Scroll down to the “Term Set Settings” section on the new column page. In the Term Picker window, navigate to the “Branches” term set we created at step 1-f above. Select it, and click ok to create the new column.
SelectFieldMMS

f) Upload a new document into the newly created “Important Documents” Library, and set it “Branch” value. In my case I assigned it the value “Finance”.
SetBranch

Step 3 – Wait for the SharePoint Online Search to pick up our value
a) The SharePoint Online Search engine is set to Continuous crawl by default. The new column should be picked up within the next 15 to 60 minutes, and since our column is of type “Managed Metadata”, the search engine will automatically create a managed property and associate it with the automaticaly generated crawled property. Wait for the indexer to pick up our new column.

4 – Map the “Branch” Crawled Property to a Refinable Managed Property
a) Navigate back to the SharePoint Online Admin Center (see step 1-b above);
b) Navigate to the Search Schema page
ManageSchema
c) Confirm that the Crawled property was automatically created. In the top navigation bar, click on the “Crawled Properties” link.
CarledPropButton
d) In the Filters section, within the “Crawled properties” textbox, type in “Branch” and click on the green arrow button. You should see that you have at least 3 results coming back. If you do, then that means that the search indexer managed to automatically crawl your new column.
crawledresults
e) In the top navigation, click on the “Managed Properties” link
ManagedPropButton
f) In the ‘Managed property” textbox enter “RefinableString00” and click on the green arrow button. You should have only one result back
refinablestringfound
g) In this article, we will be re-using a predefined refinable managed property to map to our newly created crawled property. By default, SharePoint online defined 100 refinable “text” properties (RefinableString00 to RefinableString99). These are not mapped to any crawled properties by default.
Click on the arrow beside the RefinableString00 result, and select “Edit/Map Property”
EditMapProp
h) On the next page, scroll down to the “Mappings to crawled properties” section near the bottom. Click on the “Add Mapping” button.
AddMapping
i) We now need to map it to our automatically created crawled property. In the “Search for a crawled property name:” textbox enter “Branch” and click on the “Find” button. The 3 results we got at step 4-d should be returned
3results
j) The property we are interested in here is the one that is formatted like “ows_” (in my case ows_Branch). Select the property from the list by clicking on it, scroll to the bottom of the dialog window and click on “OK”.
selectCrawledProper
k) Once the dialog Windows closes, scroll down to the bottom of the page and click on “OK”. We now have a refinable managed property that is mapped to our crawled property Branch. We are now ready to go and use this refinable property as a refiner on our search page.
5 – Modify the Search Results Page to Include our Refiner
a) Navigate back to your search center. Please note that page to be editable, you need to create your own Enterprise Search center. By default SharePoint Online creates one at https://.SharePoint.com/Search. If you navigate to your search page and don’t see the option to edit the page (assuming you should have the proper rights to edit it) it is most likely because you are trying to edit the default SharePoint OSSSearch page. This page is not customizable, and you should make sure you have a proper Enterprise Search site created. To figure out if the search page you are looking at is the OSSSearch page, simply have a look at the URL. If it looks like the following: https:.sharepoint.com/_layouts/15/osssearchresults.aspx, then you search is not pointing to a customized Search center and you will not be able to edit that page.

Assuming you are all good to go and have created your own Enterprise search center, navigate to the search result page, and edit the page.
EditPage
b) in the left web part zone, find the the “Refiner” web part. Put your mouse over the top right corner of the web part, click on the downward arrow icon and select “Edit Web Part” from the menu.
EditWebPart
c) The web part property panel will appear on the right hand side of the page. From there, take a look at the “Properties for Search Refinement” section. Make sure the “Choose refiners in the Web Part” radio button is selected and click on the “Choose Refiners…” button.
chooserefiner
d) From the list of available Managed properties in the left column, find the “RefinableString00” property we just mapped to our “Branch” column. Click on it to select it in the left column and click on the “Add” button to have it added to the list of active refiners in the right column.
PickedRefiner
e) In the Configuration section at the bottom of the dialog window, enter a friendly display name for the property (otheriwse it will show up as RefinableString00 to the users). In the “Display Name” textbox, enter your friendly name (in my case “Branch”).
DisplayNameforRefinable
f) Scroll down to the bottom of the current dialog box and click on the “OK” button.
g) In the Web Part properties panel on the right, click on the “OK” button.
WPOk
h) In the ribbon at the top of the page, click on the “Save” button.
SavePageAftermodif
6 – Perform a Search
a) After completing section 5 above and clicking the “Save” button on the Search Results page, you should be back on the results page. In the Search textbox at the top of the page, enter a keyword that will allow you to retrieve the document we uploaded at step 2-f. In my case, I will search for keyword “Financial”. enter the search keyword in the textbox and click on the maginfying glass icon to the right of it.
FinancialSearch
b) Once the results come back you should be able to see your newly added refiner in the left column
searchresultfound

Voilà! We managed to create a new column and configure it as a refiner for users, improving their search experience and allowing them to easily find the documents they were looking for!

Get Search Results in SharePoint 2013 using PowerShell

I’ve started playing with some of the search APIs in SharePoint 2013 lately, and wanted to transpose my experiments into PowerShell to see just how easy it was to do. I have been developping a C# client that runs directly on the server, prompts the user to enter a keyword and lists all search results received back from the SharePoint Search Service Application. I managed to replicate this client application in PowerShell by creating a 10 lines script. I basically converted over the C# code into PowerShell.

Before getting started, we need to make sure we load the Microsoft.Office.Server.Search.Query Assembly within our PowerShell session. Our code will by using objects from that namespace.

[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.Office.Server.Search.Query”)

My code uses the Microsoft.Office.Server.Search.Query.KeywordQuery object to retrieve search results back. This object takes in a reference to a Site Collection to perform the search against.

$site = Get-SPSite http://localhost

$keywordQuery = New-Object Microsoft.Office.Server.Search.Query.KeywordQuery($site)

Next step is to prompt the user to input a keyword for the search results. Once obtained, we will assign this keyword to QueryText property our newly created KeywordQuery object.

$keyword = Read-Host “Search Term”

$keywordQuery.QueryText = $keyword

We now have an object that represent our query to send to the server, but in order to execute this Query, we need to instantiate a second object, the Microsoft.Office.Server.Search.Query.SearchExecutor. This object exposes a method name ExecuteQuery() to which we wil pass our query object in order to get search results back.

$searchExec = New-Object Microsoft.Office.Server.Search.Query.SearchExecutor

$searchResults = $searchExec.ExecuteQuery($keywordQuery)

The last step for us is to look at the Table property of the returned object in order to get a list of items that have been identified as matching our search criterias. For clarity’s sake, we will only be exposing the Title, Path, Author, LastModifiedTime and IsDocument property of each search result.

$table = $searchResults.Table

$table | Select Title, Path, Author, LastModifiedTime, IsDocument

So to prove that my code works, I will execute a search using the SharePoint Search interface, search for the word “Gadgets”. Here is what the interface returns for results.

20150110.png

We can see from the screenshot above that search for the word “Gadgets” returns 2 results. Now, let us put our PowerShell script together:

[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.Office.Server.Search.Query”)
Write-Host “`r`n”

$site = Get-SPSite http://localhost
$keywordQuery = New-Object Microsoft.Office.Server.Search.Query.KeywordQuery($site)
$keyword = Read-Host “Search Term”
$keywordQuery.QueryText = $keyword
$searchExec = New-Object Microsoft.Office.Server.Search.Query.SearchExecutor
$searchResults = $searchExec.ExecuteQuery($keywordQuery)

Write-Host “`r`n”
$table = $searchResults.Table
Write-Host $table.Length” Results Found” -BackgroundColor “Green” -ForegroundColor “Black”
$table | select Title, Path, Author, LastModifiedTime, IsDocument

Now, if we were to execute the above PowerShell script against my local SharePoint farm, here is what the result would look like:

2015011002.png

We have therefore been able to obtain the exact same results for our SharePoint 2013 Search Web interface compared with our PowerShell version. This is a neat little script that could prove to be very useful in many scenarios.