2

I have an application where the end user is able to add new subsites to existing sites, and add sub sites to those sub sites and so on. As part of the site template I have a Search Results Web Part which is supposed to return a list of sites (and information from a custom SiteInformation list located on that site) one level below the current one i.e. show the site information for this sites immediate children.

Unfortunately using a simple query like

Path:"{\Site.URL}" ContentTypeID:MySiteInfoContentType

shows results from every site below the current site including all child and sub sites.

How can I restrict the search to only return results from one level of sub sites down?

I've been trying to do this using a wildcard search with space for one level of child site i.e.

Path:"{\Site.URL}" + "/*/Lists/SiteInformation/DispForm.aspx"

But it's not getting me anywhere. Is there a better way to limit search results by depth of sub site? For example is there a Site Parent variable which I could use?

Many thanks.

2

You can try using the property UrlDepth. It allows you to manipulate how deep the URL needs to go for the query. for example;

UrlDepth=1 returns things like http://site/subsite
UrlDepth=2 returns things like http://site/pages/page.aspx or http://site/subsite/subsite

May help a bit.

| improve this answer | |
2

In SharePoint 2013 probably the easiest way to restrict search query to a specific web would be to specify WebId property:

WebId:"Web Id goes here"

Example

enter image description here

How to determine WebId property for a web site

The following REST query returns SP.Web.ID property:

https://[site collection]/[web]/_api/web?$select=Id
| improve this answer | |
  • Thanks Vadim - this is useful but I don't think it helps in my specific case. I need to return results only from the direct child sites of the site I'm on. I was hoping here would be a property like parent so I could search for Parent:Site.Url or something along those lines. – Tim Nov 10 '14 at 13:19
  • Tim, AFAIK there is no way to restrict search query to sub site (direct child) that way – Vadim Gremyachev Nov 10 '14 at 16:58
0

Here's what worked for me;

path:"https://contoso/sites/programs" UrlDepth=3 contentclass:STS_Web Site<>{Site.URL}

with some trickery from ShareGate team https://www.youtube.com/watch?v=KAaYKe9HaDU

| improve this answer | |
0

As Matt says, you can you the UrlDepth param, however, remember to use it right after the path param, in order to make it work accordingly.

Here is an example, that will return only the 1st level child sites of a given site:

path:{site url} UrlDepth:3 contentclass:STS_Web
| improve this answer | |

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.