The POC - Part 2 post was quite underwhelming. The VHD has all the software installed for us and stealing using content off the web was easy enough (well, maybe not that easy. I ended up writing a program to download files for me as I got tired of right-clicking and selecting Save Target As…). As you noticed if you walked the process with the rest of us setting up a basic file crawl is pretty straightforward .
I hear you ask: but how would I do that in PowerShell? What if my GUI stops working and I just have to get my Fast Search Center created, and content source created and configured?
I am so glad you asked. Leo Souza wasn't that happy as I asked him and he basically gave me the information I am about to transcribe. Aren't I lucky to have such a good friend?
What we did in Part 2 breaks down into 3 parts:
Remember to open up a PowerShell window from the Start menu:
Start --> Fast Search Server 2010 for SharePoint (right click --> Run as Administrator)
Now let's do each of the above steps in turn.
> cd ..\installer\scripts
> .\AdvancedFilterPack.ps1 -enable
[answer y to the only question it asks]
There is no need to restart the machine or any of the services.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$template = Get-SPWebTemplate "SRCHCENTERFAST#0" # Want to know more? Go to http://technet.microsoft.com/en-us/library/ff678213.aspx
New-SPWeb -Url "http://intranet.contoso.com/fast-search" -Name "TechNet VM Fast Search Page" -Template $template
$contentSSA = "FASTContent"
$startaddress = "\\VBOXSVR\neurobiology-files"
$contentsourcename = "File system crawl"
$contentsource = New-SPEnterpriseSearchCrawlContentSource -SearchApplication $contentSSA -Type file -name $contentsourcename -StartAddresses $startaddress
$contentsource.StartFullCrawl()
$contentsource.CrawlStatus
$searchSite = Get-SPWeb http://intranet.contoso.com/fast-search
$keywordQuery = New-Object Microsoft.Office.Server.Search.Query.KeywordQuery $searchSite
$keywordQuery.ResultTypes = [Microsoft.Office.Server.Search.Query.ResultType]::RelevantResults
$keywordQuery.EnableFQL = 1
$keywordQuery.RowLimit = 10
$keywordQuery.QueryText = "#"
$results = $keywordQuery.Execute()
Write-Host Total hits: $results[1].TotalRows
$resultsTable = $results.Item([Microsoft.Office.Server.Search.Query.ResultType]::RelevantResults)
$resultsDataTable = $resultsTable.Table
$resultsDataTable | Format-Table -AutoSize -Property title, url
So by rights you should create two versions of the script:
The separation gives you the flexibility to use the first script in lots of situations and the second one to execute a particular task without all typing. Get to it!
If something doesn't work please let me know. You'd be surprised where I am at any given time writing this blog (and this time I am at TechReady14 sitting in a Starbucks making sure this goes out in one piece.).
References and Thanks
Create a new FAST Search Center Site Collection using PowerShell by Brent Groom (thanks, Brent!)
FAST Search for SharePoint 2010–Using PowerShell to execute search by Satish TK (Thanks, Satish!)
Testing Custom Query Features (FAST Search Server 2010 for SharePoint) (oh, author of unknown origin: thanks!)
Scripted deployment reference (SharePoint Foundation 2010)
The code
[Not sure how to run these scripts? Check out Running Windows PowerShell Scripts at TechNet. You want to make them more useful? Slice and dice them even more. I won't be doing that...]
CreateContosoFastSearchCenter.ps1
CreateAFastSearchCenter.ps1 "http://intranet.contoso.com/fast-search" "TechNet VM Fast Search Page" "CONTOSO\Administrator"
CreateAFastSearchCenter.ps1
# CreateAFastSearchCenter.ps1 <Site URL> <Page Title>
function usage($cmd) { write-host "" write-host "Create a FAST Search Center" write-host "Create a FAST Search Center using the incoming URL and name" write-host "" write-host "usage: $cmd <Site URL> <Page Title> <Owner Alias>" write-host " <Site URL> - Specifies the new FULL URL for the site (for example, http://intranet.contoso.com/fast-search)"
write-host " <Page Title> - The title to give this search center"
write-host " <Owner Alias> - DOMAIN\alias of the site owner"
exit}
# argument checksswitch ($args.count) { 3 { $siteurl = $args[0] $pageTitle = $args[1] }
default { usage $myinvocation.mycommand.definition }}
# Put this here or execute it before you run the script
$template = Get-SPWebTemplate "SRCHCENTERFAST#0"
write-host "Creating the Fast Search Center at" $siteurl
New-SPWeb -Url $siteurl -Name $pageTitle -Template $template
write-host "Finished!"
ConfigureContosoFileFASTContentSourceAndStartAFullCrawl.ps1
ConfigureAFileFASTContentSourceAndStartAFullCrawl.ps1 "File system crawl" "\\VBOXSVR\neurobiology-files"
ConfigureAFileFASTContentSourceAndStartAFullCrawl.ps1
# ConfigureAFileFASTContentSourceAndStartAFullCrawl.ps1 <ContentSourceName> <FileSystemStartAddress>
function usage($cmd) {
write-host ""
write-host "Configure A File System Content Source And Start A Full Crawl"
write-host "usage: $cmd <ContentSourceName> <FileSystemStartAddress>"
write-host " <ContentSourceName> - Name to give this content source"
write-host " <FileSystemStartAddress> - Starting point for the file system crawl"
exit
}
# argument checks
switch ($args.count) {
2 { $contentSourceName = $args[0]
$startAddress = $args[1] }
default { usage $myinvocation.mycommand.definition }
$contentSource = New-SPEnterpriseSearchCrawlContentSource -SearchApplication "FASTContent" -Type file -name $contentSourceName -StartAddresses $startAddress
$sleepTime = 30
while ($true)
{
Write-Host "Current status: " $contentsource.CrawlStatus
if ($contentsource.CrawlStatus -eq "Idle")
break
write-host "Will check status again in" $sleepTime "seconds..."
Start-Sleep -seconds $sleepTime
ExecuteContosoSimpleFQLQuery.ps1
ExecuteASimpleFQLQuery.ps1 "http://intranet.contoso.com/fast-search" $args[0]
[To execute the "# AND isDocument=true" query use "# and isDocument:true" as the script assumes the use of FQL not the SharePoint default of KQL.]
ExecuteASimpleFQLQuery.ps1
# ExecuteASimpleFQLQuery.ps1 <URL> <Query>
function usage($cmd) { write-host "" write-host "Execute a simple FQL keyword query" write-host "" write-host "usage: $cmd <URL> <Query>" write-host " <URL> - URL to the Fast Search Center"
write-host " <Query> - Simple FQL to execute"
# argument checksswitch ($args.count) { 2 { $url = $args[0]
$query = $args[1] } default { usage $myinvocation.mycommand.definition }}
$searchSite = Get-SPWeb $url
$keywordQuery.QueryText = $query