Dienstag, 29. November 2011

Session stuff: Unleash the Power of SharePoint Search with Powershell

Here are the scripts from my PowerShell session at Collaboration Day 2011….:

#Unterschiede zwischen Search und FAST cmdlets:
get-help get-FASTSearchMetadataManagedProperty -examples
get-help get-SPEnterpriseSearchMetadataManagedProperty -examples

#Überblick verschaffen mit:
Get-SPSearchService | select *
Get-SPSearchServiceInstance | select *

#Ping the Search / FAST mit (Send a request to the default content distributor): 
Ping-SPEnterpriseSearchContentService -HostName "demo2010a.contoso.com"

#Übersicht über alle Search Applications:
Get-SPEnterpriseSearchServiceApplication

#Properties mappen
Get-FASTSearchMetadataCrawledProperty -filter VorAngelegtVon
Get-FASTSearchMetadataManagedProperty -Name Author
#$vm = Get-FASTSearchMetadataManagedProperty -Name Author
#$vc = Get-FASTSearchMetadataCrawledProperty -filter VorAngelegtVon
#New-FASTSearchMetadataCrawledPropertyMapping -Managedproperty $vm crawledproperty $vc
Get-FASTSearchMetadataCrawledPropertyMapping  -name Author
_________________________________________________

#Calling KeywordQuery class
$searchSite = "http://intranet"
$site = New-Object Microsoft.SharePoint.SPSite $searchSite
$vc = New-Object Microsoft.Office.Server.Search.Query.KeywordQuery $site
$vc.ResultsProvider = [Microsoft.Office.Server.Search.Query.SearchProvider]::FASTSearch
$vc.ResultTypes = [Microsoft.Office.Server.Search.Query.ResultType]::RelevantResults
#In my case I enabled the FQL syntax and set some other parameters:
$vc.EnableFQL = $true # enable FQL
$vc.RowLimit = 2 # sets the limit of results
$vc.StartRow = 0 # 0 is the default
#Next step is the query, in my case a simple query searching for the term “backup”
#Query / Result
$vc.QueryText = "backup"
$results = $vc.Execute()
write-host "Ergebiss:" -F blue
$results
#Print out the results details:
#result details
$resultTable = $results.Item([Microsoft.Office.Server.Search.Query.ResultType]::RelevantResults)
$rows = $resultTable.Table.Rows
#And getting the properties of each result:
#Each result with properties
write-host "Details:" -F blue
$rows
#This is just interesting and nice, especially getting all the property from the
#“HitHighlightedSummary” and the “HitHighlighted” Property fields.
 
#finding out with filetyps that are in the resultset and how they are distributed
$searchSite = "http://intranet"
$site = New-Object Microsoft.SharePoint.SPSite $searchSite
$vc = New-Object Microsoft.Office.Server.Search.Query.KeywordQuery $site
$vc.ResultsProvider = [Microsoft.Office.Server.Search.Query.SearchProvider]::FASTSearch
$vc.ResultTypes = [Microsoft.Office.Server.Search.Query.ResultType]::RelevantResults
$vc.RowLimit = 1000
# Query String: the "%%" means to search everything, the "-aspx -bdc3 –file" filters to near only documents
$vc.QueryText = "%% -aspx -bdc3 -file"
$results = $vc.Execute()
$resultTable = $results.Item([Microsoft.Office.Server.Search.Query.ResultType]::RelevantResults)
$rows = $resultTable.Table.Rows
$rows| Group-Object FileExtension| Sort-Object count -descending |Format-Table -AutoSize -Property Name,count
$rows| Measure-Object Size -Average -Sum -Maximum –Minimum
_______________________________________________

Get-FASTSearchMetadataRankProfile
#Neues Rank Profil anlegen um PDF Dokumente höher zu gewichten:
$rp = Get-FASTSearchMetadataRankProfile -name default
$nrp = New-FASTSearchMetadataRankProfile -name pdf -template $rp
$fileext = Get-FASTSearchMetadataManagedProperty -Name fileextension
$nrp.CreateManagedPropertyBoostComponent($fileext, "pdf,-200000")
$nrp.update()
Remove-FASTSearchMetadataRankProfile -name pdf
_______________________________________________

#FullText Index
Get-FASTSearchMetadataFullTextIndex -Name content
Get-SPEnterpriseSearchQueryScope -SearchApplication "FastQuery"
#New-SPEnterpriseSearchQueryScope ..... -ExtendedSearchFilter "FullTextIndex=<FullTextIndex>".....
any further question etc.... just mail....

Sonntag, 20. November 2011

Query Search (FAST) with PowerShell

A nice and easy way to send queries to you SharePoint Search Server (in this example FAST Search Server) using PowerShell. Of cause this is not an option getting results to work with if your scope is the content. But it is a very useful way getting statistics, summaries etc, Have a look at some property details or something else.
First we have to do is calling the needed .net class and create an object based on it:
#Calling KeywordQuery class
$searchSite = "http://intranet"
$site = New-Object Microsoft.SharePoint.SPSite $searchSite
$vc =
New-Object Microsoft.Office.Server.Search.Query.KeywordQuery $site
$vc.ResultsProvider = [Microsoft.Office.Server.Search.Query.SearchProvider]::FASTSearch
$vc.ResultTypes = [Microsoft.Office.Server.Search.Query.ResultType]::RelevantResults
In my case I enabled the FQL syntax and set some other parameters:
$vc.EnableFQL = $true # enable FQL
$vc.RowLimit = 2 # sets the limit of results
$vc.StartRow = 0 # 0 is the default

