Alert This post is over a year old, some of this information may be out of date.

Programmatically Setting the Fetched Properties to an Extended Search Core Result Web Part

This week I needed to extend the search core result web part to be able to do some custom filtering and search result styling.

For the search result styling, additional fetched properties (columns) needed to be added programmatically to the Web Part properties. But every time I checked in the web part properties, these fetched properties were not added, and I end up with the default fetched properties.

After investigating the “Microsoft.Office.Server.Search” assembly I saw that you must meet three conditions.

  1. The “SelectColumns” (Fetched Properties) string may not be Null or empty;
  2. The “PropertiesToRetrieve” must be Null or Empty;
  3. UseLocationVisualization” must be false.
1
2
3
4
5
6
7
set
{
  if ((!string.IsNullOrEmpty(value) && string.IsNullOrEmpty(base.PropertiesToRetrieve)) && !base.UseLocationVisualization)
  {
    base.PropertiesToRetrieve = value;
  }
}

Solution

The solution to programmatically add your columns to the fetched properties is the following:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
protected override void OnInit(EventArgs e)
{
  //Set an empty string for the PropertiesToRetrieve property
  base.PropertiesToRetrieve = string.Empty;
  //Set the UseLocationVisualization property to false
  base.UseLocationVisualization = false;

  //Set the fetched properties
  base.SelectColumns = fetchProp;
}

“fetchProp” is a string that contains the following content.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
<Columns>
  <Column Name="WorkId"/>
  <Column Name="Rank"/>
  <Column Name="Title"/>
  <Column Name="Author"/>
  <Column Name="Size"/>
  <Column Name="Path"/>
  <Column Name="Description"/>
  <Column Name="Write"/>
  <Column Name="SiteName"/>
  <Column Name="CollapsingStatus"/>
  <Column Name="HitHighlightedSummary"/>
  <Column Name="HitHighlightedProperties"/>
  <Column Name="ContentClass"/>
  <Column Name="IsDocument"/>
  <Column Name="SiteTitle"/>
</Columns>

Comments

Back to top