3

I'm following this post on how to do a Keyword Query search in SP 2013. I'm getting the results items that I would expect. Now I need to display info about them.

The results are a mix of several different content types. They share some managed properties, but they also have some unique ones. The examples I've found show that I have to add each managed property I want to retrieve like so:

var keywordQuery = new Microsoft.SharePoint.Client.Search.Query.KeywordQuery(context);
var searchString = 'parentLink:"'+baseName+'"';
keywordQuery.set_queryText(searchString);

keywordQuery.set_sourceId(RESULTSOURCEGUID);

var properties = keywordQuery.get_selectProperties();
properties.add("Name");
properties.add("ContentType");
...and so on for each managed property name

But since I don't know what types will be in any given results how do I know which properties to request?

Is there a way to say "Give me all the managed properties associated with the returned item?"

2 Answers 2

2

There is a trick for this.

You can add managedproperties(filter=600/0/*) as a refiners option to your query. Like this: &refiners='managedproperties(filter%3d600%2f0%2f*)'

Note that query should return at least one result. So you can use this query:

/_api/search/query?querytext='*'&rowlimit=1
&refiners='managedproperties(filter%3d600%2f0%2f*)'
&sourceid='[your source ID]'

PrimaryQueryResult.RefinementResults.Refiners.Entries will contain all fields, including managed. If you want to exclude default fields, grab all fields from first item of result: PrimaryQueryResult.RelevantResults.Table.Rows and exclude them from Refiners list.

1
  • 1
    The original question from more than a year ago was for jsom and not REST api, but I have started using REST a lot more. I will have to check that out next time I need this. Thank you.
    – Rothrock
    Oct 12, 2016 at 15:57
0

Yes if you add this to the display template, you will be able to see ALL the properties:

for (var p in ctx.CurrentItem) {
    console.log(p + ":" + $getItemValue(ctx, p)); 
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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