1,691 articles and 12,619 comments as of Friday, September 10th, 2010

Monday, May 3, 2010

SharePoint: Search Lists and Document Libraries by Metadata

Guest Author: Peter Allen
BitsOfSharePoint

A while back I create a solution that would filter a list by the metadata, but would only do this for items and metadata viewable in the current list view.  Here are the original articles:

Thanks to all the good feedback and suggestions I have created another solution that will allow you to search any list by its metadata and will search ALL items visible or not.  Another feature I have added into this solution is that it can be placed on any pages and when the person searches it will taken them to results page. 

In order to do this we will need to have access to SharePoint designer and have permissions to edit with SharePoint designer.  SharePoint designer will be used to create a Data View Web Part where results will be displayed.

There are two main steps to create this search.

  • Create a Search Results page.
  • Add the Search Web Part to any page.

Let’s go over the process of creating a search page.

Create a Web Part Page.

Next edit it in SharePoint Designer.

Now add a Data View Web Part to a Web Part Zone.  To do this you will need to select the list or library from the Data Source Library.  The list or library you choose will be the one that is search with this solution.


Then select what the columns want to show. Also add them as a Multiple Item View.


When you save the file you will get a warning, don’t worry go ahead and say yes.


Next you will customize how the list is filtered.


Choose what fields you will filter on or have the search look through.


For the comparison make sure you select contains so that it is not an exact match.


Next for Value you are going to select Create a New Parameter.


Complete the parameter with the following:

  • Name: Search
  • Parameter Source: Query String (this is how it looks at the URL for the search criteria)
  • Query String Variable: Search


For each field/column that you want to search add another to the list and make sure the And/Or is set to Or.


When you click OK your list of items will disappear, but that is OK and is expected.


You are now done with the first major part.  If you want to customize the list more, feel free to do so.  To customize the Data View web part that has nothing showing just check the box under “Common Data View Tasks” called “Show with sample data”.

The last part is to load the Search Web Part.  This web part is one that I created and will need to be downloaded placed on any page of your SharePoint site.  I would add this to the Search Results page as well.

Search_List: http://www.bitsofsharepoint.com/ExamplePoint/CodeExamples/Search_List.dwp

Next edit the Web Part with the Rich Text Editor and change the following:

  • Search Results Location:  This should be the full URL of where the Search Results page you created with the Data View Web Part is.
  • Search Box Location: Designate if it will be on the left, center or right.
  • Search Title:  Name your search so that your end users know what they are searching.



Then save the changes and you should be able to search your list and view the results.

Here you can find a working example: List and Document Library Search

Guest Author: Peter Allen
BitsOfSharePoint

Peter Allen is President of BitsOfSharePoint Consulting LLC, based in Sacramento, CA. He has worked in the technology field for 15 years creating and deploying solutions in Healthcare, financial, construction, municipalities, telecom, and engineering firms.  He provides solutions that address site architecture, taxonomy, useability and findability.  He also speaks at SharePoint community events and blogs at his SharePoint site http://www.bitsofsharepoint.com.

 

Please Join the Discussion

21 Responses to “SharePoint: Search Lists and Document Libraries by Metadata”
  1. Francis Ong says:

    Thanks for the filtering solution but can this filter with items more than 100 items in a list view.
    Understand that Sharepoint got this limitation to only display 1-100 items in a list and the filter only take care of this 100 items within this view.

    Any solution to filter through all the items.

    • Peter Allen says:

      Francis,

      Yes, this solution will filter/search the whole list not just the 100 being viewed. My first solution, which I mentioned at the beginning of the article, only filtered what you were seeing.

      You should be able to follow the steps above, in this article, and have a solution that searches the whole list.

  2. Sam Cheung says:

    Thanks for sharing but as I am new to sharepoint, I get stucked when I come to “The last part is to load the Search Web Part. This web part is one that I created and will need to be downloaded placed on any page of your SharePoint site. I would add this to the Search Results page as well.”
    Could you clarify the statement?

  3. Peter Allen says:

    Sam,

    After you have edit the page in Designer, now open the page in IE so that you can edit and add the Web Part I created. The link is in the article.

    First download the web part to your hard drive, then edit the search page in IE and do an import a web part and load the web part you downloaded onto your computer.

    Once you add the web part I provided and configure it you can then do a search.

    Hope that helps.

  4. Ken Byrdwell says:

    Can this be modified to search more then one list? Like maybe 4 lists in the same site.

  5. Peter Allen says:

    Yes, I have done this for a client and it works well. Just follow the setups and apply it to the three other lists you add to the page. You will only need one Search Web Part to make it work.

    • Sam Cheung says:

      Thanks and I finally get to the search for 1 list. I wonder where can I put the remaining lists in as I failed to group them into 1 list for search.
      You have been helpful, Thank you very much!

      • Sam Cheung says:

        Oh I am able to search different lists by merging different lists into 1 big list now! But the list of items do not disappear. What should I do?

      • Peter Allen says:

        You would have 4 separate lists and would follow the same steps I outlined for each list. You should not have to combine them. Just adding the three other lists does not make them searchable. You have to add the list filter parameter to each one.

      • Sam Cheung says:

        I get your point and I can work them out now. However, I need to insert them into differnt ‘insert web part areas’. Anyway, I would not have done this without your help, thank you very much!

      • Arpit says:

        Sam,

        Can you explain me how it’s working for you, ‘coz i am having problem with this.
        i am trying to filtering and searching on document library.

        which is the best webpart for me to download ‘coz there is too many with different versions.
        help me.

  6. Chris Zeigler says:

    I’m having two issues with your solution as well. First, I’m getting an SSL warning each time I open the page with the Search_List webpart (I presume from the js bit). Any help on getting Sharepoint to accept that web part?
    Second, the search result is always blank. I had to do more than use only the Rich Text Editor for the web part you provided as it was still trying to reference your bitsofsharepoint.com site until I changed the URL within the Source Editor. I’m fairly new to Sharepoint Designer, but I feel like I followed the steps best possible.

    • Peter Allen says:

      Chris,

      Issue One: Not sure what the SSL issue would be. Are you access it with https://?
      Issue Two: By default the search page will be blank until you make a search. Just part of the way SP works with Data View Web Part when you are filtering based on a query string. Since it is blank to start with, it finds nothing and shows nothing. Once you put a search variable in it, it will show results.

      • Chris Zeigler says:

        1 – I am accessing it via https:// (we also have a redirect setup in case the user only does http://)
        2 – I have tried using the search. I added the piece you provided to the main page of the site, modified it to point to the Data View Web Part that you walked us through creating, but even with a search string in the search box it’s still coming up empty.

  7. IE browsers will pop up a security warning when content from an external source is being pulled into the page. Peter, is there something in the solutions that is pointing to an external script? — Mark

  8. Arpit says:

    hi
    i created webpart page. attached it with document lib, as you shown
    Now i download search webpart and import it on same page where i configure data view (webpart page which i created and customize in sharepoint designer) , now when i am going to edit search webpart by Rich Text Editior it shows me a
    Filter Box location
    value
    Help
    Options
    value
    Help

    But not Showing Like You Show in example so, where i have to put URL of search result page?

    Comment

  9. Siva Kesavulu says:

    Hi Pete

    you are life saver!!!! I have been pulling my hair to implement search option on Sharepoint list. Your solution worked perfect for me. When I see its working…..WOW!!!!!!

    Thanks a million
    Siva


Notify me of comments to this article:


Speak and you will be heard.

We check comments hourly.
If you want a pic to show with your comment, go get a gravatar!