Programmatically Setting the Fetched Properties to an Extended Search Core Result Web Part
This post is over a year old, some of this information may be out of date.
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.
- The “SelectColumns” (Fetched Properties) string may not be Null or empty;
- The “PropertiesToRetrieve” must be Null or Empty;
- “UseLocationVisualization” must be false.
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:
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.
<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>
Related articles
Fix: People Search Box Has Layout Problems When Used Outside a Search Center
Search Hover Panel Positioning Bug in non IE Browsers (SharePoint 2013)
Display the Title Row (Top Navigation) in the Search Centers of SharePoint 2013
Report issues or make changes on GitHub
Found a typo or issue in this article? Visit the GitHub repository to make changes or submit a bug report.
Comments
Let's build together
Manage content in VS Code
Present from VS Code