Add Refiner to Refinement Web Part using CSOM and PowerShell

The refinement web part present by default on a search results page help to narrow down search results. The inter connected web parts present in a search result page are

  1. Search Box Web Part
  2. Search Navigation
  3. Search Results
  4. Refinement Web Part

The refinement web part used refiners which are managed properties bound to crawled properties created by search crawl. The managed properties must be enabled as refiners to be able to use on the web part.

newrefineraddedtowebpart

By default, the refiners FileType, contentclass, contentTypeId, WebTemplate, DisplayAuthor and LastModifiedTime are available to select.

The XML definition of the webpart is

<webParts>
<webPart xmlns=”http://schemas.microsoft.com/WebPart/v3″&gt;
<metaData>
<type name=”Microsoft.Office.Server.Search.WebControls.RefinementScriptWebPart, Microsoft.Office.Server.Search, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” />
<importErrorMessage>Cannot import this Web Part.</importErrorMessage>
</metaData>
<data>
<properties>
<property name=”StatesJson” type=”string”>{}</property>
<property name=”HelpUrl” type=”string” />
<property name=”ServerIncludeScriptsJson” type=”string”>null</property>
<property name=”Height” type=”string” />
<property name=”TitleUrl” type=”string” />
<property name=”SelectedRefinementControlsJson” type=”string”>{“refinerConfigurations”:[{“sortBy”:0,”sortOrder”:0,”maxNumberRefinementOptions”:21,”propertyName”:”FileType”,”type”:”Text”
,”displayTemplate”:”~sitecollection/_catalogs/masterpage/Display Templates/Filters/Filter_Default.js”,”displayName”:””,”useDefaultDateIntervals”:false,”aliases”:[“format”],”refinerSpecStringOverride”:””
,”intervals”:null},{“propertyName”:”contentclass”,”displayName”:null,”displayTemplate”:”~sitecollection/_catalogs/masterpage/Display Templates/Filters/Filter_Default.js”,”maxNumberRefinementOptions”:10
,”type”:”Text”,”refinerSpecStringOverride”:null,”useDefaultDateIntervals”:false,”isInherited”:false,”sortBy”:0,”sortOrder”:0,”intervals”:null,”aliases”:[“DAV:contentclass”]},{“propertyName”:”ContentTypeId”
,”displayName”:null,”displayTemplate”:”~sitecollection/_catalogs/masterpage/Display Templates/Filters/Filter_Default.js”,”maxNumberRefinementOptions”:15,”type”:”Text”,”refinerSpecStringOverride”:null
,”useDefaultDateIntervals”:false,”isInherited”:false,”sortBy”:0,”sortOrder”:0,”intervals”:null,”aliases”:null},{“propertyName”:”WebTemplate”,”displayName”:null
,”displayTemplate”:”~sitecollection/_catalogs/masterpage/Display Templates/Filters/Filter_Default.js”,”maxNumberRefinementOptions”:10,”type”:”Text”,”refinerSpecStringOverride”:null
,”useDefaultDateIntervals”:false,”isInherited”:false,”sortBy”:0,”sortOrder”:0,”intervals”:null,”aliases”:null},{“propertyName”:”DisplayAuthor”,”displayName”:null
,”displayTemplate”:”~sitecollection/_catalogs/masterpage/Display Templates/Filters/Filter_Default.js”,”maxNumberRefinementOptions”:9,”type”:”Text”,”refinerSpecStringOverride”:null
,”useDefaultDateIntervals”:false,”isInherited”:false,”sortBy”:0,”sortOrder”:0,”intervals”:null,”aliases”:null},{“propertyName”:”LastModifiedTime”,”displayName”:null
,”displayTemplate”:”~sitecollection/_catalogs/masterpage/Display Templates/Filters/Filter_SliderBarGraph.js”,”maxNumberRefinementOptions”:0,”type”:”DateTime”
,”refinerSpecStringOverride”:null,”useDefaultDateIntervals”:true,”isInherited”:false,”sortBy”:0,”sortOrder”:0,”intervals”:null,”aliases”:[“Write”,”FileWrite”,”DAV:getlastmodified”]},{“sortBy”:0
,”sortOrder”:0,”maxNumberRefinementOptions”:15,”propertyName”:”RefinableString00″,”type”:”Text”,”displayTemplate”:”~sitecollection/_catalogs/masterpage/Display Templates/Filters/Filter_Default.js”
,”displayName”:”Directorate”,”useDefaultDateIntervals”:false,”aliases”:null,”refinerSpecStringOverride”:””,”intervals”:null},{“sortBy”:0
,”sortOrder”:0,”maxNumberRefinementOptions”:15,”propertyName”:”RefinableString01″,”type”:”Text”,”displayTemplate”:”~sitecollection/_catalogs/masterpage/Display Templates/Filters/Filter_Default.js”
,”displayName”:”Status”,”useDefaultDateIntervals”:false,”aliases”:null,”refinerSpecStringOverride”:””,”intervals”:null}]}</property>
<property name=”AllowConnect” type=”bool”>True</property>
<property name=”RenderTemplateId” type=”string”>~sitecollection/_catalogs/masterpage/Display Templates/Filters/Control_Refinement.js</property>
<property name=”AllowZoneChange” type=”bool”>True</property>
<property name=”EmptyMessage” type=”string” />
<property name=”ExportMode” type=”exportmode”>All</property>
<property name=”AllowHide” type=”bool”>True</property>
<property name=”AllowEdit” type=”bool”>True</property>
<property name=”Description” type=”string”>This webpart helps the users to refine search results</property>
<property name=”AllowMinimize” type=”bool”>True</property>
<property name=”ChromeType” type=”chrometype”>None</property>
<property name=”ChromeState” type=”chromestate”>Normal</property>
<property name=”CatalogIconImageUrl” type=”string” />
<property name=”HelpMode” type=”helpmode”>Modeless</property>
<property name=”TitleIconImageUrl” type=”string” />
<property name=”Width” type=”string” />
<property name=”AlternateErrorMessage” type=”string” null=”true” />
<property name=”Hidden” type=”bool”>False</property>
<property name=”Title” type=”string”>Refinement</property>
<property name=”AllowClose” type=”bool”>True</property>
<property name=”MissingAssembly” type=”string”>Cannot import this Web Part.</property>
<property name=”UseManagedNavigationRefiners” type=”bool”>False</property>
<property name=”QueryGroupName” type=”string”>Default</property>
<property name=”EmitStyleReference” type=”bool”>True</property>
<property name=”Direction” type=”direction”>NotSet</property>
</properties>
</data>
</webPart>
</webParts>

To modify the collection of refiners the property “SelectedRefinementControlsJson” which is in Json format needs to be updated.

The property “SelectedRefinementControlsJson” is converted to JSON using PowerShell ConvertFrom-Json method before additional refiners are added. The PowerShell ConvertTo-Json method is used to convert back to JSON before updating the “SelectedRefinementControlsJson” property.

Advertisements

One thought on “Add Refiner to Refinement Web Part using CSOM and PowerShell

  1. Pingback: Update Search Result Web Part: Query Text and Result Source | reshmeeauckloo

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s