PowerShell
Edit|Remove
powershell
<#
.SYNOPSIS
Test the FAST Installation for basic indexing and search functionality
.DESCRIPTION
Test the FAST Installation:
1. Feed a test document
2. Confirm that document can be retrieved via search
3. Delete the test document
.NOTES
File Name : Test-FastInstallation.ps1
Author : Matthew King <matthew.king@microsoft.com>
#>
$guid = [string][System.Guid]::NewGuid()
$tempFile = "$guid.txt"
Push-Location $env:TEMP
try {
$guid > $tempFile
Write-Host "Adding our test document... " -NoNewline
$output = docpush -c sp $tempFile
if ($?) {
Write-Host "OK"
}
else {
$output
return
}
}
finally {
rm $tempFile
Pop-Location
}
function Test-FASTSearch {
param(
[string]$Query = "meta.collection:sp",
[int]$baseport = 13000
)
Add-Type -AssemblyName System.Web
$equery = [System.Web.HttpUtility]::UrlEncode($Query)
$hits = 1
$port = $baseport + 280
$url = "http://localhost:$port/cgi-bin/asearch?query=$equery&hits=$hits"
$web = New-Object Net.WebClient
$response = $web.DownloadString($url)
$totalHits = -1
if ($response -match "#CNT (\d+)") {
$totalHits = $matches[1]
}
$totalHits
}
[xml]$xml = Get-Content (Join-Path $env:FASTSEARCH "etc\Node.xml")
$baseport = $xml.config.baseport
$query = "`"$guid`""
Write-Host "Searching for it... " -NoNewline
$found = $false
for ($i=0; $i -lt 5; $i++) {
if ($i -gt 0) {
Write-Verbose 'Not found... sleeping for 10 seconds'
Start-Sleep 10
}
$hits = Test-FASTSearch $query $baseport
if ($hits -eq 1) {
Write-Host 'Found it!'
$found = $true
break
}
elseif ($hits -gt 1) {
Write-Warning "Found more documents than expected"
break
}
elseif ($hits -eq -1) {
Write-Error "Something bad happened"
break
}
}
if (-not $found) {
Write-Error "Failed to find our document"
}
else {
Write-Host "Deleting test document... " -NoNewline
$output = docpush -c sp -d -u http://cohowinery.com/ $tempFile
if ($?) {
Write-Host "OK"
}
else {
$output
}
}
<#
.SYNOPSIS
Test the FAST Installation for basic indexing and search functionality
.DESCRIPTION
Test the FAST Installation:
1. Feed a test document
2. Confirm that document can be retrieved via search
3. Delete the test document
.NOTES
File Name : Test-FastInstallation.ps1
Author : Matthew King <matthew.king@microsoft.com>
#>
$guid = [string][System.Guid]::NewGuid()
$tempFile = "$guid.txt"
Push-Location $env:TEMP
try {
$guid > $tempFile
Write-Host "Adding our test document... " -NoNewline
$output = docpush -c sp $tempFile
if ($?) {
Write-Host "OK"
}
else {
$output
return
}
}
finally {
rm $tempFile
Pop-Location
}
function Test-FASTSearch {
param(
[string]$Query = "meta.collection:sp",
[int]$baseport = 13000
)
Add-Type -AssemblyName System.Web
$equery = [System.Web.HttpUtility]::UrlEncode($Query)
$hits = 1
$port = $baseport + 280
$url = "http://localhost:$port/cgi-bin/asearch?query=$equery&hits=$hits"
$web = New-Object Net.WebClient
$response = $web.DownloadString($url)
$totalHits = -1
if ($response -match "#CNT (\d+)") {
$totalHits = $matches[1]
}
$totalHits
}
[xml]$xml = Get-Content (Join-Path $env:FASTSEARCH "etc\Node.xml")
$baseport = $xml.config.baseport
$query = "`"$guid`""
Write-Host "Searching for it... " -NoNewline
$found = $false
for ($i=0; $i -lt 5; $i++) {
if ($i -gt 0) {
Write-Verbose 'Not found... sleeping for 10 seconds'
Start-Sleep 10
}
$hits = Test-FASTSearch $query $baseport
if ($hits -eq 1) {
Write-Host 'Found it!'
$found = $true
break
}
elseif ($hits -gt 1) {
Write-Warning "Found more documents than expected"
break
}
elseif ($hits -eq -1) {
Write-Error "Something bad happened"
break
}
}
if (-not $found) {
Write-Error "Failed to find our document"
}
else {
Write-Host "Deleting test document... " -NoNewline
$output = docpush -c sp -d -u http://cohowinery.com/ $tempFile
if ($?) {
Write-Host "OK"
}
else {
$output
}
}