locked
Search Webpart to Restrict to a Document Library RRS feed

  • Question

  • How do you restrict a search web part to only search the contents of a particular document lbrary? I have a web page with a document library web part added to it. I want to add a search box to the page that only returns results from the document library on the page. This would be similar to how a document library search works when you navigate directly to the library and see the search bar in the top right.

    I hope this is a simple question and I thank you in advance!

    Friday, November 18, 2011 9:34 PM

Answers

  • You can use the OTB managed property called "path" for this.

     The idea is that  you will append an additional statement to each query from this search box.  The extra query will look something like this:

    path:sitename/doclibraryname

    This query says "return all items where the path contains sitename/doclibraryname"

     There are multiple ways to implement this.

    1. On your search box we part add this query to the "Additional Query Terms" section of the config panel.  Then check the "Append Additoinal Terms to query" checkbox.
    2. On your Core Results web part add the query to the "Append Text to Query" section of the config panel.
    3. Create a custom scope with this query and apply the scope to the core results web part on your destination page.

    Paul Olenick SharePoint/FAST Architect , MCTS http://olenicksharepoint.wordpress.com/
    • Proposed as answer by Steve.Curran Saturday, November 19, 2011 4:21 AM
    • Marked as answer by epistrophy25 Monday, November 21, 2011 6:43 PM
    Saturday, November 19, 2011 1:14 AM
  • You could add a Search Core Results web part on the same page. 

    Then configure your search input box to point to the same page (I think it's under Miscelaneous or Advanced).


    Paul Olenick SharePoint/FAST Architect , MCTS http://olenicksharepoint.wordpress.com/
    • Marked as answer by epistrophy25 Monday, November 21, 2011 8:26 PM
    Monday, November 21, 2011 7:43 PM
  • The refiners are added as a separate web part.  See here for a description:

    http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2010/03/15/get-to-know-the-refinement-web-part-in-sharepoint-2010-enterprise-search.aspx


    Paul Olenick SharePoint/FAST Architect , MCTS http://olenicksharepoint.wordpress.com/
    • Marked as answer by epistrophy25 Tuesday, November 22, 2011 9:02 PM
    Tuesday, November 22, 2011 2:45 AM

All replies

  • You can use the OTB managed property called "path" for this.

     The idea is that  you will append an additional statement to each query from this search box.  The extra query will look something like this:

    path:sitename/doclibraryname

    This query says "return all items where the path contains sitename/doclibraryname"

     There are multiple ways to implement this.

    1. On your search box we part add this query to the "Additional Query Terms" section of the config panel.  Then check the "Append Additoinal Terms to query" checkbox.
    2. On your Core Results web part add the query to the "Append Text to Query" section of the config panel.
    3. Create a custom scope with this query and apply the scope to the core results web part on your destination page.

    Paul Olenick SharePoint/FAST Architect , MCTS http://olenicksharepoint.wordpress.com/
    • Proposed as answer by Steve.Curran Saturday, November 19, 2011 4:21 AM
    • Marked as answer by epistrophy25 Monday, November 21, 2011 6:43 PM
    Saturday, November 19, 2011 1:14 AM
  • You can use the OTB managed property called "path" for this.

     The idea is that  you will append an additional statement to each query from this search box.  The extra query will look something like this:

    path:sitename/doclibraryname

    This query says "return all items where the path contains sitename/doclibraryname"

     There are multiple ways to implement this.

    1. On your search box we part add this query to the "Additional Query Terms" section of the config panel.  Then check the "Append Additoinal Terms to query" checkbox.
    2. On your Core Results web part add the query to the "Append Text to Query" section of the config panel.
    3. Create a custom scope with this query and apply the scope to the core results web part on your destination page.

    Paul Olenick SharePoint/FAST Architect , MCTS http://olenicksharepoint.wordpress.com/

    Great, thank you! Option 1 is exactly what I need.
    Monday, November 21, 2011 6:44 PM
  • Is there a way to get the search results to show up in the same page as where the search web part is located?
    Monday, November 21, 2011 6:44 PM
  • You could add a Search Core Results web part on the same page. 

    Then configure your search input box to point to the same page (I think it's under Miscelaneous or Advanced).


    Paul Olenick SharePoint/FAST Architect , MCTS http://olenicksharepoint.wordpress.com/
    • Marked as answer by epistrophy25 Monday, November 21, 2011 8:26 PM
    Monday, November 21, 2011 7:43 PM
  • Awesome! Thank you!

    Monday, November 21, 2011 8:26 PM
  • Also, is there a way to add the "Search Refinements" drilldown to the Search Core Results web part? I couldn't find a way of doing that inside the webpart.
    Tuesday, November 22, 2011 12:42 AM
  • The refiners are added as a separate web part.  See here for a description:

    http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2010/03/15/get-to-know-the-refinement-web-part-in-sharepoint-2010-enterprise-search.aspx


    Paul Olenick SharePoint/FAST Architect , MCTS http://olenicksharepoint.wordpress.com/
    • Marked as answer by epistrophy25 Tuesday, November 22, 2011 9:02 PM
    Tuesday, November 22, 2011 2:45 AM
  • Thank you! (again of course!)
    Tuesday, November 22, 2011 9:02 PM
  • I'm trying to use the "Append Text to Query" option to restrict the results from an advanced search webpart. But when the page loads the screen is displaying all documents in the search path.  Is there any way to prevent the search executing until the user enters the search criteria and clicks the search button?
    Tuesday, August 7, 2012 10:22 AM