0

The SharePoint search service works on documents content and it Metadata (properties), I need to retrieve the field name and it content (SPField) which the search are matched on it.

What field should I add to the SelectProperties object ? or where I can find these information.

KeywordQuery keywordQuery = new KeywordQuery(SPContext.Current.Site);

keywordQuery.QueryText = queryText;
keywordQuery.ResultsProvider = SearchProvider.Default;
var selecProperties = keywordQuery.SelectProperties;
selecProperties.Add("UniqueId");
selecProperties.Add("FileLeafRef");
selecProperties.Add("ListId");
selecProperties.Add("WebId");
selecProperties.Add("Created");
selecProperties.Add("CheckoutUserOWSUSER");

SearchExecutor searchExecutor = new SearchExecutor();
ResultTableCollection resultTableCollection = searchExecutor.ExecuteQuery(keywordQuery);
ResultTable resultTable = resultTableCollection.Filter("TableType", KnownTableTypes.RelevantResults).FirstOrDefault();
DataTable dataTable = resultTable.Table;
imsome1
  • 1,182
  • 4
  • 22
  • 37
Ron
  • 1,748
  • 2
  • 12
  • 11

1 Answers1

0

I found the solution in the KeywordQuery object in the property HitHighlightedProperties all needed is to add crawled properties (managed properties) to SelectProperties and HitHighlightedProperties, then in the field you will find xml contains details about the found keyword in all available fields.

Ron
  • 1,748
  • 2
  • 12
  • 11