Forum Discussion
pnp.sp.search > Add property to searchresults
I have this code:
private GetSearchresults(): void { pnp.sp.search(<SearchQuery>{ Querytext: "ContentType:TEST_matters", RowLimit: 10, EnableInterleaving: true, SelectProperties: ["RefinableString10", "CreatedBy","Created"], RefinementFilters: ["RefinableString18:equals('false')"], }).then((result: SearchResults) => { var props = result.PrimarySearchResults; debugger; var propValue = ""; var counter = 1; props.forEach(function(object) { propValue += counter++ +'. Title - ' +object.Title +"<br/>"+"Rank - " + object.Rank +"<br/>"+"File Type - " + object.FileType+"<br/>"+ "Original Path - " +object.OriginalPath +"<br/>"+" Summary - "+ object.HitHighlightedSummary + "<br/>"+"<br/>"; });
Now I want to have the "RefinableString10" field like this "object.RefinableString10". But I get an error that "RefinableString10" does not exist in "SearchResults". However, in debug, I can see "RefinableString10" which is proper filled. I suppose I need to declare something? But I do not have any clue.
Thanks, Mike
- Mike JansenIron Contributor
For now I added the "RefinableString10" to the "SearchResult" declaration in "search.d.ts". It works but is this the way to go? Ain't it possible to add a property to the SearchResults in the webpart.ts file?
- Leonardo TabosaCopper Contributor
I'm having this same problem right now with one search solution.
Did you found other way to make it work?
- Leonardo TabosaCopper Contributor
This is what I did to fix this problem.
First I create other Interface that extends from the SearchResult:
export interface MySearchResult extends pnp.SearchResult{RefinableString10?:string;}Than instead of use the parameter result: SearchResult i used result: MySearchResultIn the example should be instead of function(object) you could use result:MySearchResult