Search Content Within List / Library Using Customsearch Webpart In Sharepoint

In this article, you will learn how to search content within a list or library, using CustomSearch Webpart in Sharepoint.

Introduction

CustomSearch Webpart is a generic webpart to search the document/item and content inside it from the document library/list. The search result displays in a popup with a link to the item/document. Clicking on the link will open in a new tab.

Prerequisites 

  1. Search must be configured in the Server and one content source should have been created.
  2. In case we add or edit any item/document to the list/Document Library, Full crawl or Continuous crawl must be started and completed.

Configure Webpart

After adding the Webpart to the page, we need to configure the Webpart properties. Webpart is having only 3 properties, as given below, to filter the data. Please find the screenshot, given below, to set the properties.


 

  1. List/Document Library name (Ex – AlertHome).
  2. Search Query (Ex - DatePublished<=Today and ExpirationDate>=Today).
  3. Columns names to display in the search result (Ex - Title,DatePublished,ExpirationDate).

    Value(Example for list)List/Document Library nameTestDoc
    DatePublished<=Today AND ExpirationDate>=TodayColumns name to display in search resultTitle,Status
Note 
  1. Query in “Search query” property is optional. In case we want to configure the query, then it should match the condition of the default view of list/Library.
  2. The column names configured in “Columns name to display in search result” property must be managed properties.
  3. Even if we don’t mention any column in “Columns name to display in search result” property, search results will display the title of the item/document.

To create managed property

For example, we will create a managed property for a Status column.

 Managed Property Crawled Property
 Status ows_TestStatus

Open central admin with run as an administrator > Manage Service Applications > Click Search Service Application. 

  • Click Search Schema under Queries and results.
     
  • Click New Managed Property.

 

  • In New Managed Property window, add the Property name, Description, type of information in this property, check searchable, check Queryable, check retrievable.

  • In Mapping to crawled properties section, click Add a mapping.
  • In Crawled property selection window, select SharePoint from Filter on a category dropdown list. Search a crawled property that you want to map with. Select the property and click OK. Click OK again from the main window.