0

i have a SharePoint 2013 Farm and want to Query the Search and display the outputs Title and Path column. Under SP2010 i have did it successfully with the code below:

Dim site As SPSite = New SPSite(url)
Dim web As SPWeb = site.OpenWeb

Dim proxy As SearchServiceApplicationProxy = DirectCast(SearchServiceApplicationProxy.GetProxy(SPServiceContext.GetContext(site)), SearchServiceApplicationProxy)
Dim q As KeywordQuery = New KeywordQuery(proxy)

q.ResultsProvider = SearchProvider.Default
q.ResultTypes = ResultType.RelevantResults
q.RowLimit = 2000

Dim path as String = "http://sp2013/sites"

Dim queryClassAndPath As String = "contentclass:""sts_site"" AND path:""" & path & """"

q.SelectProperties.Add("Title");
q.SelectProperties.Add("Path");

q.QueryText = querytext

q.TrimDuplicates = False

Dim results As ResultTableCollection = q.Execute()
Dim result As ResultTable = results(ResultType.RelevantResults)

Dim dt As DataTable = New DataTable()
dt.Load(result, LoadOption.OverwriteChanges)

For Each r As DataRow In dt.Rows
    Console.WriteLine(r(0))
Next

But when i execute this against an SharePoint 2013 Search server i do not get a Title nor Path column.

Why isnt the Title and Path Column in the results anymore?

0

I found the solution. If you define in the KeyWordQuery Object SelectedProperties, than you get beside these Properties additional Properties so that a result via result[0] is not possible. You have to call the Property explicit by

result["Title"]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.