Reputation: 344
I created some Managed Properties following instructions at http://technet.microsoft.com/en-us/library/ff621097(v=office.14).aspx. I then created a custom SharePoint application page with a KeywordQuery search to find only documents using the following code:
using System;
using System.Collections.Generic;
using System.Data;
using Microsoft.Office.Server.Search.Query;
using Microsoft.SharePoint.WebControls;
protected System.Data.DataTable TrySearch(string keywords, Int32 pageSize, Int32 page, out Int32 totalPages)
{
int startRow = (page - 1)*rowLimit;
var kwq = new KeywordQuery(Site);
kwq.QueryText = string.Format("Title:\"{0}\"", keywords);
kwq.ResultTypes = ResultType.RelevantResults;
kwq.RowLimit = pageSize;
kwq.StartRow = startRow;
kwq.TrimDuplicates = true;
kwq.HiddenConstraints = "path:\"*/User Docs*\" AND IsDocument:true";
kwq.KeywordInclusion = KeywordInclusion.AllKeywords;
// Default
kwq.SelectProperties.Add("WorkId");
kwq.SelectProperties.Add("Rank");
kwq.SelectProperties.Add("Title");
kwq.SelectProperties.Add("Path");
kwq.SelectProperties.Add("SiteName");
kwq.SelectProperties.Add("HitHighlightedSummary");
kwq.SelectProperties.Add("HitHighlightedProperties");
kwq.SelectProperties.Add("ContentClass");
kwq.SelectProperties.Add("IsDocument");
// Custom (they come back blank even when set as managed properties)
kwq.SelectProperties.Add("IntroText");
kwq.SelectProperties.Add("Date");
kwq.SelectProperties.Add("ListItemId");
ResultTableCollection rtc = kwq.Execute();
var results = new DataTable();
if (rtc.Count == 0)
{
totalPages = 0;
return results;
}
using (ResultTable relevantResults = rtc[ResultType.RelevantResults])
{
results.Load(relevantResults, LoadOption.OverwriteChanges);
totalPages = (int) Math.Round((double) relevantResults.TotalRows/pageSize);
}
return results;
}
My problem is that no what I do, I cannot get values back for my managed properties. The search works fine. I can filter accordingly and get the results I expect, it's just that the custom columns are empty. I'm mostly concerned with the ID, but I'd love to get all the custom properties I've asked for.
Could there be some sort of setting I've missed on the server? Any help is appreciated.
Upvotes: 1
Views: 2470
Reputation: 11
I suppose you must have reached the solution by now, but for those struggling with the same issue the solution is:
After mapping the crawled properties to existing/new managed properties, crawl again. That's it. Data will show up for the requested properties.
Upvotes: 0