How do I code a custom search page to search current site and sub-sites only in SharePoint 2007?
Users of our SharePoint-2007 Portal will have the ability to create their own site and sub-sites. These sites will be searchable but the search will be limited to the site and sub-sites if any.
I am trying to develop a custom search page with its own code be开发者_如何学Chind logic (c#) and custom UI. This custom search page will be part of the site template. I am not sure what is the best way to go about coding the search page and the site template. What scope do I use? Do I need to create a new scope every time a user creates a site? The out of the box SharePoint search page has a scope dropdown with the option "This Site". But I don't see that scope in the list of scopes under Search Administration. Any help or pointers are most welcome. Thanks in advance.
"This Site" and "This List" scopes are not true scopes. They represent functionality that is built in to the MOSS search code. Those "scopes" are invoked via special querystring parameters (i.e. property filters).
By default when you perform those searches, it redirects to a page called OSSSearchResults.aspx that looks like part of the local site. Take note of the querystring parameters:
k=<search_terms>
: Keyword(s), the terms you're searching for.cs=This%20Site
: Contextual scope, the scope you want to use (can also useThis%20List
).u=<site_url>
: Url, the site you want to constrain the search results to.
When we built our intranet portal, we created a customized Search Center. It handles enterprise search tasks, but if you pass it the same parameters noted above, it will also provide the Site- and List-scoped searches. In this way, we're able to have one central place to provide search functionality, one place to customize/style, and all of our searches look and behave in the same way.
In each site, as part of our page layout, we have a search box specifically for "This Site". When you search from it, we simply POST
the appropriate parameters back to our search center, and there you have it.
精彩评论