Dev / Test

Juan Carlos

How To Import Search Query Suggestions using PowerShell!

July 6th, 2014 | Author: | Filed under: CloudShare, Demos & POCs, Dev / Test, SharePoint, Training | Tags: , ,


Undoubtedly, SharePoint search is one of the most powerful features available in the platform not only for the out of the box features but also for the multiple extensibility points provided. In this post we will see how we can improve the search user experience through search query suggestions imported in SharePoint using the power provided by PowerShell.

  • Before going ahead with all the PowerShell staff, we need to define a file with all the query suggestions we want to add to the SharePoint Search. In my case, I have created a simple text file with all these suggestions. As you can see in the file structure, I’m using the QuerySuggestion term as a header in order to simplify the data processing required to extract each suggestion from the file.

image

  • Once we have ready the query suggestions, we need to define the PowerShell code that will import them in the SharePoint Search. This script, which is ready from download in How to import search query suggestions to the SharePoint Search, uses the cmdlet New-SPEnterpriseSearchLanguageResourcePhrase to add each Query Suggestion in a specific Scope (Search Service Application, Site Collection or Site). Finally, in order to provide the query suggestions to final users it’s required to execute the “Prepare query suggestions” Timer Job.

####################################################

# Script that allows to import query suggestions to the SharePoint Search.
# Required Parameters:
#    ->$sInputfile: Query suggestions file.
#    ->$sLanguage: Language for the Query Suggestions.
####################################################

If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{ Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell }

$host.Runspace.ThreadOptions = “ReuseThread”

#Definition of the function that imports new query suggestions to SharePoint
function Import-QuerySuggestions
{
param ($sInpuntFile,$sLanguage)
try
{
Write-Host “Importing Query Suggestions..” -ForegroundColor Green
#Checking if the query suggestions file exists
$bFileExists = (Test-Path $sInputFile -PathType Leaf)
if ($bFileExists) {
“Loading $sInputFile for processing…”
$tblData = Import-CSV $sInputFile
} else {
Write-Host “File $sInputFile not found. Stopping the Import Process!” -foregroundcolor Red
exit
}

$ssaSearchApp = Get-SPEnterpriseSearchServiceApplication -Identity “Search Service App”
$spSearchOwner = Get-SPEnterpriseSearchOwner -Level SSA

#Processing the file data
foreach ($row in $tblData){
$sQuerySuggestion=$row.QuerySuggestion.ToString()
Write-Host “Adding $sQuerySuggestion as a Query Suggestion”
New-SPEnterpriseSearchLanguageResourcePhrase -SearchApplication  $ssaSearchApp -Language $sLanguage -Type QuerySuggestionAlwaysSuggest -Name $sQuerySuggestion -Owner $spSearchOwner
}

#Starting the Timer Job that makes available new query suggestions
$qsTimerJob = Get-SPTimerJob -type “Microsoft.Office.Server.Search.Administration.PrepareQuerySuggestionsJobDefinition”
Write-Host “Starting ” $qsTimerJob.Name ” Timber Job” -ForegroundColor Green
$qsTimerJob.RunNow()
Write-Host “Query Suggestions successfully imported!!” -ForegroundColor Green

}
catch [System.Exception]
{
write-host -f red $_.Exception.ToString()
}
}

Start-SPAssignment –Global
#Archivo con los Usuarios
$ScriptDir = Split-Path -parent $MyInvocation.MyCommand.Path
$sInputFile=$ScriptDir+ “\QuerySuggestions_Madrid.txt”
$sLanguage=”ES-es”
Import-QuerySuggestions -sInpuntFile $sInputFile -sLanguage $sLanguage
Stop-SPAssignment –Global

Remove-PSSnapin Microsoft.SharePoint.PowerShell

