The process of building custom solutions for SharePoint Server.
Based on the details you shared, I understand that you are running into an issue with a SharePoint Advanced Search query. While your query successfully restricts search results to a specific folder path when executed from the main site collection, it fails completely when run from a subsite instead returning all folders, site assets, and documents from across the entire SharePoint environment.
The path filter you provided does not seem to account for the subsite hierarchy. If the target folder actually resides within a subsite, the search query must precisely match the absolute URL format indexed by SharePoint Search (e.g., including the /subsite/ segment). In SharePoint Search, KQL (Keyword Query Language) property restrictions only function correctly when using a valid, queryable Managed Property and exact syntax. If a path is malformed or missing the subsite context, SharePoint may fail to process it as a structured property restriction and instead treat the path string as general free-text keywords, causing the scope to explode to the entire farm.
Depending on your SharePoint Server version and crawl configuration, the Search Index might store the space character as an encoded %20 or as a literal space.
At first, the best approach is to encapsulate this logic within a Custom Result Source rather than relying on complex inline web part queries. If your environment supports it, the DocumentLink managed property is generally much more robust than Path for targeting folders.
-Create a Custom Result Source
Navigate to your subsite (or site collection) Site Settings > Under the Search section, click on Result Sources > Click New Result Source > In the Query Transform section, utilize a targeted query structure like this:
(DocumentLink:"https://serversite/subsite/Processos Troncal/*")
AND FileExtension:(docx OR doc OR xlsx OR xls OR pdf OR csv OR pptx OR jpg OR png)
AND IsDocument:1
AND (Title:{searchTerms} OR Tags:{searchTerms} OR Keywords:{searchTerms} OR Filename:{searchTerms} OR Description:{searchTerms})
Save the Result Source, and then configure your Advanced Search page or Search Results Web Part to use this newly created Result Source.
If DocumentLink is unavailable or does not return results:
Switch back to the Path property, but ensure you include the explicit subsite URL. It is highly recommended to isolate and test the path constraint by itself first before layering on the extensions and keywords.
Try using the full folder path with a wildcard mapping:
(Path:"https://serversite/subsite/Processos%20Troncal/*")
AND FileExtension:(docx OR doc OR xlsx OR xls OR pdf OR csv OR pptx OR jpg OR png)
AND IsDocument:1
AND (Title:{searchTerms} OR Tags:{searchTerms} OR Keywords:{searchTerms} OR Filename:{searchTerms} OR Description:{searchTerms})
Appending /* to the end of the DocumentLink or Path string ensures that SharePoint captures all nested files and items deep inside that specific directory structure. If the query still pulls global results, test variations of the folder string in a basic search box to observe how your specific crawl architecture has tokenized the folder name.
Using a dedicated Result Source combined with the full subsite path context will keep your query from breaking and prevent unmanaged assets from leaking into your results.
Hope this helps! Let me know if the query still acts up after adjusting the path.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.