Forum Discussion
Sharepoint search box web part - results only current site
I only want to show results (documents) from the current site
This of course isn't the curerent site of the search results web part. You actually want the search results from the current site where the search box came from.
If you look at the search box web part it goes to a url like this ( you can ofcourse replace this with your own!)
~site/_layouts/15/osssearchresults.aspx?u={contexturl}
so you could include path=... as an addtional query string. Then your search results web part cfould respond to that.
Within the web part properties you can also enable the drop down ( in the web part settings). The negative of this option is that this site isn't the default scope.
Hi Pieter Veenstra,
Let me see if I understand you correct.
I would need to change the webpart property to : ~site/_layouts/15/osssearchresults.aspx?u={contexturl}path=..
Can you give me some kind of example. As you understand this path= must be something link path=[some variable] to have this a dynamic solution.
Thanks, Mike
- Jan 10, 2017
Hi Mike,
You can use any page you like. Then within the web part properties of the search boxes configure the url of your custom results page.
The Url I gave you is the out of the box one. Whcih will not work for your requirements as you will need to update the query in the results web part.
You could make the query in the results web part include a querystring parameter.
I would create a page (e.g. pages/results.aspx) then add the results web part on that page.
So in the search box I would configure a url like:
(I've not tested this)
/anysite/Pages/results.aspx?u={contexturl}&mypath=~site
Then in the search results web part you will get a query like:
{searchboxquery} Path:{QueryString.mypath}
- Mike JansenJan 10, 2017Iron Contributor
Pieter Veenstra wrote:Hi Mike,
You can use any page you like. Then within the web part properties of the search boxes configure the url of your custom results page.
The Url I gave you is the out of the box one. Whcih will not work for your requirements as you will need to update the query in the results web part.
You could make the query in the results web part include a querystring parameter.
I would create a page (e.g. pages/results.aspx) then add the results web part on that page.
So in the search box I would configure a url like:
(I've not tested this)
/anysite/Pages/results.aspx?u={contexturl}&mypath=~site
Then in the search results web part you will get a query like:
{searchboxquery} Path:{QueryString.mypath}
Hmmm, have to do some more testing but first test gives the url like this: .......134&mypath=~site&k=test&ql=1043
~site is not changes to the url of the site.
(fyi "test" is my search)
- Jan 10, 2017
You might have to hard code the url in your search boxes.