Which is the best way of limiting search results to a specific subsite when using the search REST API in SharePoint 2013?
I've tried adding a new content source ("MySubsiteContentSource") (in addition to the default "Local SharePoint sites") that specifies the subsite http://localhost/subsite
as the single start address, but I'm unsure of whether this is the right approach and in either case I haven't been able to filter the results to only use this content source.
I've also tried to create a custom result source that uses the transform {searchTerms} ContentSource:MySubsiteContentSource
, but when adding &sourceId=[id of the result source]
to the query I'm getting an error stating that the sourceId
parameter is invalid.
Last, I've tried queries on the form:
http://localhost/_api/search/query?querytext='test path:http://localhost/subsite/*'
But this returns 0 results. Even specifying http://localhost/*
as path returns 0 results. When I just use query?querytext='test'
I get results, but for the whole site collection (as expected).
I get the same behavior when searching from the search center app GUI. If I specify the id of the subsite web in the query (using webid:[guid]), I get the results I'm after, but I would really rather not hard-code guids like that.
sourceId='{source GUID}'
? I kept getting Bad Request's, and it turned out I forgot the single quotes around the GUID.