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
- Search must be configured in the Server and one content source should have been created.
- 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.
- List/Document Library name (Ex – AlertHome).
- Search Query (Ex - DatePublished<=Today and ExpirationDate>=Today).
- Columns names to display in the search result (Ex - Title,DatePublished,ExpirationDate).
Value(Example for list) | List/Document Library name | TestDoc |
DatePublished<=Today AND ExpirationDate>=Today | Columns name to display in search result | Title,Status |
Note
- 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.
- The column names configured in “Columns name to display in search result” property must be managed properties.
- 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.