image

  • Of course, you can verify that all the query suggestions has been imported using again the magic and power of Windows PowerShell. In this case, I have prepared a small script that you can get again in the TechNet Script Gallery (How to get all query suggestions defined in a SharePoint Farm!. As you can see in the script, you only need to properly call the Get-SPEnterpriseSearchQueryCantidates in order to get all query suggestions available in the SharePoint farm.

###################################################

# Script that allows to get all the query suggestions already defined in a SharePoint farm.
####################################################

If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{ Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell }

$host.Runspace.ThreadOptions = “ReuseThread”

#Definition of the function that gets current query suggestions in the SharePoint farm
function Get-QuerySuggestions
{
try
{
Write-Host “Getting all the query suggestions…” -ForegroundColor Green
$ssaSearchApp = Get-SPEnterpriseSearchServiceApplication -Identity “Search Service App”
$spSearchOwner = Get-SPEnterpriseSearchOwner -Level SSA
Get-SPEnterpriseSearchQuerySuggestionCandidates -SearchApplication $ssaSearchApp -Owner $spSearchOwner
}
catch [System.Exception]
{
write-host -f red $_.Exception.ToString()
}
}

Start-SPAssignment –Global
Get-QuerySuggestions
Stop-SPAssignment –Global

Remove-PSSnapin Microsoft.SharePoint.PowerShell

image

  • Finally, just verify your query suggestions are ready to use in a SharePoint Search Center.

image

And that’s all about how to import Search Query Suggestions to SharePoint using PowerShell. Happy CloudSharing!


Daniel Bakshi

Want to know how vagrant radically improves integration tests?

June 29th, 2014 | Author: | Filed under: CloudShare, Dev / Test | Tags: , , , , , ,


CloudShare’s Dev team leader with the answer.

Checkout this neat article:

http://techblog.cld.sr/?p=111

[Promo  Code - vagrant]


Juan Carlos

How to determine the size of the SharePoint Content DBs in a SharePoint Farm!

June 20th, 2014 | Author: | Filed under: CloudShare, Demos & POCs, Dev / Test, SharePoint, Training | Tags: ,


One of the most common administration tasks when managing a SharePoint environment is to have under control the sizes of the SharePoint content databases available in a SharePoint farm. Although there are several possibilities to get this information, I recommend you to use Windows PowerShell so you can take advantage of the features and great capabilities it provides when doing SharePoint administration task. As you will learn in this article, you can easily get the size for your SharePoint Content Databases by means of a PowerShell Script.

Read the rest of this entry »


Chris Riley

We are developers too!

June 17th, 2014 | Author: | Filed under: CloudShare, Demos & POCs, Dev / Test | Tags: , , ,


CloudShare is a tool that many developers have made apart of their day-to-day work. And that platform has to be built just like any other application.  Our awesome team of developers faces the same processes and challenges that the entire development world does, and they want to share their story with you.

Read the rest of this entry »


Juan Carlos

How to execute PowerShell scripts and cmdlets in Visual Studio!

May 22nd, 2014 | Author: | Filed under: Dev / Test, SharePoint | Tags: , ,


As SharePoint developers, sometimes we need to do some IT Pro stuff such as creating a PowerShell Scripts for doing common tasks: deploying .WSP solutions to the farm, create some auxiliary lists, etc. In order to create and execute these scripts you can use the SharePoint 2013 Management Console or the Microsoft ISE (Integrated Shell Script Environment) as your scripting tools. However, most of the time we are using Visual Studio for our programming stuff and we don’t feel happy switching from Visual Studio to the scripting tool we have chosen…so the question around the corner is if there is a way to execute PowerShell Scripts in our favorite development tool.

Read the rest of this entry »


Juan Carlos

SharePoint 2013 and Yammer Integration Features in the Service Pack 1

April 26th, 2014 | Author: | Filed under: CloudShare, Demos & POCs, Dev / Test, SharePoint | Tags: , ,


After some weeks where I guess SharePoint team has been very busy, we can finally say that the “real and definitive” service pack (SP) 1 for SharePoint 2013 has just arrived and it’s ready to download and install on your SharePoint deployments (Note: For your reference, I recommend you to read Stefan Goßner ’s blog post about the re-release of SharePoint 2013 SP 1. In this article I will show you one of the enhancements included as part of the SharePoint 2013 SP 1: a first integration approach between SharePoint 2013 and Yammer. Indeed, SharePoint 2013 included a first approach to real hybrid solutions where we will have out of the box the possibility of using on-premises and Office 365 features.

Read the rest of this entry »


Juan Carlos

How to hide the SharePoint 2013 Ribbon programmatically!

April 15th, 2014 | Author: | Filed under: Dev / Test, SharePoint | Tags: , , , ,


This time I want to share with you some tips about how to hide the SharePoint 2010 / 2013 Ribbon programmatically.

Read the rest of this entry »


Scott Petri

Controlling your Costs with Environment Policies

April 14th, 2014 | Author: | Filed under: CloudShare, Demos & POCs, Dev / Test | Tags: , , , , , ,


Managing policies …and your usage …and your costs …and how it all adds up sounds super dull, right? And it is.

That is, until it isn’t. Have you ever had to experienced the feeling of going to your boss or any other financial controller in your company with an unexpected bill? And that bill happened to be larger than you could have imagined? It’s a long walk to their office isn’t it? Well, we don’t want you to experience that, ever!

Read the rest of this entry »


Chris Riley

Using Cloud Orchestration to Respond Quickly to Heartbleed

April 11th, 2014 | Author: | Filed under: Dev / Test | Tags: , , , , , , , ,


I wish I could say I found out about the Heartbleed bug very quickly and from some super deep technical source.  But I didn’t.  I found it on my favorite Tmblr blog, filled with animated gifs about DevOps that gets me through the day. And once I realized what this particular Gif was telling me, I too was in a small state of shock.

Read the rest of this entry »


Chris Riley

If you build it they will …. Find Bugs?

April 8th, 2014 | Author: | Filed under: Dev / Test | Tags: , , , , , , ,


Last week CloudShare joined the 2014 Build Conference in San Francisco.  If you have never been to the conference, I recommend it.  It is a great way for developers to find out what is new in the Microsoft Dev Tools world, meet with Peers to solve real world problems, and get up to speed on modern day trends.  Like one of this years themes, DevOps.

Read the rest of this entry »