I am also working on a similar activity to write relative URLs in CSWP so that I won't have to update the URLs again when site is moved to Production environment.
As per the inputs provided by @Precursive here, the query variable {SiteCollection.URL}
does work but it returns the URL value in double quotes. So I initially used it as given below in my CSWP.
path:{SiteCollection.URL}path1/patha/
SharePoint translates it to
path: "http://mysiteURL"path1/patha/
Please note that we don't see any error and in fact results are also returned. But this is misleading(at least in my case). This is because it doesn't return results matching exactly with the path we desire i.e. "http://mysiteURLpath1/patha/" instead we get a lot of results which are out of scope of this path as well. And it was not acceptable in my case.
Thanks to Carl in 't Veld for sharing the MSDN article link explaining what are different query variables and how do to work them. As per this article, in order to get the query variable value without double quotes, we need to use an escape character in query variable. So I have changed my relative query as given below:
path:"{\SiteCollection.URL}/path1/patha/"
and SharePoint translates it to
path: "http://mysiteURL/path1/patha/"
which returns exactly the same results which you would get if you were using absolute path. Hope this helps someone in future.
ows_SiteName(Text)
, you can create a managed property on this crawled property for exampleSiteName
and the addSiteName:yourSiteName
to your query :) EDIT: It also hasows_SPSiteURL
if you need :)path:"~/MySubsite/MyLibrary"
path:"http://MySite/MySubsite/MyLibrary"
it should work withpath:*/MySubsite/MyLibrary
I think. just add * and remove the quotes