Next step is the query, in my case a simple query searching for the term “backup”

#Query / Result
$vc.QueryText = "backup"
$results = $vc.Execute()
write-host "Ergebiss:"  -F red
$results

Print out the results details:

#result details
$resultTable = $results.Item([Microsoft.Office.Server.Search.Query.ResultType]::RelevantResults)
$rows = $resultTable.Table.Rows

And getting the properties of each result:

#Each result with properties
write-host "Details:"  -F red
$rows

This is just interesting and nice, especially getting all the property from the “HitHighlightedSummary” and the “HitHighlighted” Property fields. But bases on this script, you can also do some other useful things, for example: finding out with filetyps that are in the resultset and how they are distributed

$searchSite = "http://intranet"
$site = New-Object Microsoft.SharePoint.SPSite $searchSite
$vc =
New-Object Microsoft.Office.Server.Search.Query.KeywordQuery $site
$vc.ResultsProvider = [Microsoft.Office.Server.Search.Query.SearchProvider]::FASTSearch
$vc.ResultTypes = [Microsoft.Office.Server.Search.Query.ResultType]::RelevantResults
$vc.RowLimit = 1000
# Query String: the "%%" means to search everything, the "-aspx -bdc3 –file" filters to near only documents
$vc.QueryText = "%% -aspx -bdc3 -file"
$results = $vc.Execute()
$resultTable = $results.Item([Microsoft.Office.Server.Search.Query.ResultType]::RelevantResults)
$rows = $resultTable.Table.Rows
$rows| Group-Object FileExtension| Sort-Object count -descending |Format-Table -AutoSize -Property Name,count,Size
$rows| Measure-Object Size  -Average -Sum -Maximum –Minimum

Output looks like:

Name    Count
----    -----
HTML       53
DOC        42
DOCX       20
XLSX       12
PPTX       10
PPSDC       4
VDW         3
XAP         2
XLS         2
ONETOC2     2
XML         2
VSD         2
TXT         1
            1
ONE         1


Count    : 157
Average  : 201299,133757962
Sum      : 31603964
Maximum  : 9711217
Minimum  : 0
Property : Size

Be careful with the “$vc.RowLimit” parameter, just getting the first 1000 or let’s say 10000 entities gives you a good overview and won’t stress you SearchServer too much…
Have fun playing around with it.

PS: Script based on a post from Harald S. Fianbakken, I corrected some syntax error and add some own ideas etc…

Montag, 10. Oktober 2011

Using custom fields in search results

Find out the given internal name of the custom field....
SharePoint search crawler identifies automatically all fields in a given contend source. This will work for all contend types the SharePoint search server can handle per default or an Ifiler is installed. Of cause SharePoint user defined fields in lists or document libraries are crawled.
There is an MSDN article that describes how to use custom fields in core search result webpart: LINK. It’s just an easy doing, you have to put you custom field to the field list in the Display Properties node of the search results webparts and modify the XSLT transformation (XSLT) to display the custom property. Details see the link above.
But there a two little catches: first is that you have to map the crawled property that includes your customer field to a managed property to use it in search results. But that’s not a real big thing. You can do this using PowerShell or via SharePoint central admin. For example see my post: Bring up crawled contend to the user or this MSDN article: LINK. But to do this you have to find out which crawled property represents you custom field. For this you have to find out the static name of the field. Of cause there are several ways to reach this goal. I used SharePoint Manager; a free tool you can download from codeplex: LINK.
Open SharePoint Manager on you SharePoint Server, navigate to the list containing your custom field and click the field. In the right section you see the details of the selected field. In the cell static name you will find the value needed:
(this is SharePoint Manager on a SharePoint 2007 Server. It works similar in a SP 2010 environment)
In my demo case the field name is “2011 Fällig” and the static name is “_x0032_011_x002c__x0020_F_x00e4_”
Another way to find out the static name is to analyze the URL. To do this go to list settings -> click on the column name in which you are interested -> on the change column page the URL will ends with the static name:
… 176%7D&Field=%5Fx0032%5F011%5Fx002c%5F%5Fx0020%5FF%5Fx00e4%5F
This will work fine for simple field names, but you see that it can be horrible in case of complex field names.
So know we can use the static name to find out the crawled property. For example via PowerShell. If you use PowerShell it’s important to know, that the system puts an “ows_” to the static name of the field to name the crawled property. So our crawled property looks like “ows__x0032_011_x002c__x0020_F_x00e4_”. The PowerShell call in my demo case is:
Get-SPEnterpriseSearchMetadataCrawledProperty -searchapplication b835108f-5a59-4348-9cfb-c71adc1415b0 -category SharePoint -Name  ows__x0032_011_x002c__x0020_F_x00e4_
Another and of cause in this case easer way is using the search function for crawled properties in the search service administration section:
Now that we have the name of the crawled property containing the contend of the custom list field we can map it to a managed property and use it in SharePoint search for filtering, display it in search core results ore what else…