My presentation at the Australia SharePoint Conference went really well last week. As part of the demos I completed five search crawls. After the initial crawls I mapped some new Managed Properties to Crawled properties and then concluded with configuring some refiners in a FAST Search Centre.
To help speed up this process I performed the property creation and mappings using Powershell. A few of the attendees has asked for these scripts, so here they are:
Example One - Create a new 'category' managed property, and map it to two crawled properties
$categorymanagedproperty = New-FASTSearchMetadataManagedProperty -Name category -type 1 -description "SPCAU Demo Property"
Set-FASTSearchMetadataManagedProperty -Name category -Queryable $true -StemmingEnabled $true -RefinementEnabled $true
$categorycrawledproperty1 = Get-FASTSearchMetadataCrawledProperty -name "productcategorydescription"
$categorycrawledproperty2 = Get-FASTSearchMetadataCrawledProperty -name "searchviewread listelement.productcategorydescription"
New-FASTSearchMetadataCrawledPropertyMapping -Managedproperty $categorymanagedproperty -crawledproperty $categorycrawledproperty1
New-FASTSearchMetadataCrawledPropertyMapping -Managedproperty $categorymanagedproperty -crawledproperty $categorycrawledproperty2
The New-FASTSearchMetadataManagedProperty command creates a new managed property.
Set-FASTSearchMetadataManagedProperty allows us to update settings on the managed property, such as enabling querying, stemming and refinement.
Running Get-FASTSearchMetadataCrawledProperty will output all of the crawled properties in the index, so this command is typically executed with parameters that filter down the property to retrieve one crawled property.
Finally the New-FASTSearchMetadataCrawledPropertyMapping command takes a managed property and crawled property as parameters and maps the two together.
It's as easy as that!
Another pattern I had in my scripts is to map a crawled property to an existing managed property.
Example Two : Map a crawled property to an existing managed property
$titlemanagedproperty = Get-FASTSearchMetadataManagedProperty -Name title
$titlecrawledproperty = Get-FASTSearchMetadataCrawledProperty | where-object {($_.Name -eq "productname") -and ($_.CategoryName -eq "JDBC")}
New-FASTSearchMetadataCrawledPropertyMapping -Managedproperty $titlemanagedproperty -crawledproperty $titlecrawledproperty
The above example maps the productname crawled property to the title managed property. The Get-FASTSearchMetadataManagedProperty command is used to get an existing managed property instead of creating a new one. Note also that the Get-FASTSearchMetadataCrawledProperty in the above example differs from the previous, where-object is used to apply filters on not only the crawled property Name but also the CategoryName, I found I had to do this as the specific crawled property name was not unique for some reason, this is quite a common situation, by also specifying the crawled property category we can ensure we're picking up the correct property.
Example Three - Undo Properties and Mappings
This final example includes commands to delete managed properties or property mappings.
Remove-FASTSearchMetadataManagedProperty -Name category -Force
$titlemanagedproperty = Get-FASTSearchMetadataManagedProperty -Name title
$titlecrawledproperty = Get-FASTSearchMetadataCrawledProperty | where-object {($_.Name -eq "productname") -and ($_.CategoryName -eq "JDBC")}
Remove-FASTSearchMetadataCrawledPropertyMapping -Managedproperty $titlemanagedproperty -crawledproperty $titlecrawledproperty -Force
The first command Remove-FASTSearchMetadataManagedProperty will delete the managed property and all it's property mappings. The next three commands involve deleting only a mapping of properties - you wouldn't want to delete the title managed property!!! So you need to get the specific managed property and crawled property and then run the Remove-FASTSearchMetadataCrawledPropertyMapping command to remove the mapping. Note the -Force parameter executes the command without prompting the user for confirmation.
I recommend creating, configuring and mapping FAST Search properties using Powershell as its quicker than doing the same using the FAST Query SSA. More importantly it's repeatable! So this is particularly useful when you need to repeat the same work between environments from Dev --> Test --> Production. Leaving this to be done manually is too time consuming and prone to human error. A word of warning though - don't develop your Powershell scripts in production! You could inadvertently alter some out of the box managed properties or other settings as you're trying to work out your scripts.
No comments:
Post a Comment