When you search within a SharePoint site, you expect results from only that site. But sometimes the search results include items from other sites in the same tenant. This happens because SharePoint search scopes are not limited to the current site by default. In this article, you will learn how to set the search scope to the current site using the Search Box web part property. You will also see how to create a custom search result page that shows only content from the specified site.
Key Takeaways: Limit Search Results to a Single SharePoint Site
- Search Box web part > Scope property: Set to “This Site” to restrict results to the current site collection.
- Search Results web part > Query property: Use the
siteoperator (e.g.,site:https://tenant.sharepoint.com/sites/siteA) to filter results to a specific site. - Custom search results page: Create a dedicated page with a Search Results web part that contains the site-scoped query.
Why SharePoint Search Shows Results From Other Sites
SharePoint search uses a global index by default. When a user types a query in the Search Box web part, the search service queries the entire tenant index. This index contains all content from all site collections where crawling is enabled. The search box does not automatically limit the query to the current site.
The Search Box web part sends the query to the default search results page, which is usually the tenant-level search center. That search center page runs a query without any site restriction. As a result, users see results from every site they have permission to access.
To change this behavior, you must modify the Search Box web part scope or create a custom search results page that includes a site-scoped query. Both methods force the search to return only items from the intended site collection.
Steps to Set the Search Box Scope to the Current Site
The quickest method is to change the Search Box web part scope property. This setting tells the search box to send queries to a specific result source or to limit the scope to the current site. Follow these steps on any modern SharePoint site.
- Edit the page
Navigate to the SharePoint site where the search box appears. Click the Edit button in the top-right corner of the page. If you are on a team site, the edit button is on the command bar. On communication sites, click Edit at the top of the page. - Select the Search Box web part
Click the Search Box web part on the page. A toolbar appears above the web part. Click the pencil icon (Edit web part) to open the property pane on the right side of the screen. - Change the scope setting
In the property pane, locate the Scope section. The default value is “This site collection.” Change it to “This site.” The “This site” option limits results to the current site collection only. If the option is not visible, click the dropdown and select it. - Set the search result page
Below the scope setting, find the Search results page URL field. By default, it points to the tenant search center. To use a custom results page, enter the URL of a page you create in the next section. If you skip this step, the search box still uses the tenant search center and scope may not apply correctly. - Save and publish
Click Apply at the bottom of the property pane. Then click Publish or Republish in the top-right corner of the page editor.
After publishing, test the search box. Type a query that exists on another site. The results should show only items from the current site. If results from other sites still appear, the scope property may not be supported in your SharePoint version. In that case, use the custom search results page method below.
Create a Custom Search Results Page With Site-Scoped Query
A more reliable method is to create a dedicated search results page that contains a Search Results web part with a query that filters by site. This method works in SharePoint Online and SharePoint Server 2019 or later.
- Create a new page
Go to the SharePoint site where you want the search results to appear. Click Settings (gear icon) > Add a page. Give the page a name like “SiteSearchResults” and click Create. - Add the Search Results web part
On the new page, click the plus sign (+) to add a web part. In the web part picker, search for “Search Results” and select it. The web part appears on the page with default settings. - Edit the query
Click the Edit web part icon (pencil) on the Search Results web part. In the property pane, click the Query button. A dialog box opens. In the Query text field, replace the default query with your site-scoped query. - Write the site-scoped query
Use thesiteoperator followed by the full URL of the site collection. For example:{searchboxquery} site:https://contoso.sharepoint.com/sites/Sales
The{searchboxquery}variable inserts the user’s typed search term. Thesite:operator restricts results to that site. Replace the URL with your site’s URL. - Save the query
Click OK to close the query dialog. Then click Apply in the property pane. Publish the page. - Point the Search Box web part to this page
Go back to the page with the Search Box web part. Edit that web part and set the Search results page URL to the URL of your new custom search results page. Save and publish.
Now when a user searches from the Search Box web part, the query goes to your custom page. The Search Results web part on that page filters results to the specified site only. This method works even if the scope property on the Search Box web part is ignored.
Common Issues When Restricting Search Results to a Single Site
Search Box web part does not have a scope dropdown
In some modern SharePoint sites, the Search Box web part property pane does not show the Scope section. This happens on team sites connected to a Microsoft 365 group. The scope setting is hidden because the web part relies on the default search center. In this case, you must use the custom search results page method with a site-scoped query.
Search results still show items from other sites after setting scope
If you set the Search Box scope to “This site” but results still come from other sites, the Search Box web part may be sending queries to the tenant search center instead of a custom results page. Verify that the Search results page URL in the Search Box web part is set to your custom search results page. If it is still pointing to the default search center, the scope setting is ignored.
Site-scoped query returns no results
A query with the site: operator returns no results if the site URL is incorrect. Make sure you use the full site collection URL, not the root URL of the tenant. For example, use site:https://contoso.sharepoint.com/sites/Sales instead of site:https://contoso.sharepoint.com. Also check that the site has been crawled by search. If the site is new, wait a few hours for the crawl to complete.
Search results include items from subsites
The site: operator includes content from all subsites within the site collection. If you want to exclude subsites, use the path: operator instead. For example:{searchboxquery} path:https://contoso.sharepoint.com/sites/Sales
The path: operator restricts results to the exact folder or site, excluding subsites.
Search Box Scope: Default vs This Site vs Custom Query
| Item | Default (Tenant Search) | This Site Scope | Custom Query (site: operator) |
|---|---|---|---|
| Results scope | All sites in the tenant | Current site collection only | Single site collection by URL |
| Setup effort | None | Change one dropdown in web part | Create a new page and edit query |
| Works on all modern sites | Yes | No (hidden on group-connected sites) | Yes |
| Supports subsite exclusion | No | No | Yes (use path: operator) |
| Requires custom results page | No | No | Yes |
Use the custom query method if you need precise control over which site is searched. Use the scope dropdown if your site supports it and you only need to limit results to the current site collection.
Now you can prevent site search from returning results from other sites. Start by checking whether the Search Box web part on your site supports the scope dropdown. If it does, change the scope to “This site.” If not, create a custom search results page with a site-scoped query. For advanced control, use the path: operator to exclude subsites from the search results.