FAST Search for SharePoint 2010 – Using PowerShell to execute searches.
In some cases, you may want to test query results and there is a relatively easy way to do using PowerShell.
General steps are:
1) Pass the site URL to the Search object
2) Pass the QueryText (the query that you want to test)
3) Set search parameters
4) Execute query and format the results
Here is the code:
1: #load the site and set the keyword query object
2: $searchSite = Get-SPSite http://www.sathishtk.com
3: $keywordQuery = New-Object Microsoft.Office.Server.Search.Query.KeywordQuery $searchSite
4: $keywordQuery.ResultTypes = [Microsoft.Office.Server.Search.Query.ResultType]::RelevantResults
5: # activate FQL queries
6: $keywordQuery.EnableFQL = 1
7: $keywordQuery.RowLimit = 10
8: #Pass the query text - SharePoint
9: $keywordQuery.QueryText = "SharePoint"
10: #query execution
11: $results = $keywordQuery.Execute()
12: #display total number of rows
13: Write-Host Total hits: $results[1].TotalRows
14: $resultsTable = $results.Item([Microsoft.Office.Server.Search.Query.ResultType]::RelevantResults)
15: $resultsDataTable = $resultsTable.Table
16: # display the results in table format for better view
17: $resultsDataTable | Format-Table -AutoSize -Property title, url