SharePoint Search move to another page with same Query and Filters
NOTE: this is classic SP, meaning 2013, or classic experience in 365, classic sites, or in my case, Publishing Site Collection, even on O365 - SP Online.
Scenario: I have a search page, for our randomly designed search results, with filters and paging, so far so good, SP provides everything except the design, for that we play with our design templates.
Now our darling customer asks us to make a dynamic page for our singe item result.
Usually either we build a page-based system, and the results are pages, or even with documents-based system, usually we click on the docs and open them.
In our case we had documents, in a Documents Library (where else?), with some columns, and when we click on a result we go to a customized page that projects the metadata (columns) to that page.
Again, so if we get a result for a PDF or Image, we now open another .aspx page, there we show the Title and Thumbnail and Description and so on of the file, most of them just more fields in the Documents Library.
So what were our challenges?
1. Provide image url to the image itself, when under Documents Library
2. Provide thumbnails to documents
3. When moving to single item page, collect our query, including fixing the selected item index
4. When in the single item page, run the query on our search results web part
5. Taming an reusing the hover panel with the preview of the files
1. Provide image url to the image itself, when under Documents Library
Eventually we found the the search results, although Path is always "/DispForm.aspx?ID=68" ect., there is another MMD named "DefaultEncodingURL" that returns the actual file path.
2. Provide thumbnails to documents
We initially tried the "getpreview.ashx" endpoint, but with long PDFs he just gave them fixed around 400px height, and therefor the width was les than 100px, and it looked terrible. I'll still write down the syntax for anyone using any 2013+ on-premise SP.
_spPageContextInfo.siteAbsoluteUrl + '/_layouts/15/getpreview.ashx?path=' + ctx.CurrentItem.Path
But witO365 we have our great Graph Engine that can also help us with Thumbnails, with high quality
img = location.origin +
'/_api/v2.0/sharePoint:' +
(ctx.CurrentItem.Path.replace(location.origin, '')) +
':/driveItem/thumbnails/0/large/content?preferNoRedirect=true';
3. When moving to single item page, collect our query, including fixing the selected item index
When you are paging some search results there are 2 options. If you didn't filtered anything yet its really simple, the webparts just add some hash to your url like this "#k=#s=15#l=1033" where 'k' is part of the query text, 's' is the index to start with (s for start I guess), and 'l' should be for language support.
So if this is the case, let say I defined 6 results per page, moved 4 pages, so 's' is 24, and now I click on the 4th item, when moving to a simple item per page, I actually need to replace the value of 's' to 28. Some spitting and rebuilding does the trick (coming right up).
BUT if we have filters then there is a big object being built in your url hash zone, and it has the 's' hidden inside.
That obj is actually a JSON obj, containing 'k' as a string, 's' as an int, and 'r' for refiners, as an array.
I made a function to target all cases
Calling that we will be using "ctx.CurrentItemIdx" in our display template and send in inside onclick.
4. When in the single item page, run the query on our search results web part
So we are in our new page. The simple hashtag of "#k=#s=15#l=1033" does not need any help, as soon as you got the right 's' value the search result webpart finds the right item, and as long as you pass the query text, either by 'k' or some other Query String or token method, you can now page the same items as in the previous page.
5. Taming an reusing the hover panel with the preview of the files
TBC
Sharepoint Search Move To Another Page With Same Query And Filters >>>>> Download Now
ReplyDelete>>>>> Download Full
Sharepoint Search Move To Another Page With Same Query And Filters >>>>> Download LINK
>>>>> Download Now
Sharepoint Search Move To Another Page With Same Query And Filters >>>>> Download Full
>>>>> Download LINK MZ