Creating FAST Managed Properties using Power shell

Add-PSSnapin Microsoft.SharePoint.PowerShell
if([Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")-eq$null){throw "Unable to load Microsoft.SharePoint.dll";}

Add-PSSnapin Microsoft.FASTSearch.PowerShell
if([Reflection.Assembly]::LoadWithPartialName("Microsoft.FASTSearch.PowerShell")-eq$null){throw "Unable to load Microsoft.FASTSearch.dll";}

function SetManagedProperties([string]$mpName, [int]$mpType = 0, [string]$cpName, [int]$sortableType = 0, [bool]$isQueryable = $false, [bool]$isRefiner = $false, [string]$ftiName, [int]$indexMapping = 1){

    if($mpName -eq $null){
        Write-Host "Error: Managed Property Name is null"
        return;
    }
    if($mpType -eq 0){
        Write-Host "Error: Managed Property Type should be grater than zero"
        return;
    }   
    if($cpName -eq $null){
        Write-Host "Error: Crawled Property Name is null"
        return;
    }   
   
    $mp = Get-FASTSearchMetadataManagedProperty $mpName
   
     if($mp -ne $null){
        Remove-FASTSearchMetadataManagedProperty -Name $mpName -Force
        Write-Host "Removing existing managed property ($mpName).."
    }
       
    $cp = Get-FASTSearchMetadataCrawledProperty -Name $cpName
   
    if($cp -eq $null){
        Write-Host "Error: $cpName - Crawled Property Not Found."
        return;
    }
   
    try{
   
        $mp = New-FASTSearchMetadataManagedProperty -Name $mpName -Type $mpType
    }
    catch{
        Write-Host "Error in creating managed property - $mpName"
        return;
    }
   
    try{
        $pMapping =  New-FASTSearchMetadataCrawledPropertyMapping -CrawledProperty $cp -ManagedProperty $mp
    }
    catch{
        Write-Host "Error in Mapping managed property - $mpName & Crawled Propery - $cpName"
        return;
    }
   
    $fti =  Get-FASTSearchMetadataFullTextIndex -Name $ftiName

    try{
        New-FASTSearchMetadataFullTextIndexMapping -ManagedProperty $mp -FullTextIndex $fti -Level $IndexMapping
    }
    catch{
        Write-Host "Error in Index Mapping to Managed Property - $mpName & Crawled Propery - $cpName"
        return;
    }
   
    try{
        Set-FASTSearchMetadataManagedProperty -Name $mpName -MergeCrawledProperties $true -Queryable $isQueryble -SortableType $sortableType -RefinementEnabled $isRefiner   
    }
    catch{
        Write-Host "Error on enable Sortable, Queryable, RefinementEnabled for Managed Property - $mpName & Crawled Propery - $cpName"
        return;
    }
    Write-Host "$mpName created successfully!"
}

#mpType (1-Text, 2-Integer, 3-Boolean, 4-Float, 5-decimal, 6-DateTime)
#sortableType (0-Disabled, 1-Enabled)
#indexMapping (1 to 7)
SetManagedProperties -mpName "ManagedPropertyName" -mpType 1 -cpName "CrawledPropertyName" -sortableType 0 -isQueryable $false -isRefiner $false -ftiName "Content" -indexMapping 1

Comments

Popular posts from this blog

Windows Azure Package Build Error: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

Resource ID : 1. The request limit for the database is 180 and has been reached.

How to get Client's Location using IPAddress