1

We have created two different result sources This site and Site discussions. They each point to a custom search results page on our site. That is all working well.

When a search goes to the Site discussions result page, I would like to select the Site discussions result source instead of reverting to the This site default.

I can't find anything to help with this. So many searches just return how to set the value in the web ui.

I'm looking for some javascript that can set the result source in the searchbox on page load.

0

The result source is a property of the Search Result web part.

  1. Edit the page
  2. Edit the Search Results Web part
  3. Edit the query and change the result source to the desired source.
  4. Save the web part, save the page, check in, and publish.
  • Thanks for the suggestion, but it doesn't work for me. I went in and checked. The search result in the query builder is "all discussions," but the search box on the page still defaults to "this site." – Rothrock Jan 23 '18 at 16:35
  • The search box should not have anything to do with it. Do you mean the search navigation? – Matthew McDermott Jan 23 '18 at 19:11
  • huh? The question is about having the search box use the correct search result source. Of course the search box has something to do with it! I have two result sources and each goes to a specific search results page with a properly configured search results web part. But on the discussion results page the search box is set to the "this site" results page. As a user I want to remain on the vertical I've selected, not go back to this site everytime I search. – Rothrock Jan 23 '18 at 20:10
  • I meant the search box has nothing to do with your chosen result source. Did you set the search box to "Send queries to other Web Parts on this page"? – Matthew McDermott Jan 24 '18 at 12:42
  • The search box is from the masterpage. I can't change anything about it. The code above does what I need. – Rothrock Jan 24 '18 at 17:39
0

I've been poking around in _layouts\15\search.clientcontrols.js This is the best answer I've been able to come up with. I've put this code in a script editor on the discussions results page.

Sys.Application.add_load(setSearch);

function setSearch(){
    var searchBox = $getClientControl($get('SearchBox'));

    searchBox.set_resultsPageAddress(document.location.pathname);
    searchBox.set_currentPrompt('Search discussions')
}

I do have to know what the prompt should be -- I haven't figured out how to dynamically get the possible search results from the searchbox, but in this case it will work fine.

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.