Jan 10 2017 02:51 AM
I thought this would be easy but I can't find is out.
On a site I use the (standard) search box web part. When I use this it returns results from the whole site collection. I do not want that. I only want to show results (documents) from the current site.
I did create a custom results page and configured it to show only documents of the current site. However I created this page on the root of the site collection as I do not want to create a specific search result page for al my subsites (can be a few 1000).
What is wrong with my approach?
Jan 10 2017 07:12 AM
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.
Jan 10 2017 07:15 AM
Jan 10 2017 07:18 AM
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 07:20 AM
@Brent Ellis wrote:
Try adding this to your Change Query option under the properties of the the Search Results Web Part
Path:{Site.URL}
I tried that but it takes the url of the page where the search results page is located (the root in my case) not the page where the query was issued.
Jan 10 2017 07:21 AM
Hi @Brent Ellis,
Does that work?
Isn't Site.Url using the Site of the search results web part? Therefore If all search boxes on many sites all need to lead to the same search results page then that wouldn't work. you would get results from where the search result page has been created.
Jan 10 2017 07:23 AM
@Pieter Veenstra wrote:Hi @Brent Ellis,
Does that work?
Isn't Site.Url using the Site of the search results web part? Therefore If all search boxes on many sites all need to lead to the same search results page then that wouldn't work. you would get results from where the search result page has been created.
Indeed my experience as well
Jan 10 2017 07:29 AM
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}
Jan 10 2017 07:37 AM
@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 07:40 AM
You might have to hard code the url in your search boxes.
Jan 10 2017 07:51 AM
Looks that way. I will try some solutions to see if I can create a more global solution.
Jan 10 2017 07:58 AM
If you are in a position where you can us PnP to provision your web parts then {site} would contain the url.
Jan 10 2017 08:09 AM
Jan 11 2017 05:04 AM
Part 2 ;)
Solved it but, a bit strange, I think.
Like mentioned I've changed the results page url like this:
https://mytenant/sites/test/sitePages/results_test.aspx?u={contexturl}&mypath='https://mytenant/sites/test/customer500/case1'
I did not do anything with the "mypath" variable anywhere. Even not in the result source.
I'm not a big fan of solutions that suddenly work, without knowing why ;)
Can someone explane why this seems to work?
Jan 11 2017 08:36 AM
Jan 12 2017 04:38 AM - edited Feb 07 2017 04:52 AM
In advanced mode:
"path:"https://blabla.sharepoint.com/sites/test" (FileExtension:doc OR FileExtension:docx OR FileExtension:xls OR FileExtension:xlsx OR FileExtension:ppt OR FileExtension:msg OR FileExtension:pptx OR FileExtension:pdf) (IsDocument:"True" OR contentclass:"STS_ListItem")"
Nothing magic here. The result source is just the "documents" result source
Jan 12 2017 06:16 AM
So if you take:
"path:"https://mytenant.sharepoint.com/sites/test"
Do you still get the results back for the /sites/test site only?
I would always configure the result source as Local sharepoint results. and then only use the query to do the filtering.
Jan 12 2017 07:11 AM
All I did was set the result source to "documents" and change the URL of the results page and now I get results from the subsite: https://mytenant.sharepoint.com/sites/test/customer1/order2
That's all. When I check the advanced mode I see the above but I did not configure that manually.