It will be very useful for the users to have the search being suggested based on the past searches while they are typing in the search text box in a SharePoint search site. Yes I’m talking about the same concept that you find in the Google search but with a limited functionality.
This feature is available as an OOTB feature in SharePoint 2013 enterprise search. Look at this link to know more about this cool feature. The process is completely different though.
As you can see in the above image, as I type “I love s”, I get “I love SharePoint” and “I love Silverlight” as suggestions. These 2 are retrieved from a SharePoint list called “Search Keywords”.
So how and when are these suggestion keywords stored in the “Search Keywords” list? When a user is searching in the search site and the results page finished loading, the JS code added in the CEWP in the results page would add the search query in the “Search Keywords” list as new list item. Thus the matching suggestion keywords are retrieved from the list as the user is typing in the search text box later.
Since the suggestion keywords are added to a SharePoint list as a new list item every time a user searches, the performance may reduce when 1000’s of items get stored in the list. So it is advised to manually delete few keywords often from the list.
I have explained the code in two parts in the below blog posts:
Part 1: How to give the Auto suggestion/complete functionality to the Search box with search terms retrieved from a SharePoint list.
Part 2: How to store the users’ searched queries to a SharePoint list dynamically and then show them as suggestions in the search box while searching.
Since it is purely a client side application, we can simply deploy it by just moving the files. I assume that you have worked with Content editor web part before. You need to create 2 CEWPs, one for search home page and the other for the search results page. I have explained the deployment process through the below steps:
- Download the SPAutosuggestion.zip file and unzip it.
- Create a folder called SPAutosuggestion under the layouts folder of your SharePoint server.
- Copy the files jquery-1.7.js, jquery.ui.autocomplete.js, jquery.ui.core.js, jquery.ui.complete.js, jquery.ui.widget.js, and jquery-ui.CSS from the unzipped folder in to the above create folder.
- Go to your SharePoint search site and create a list called “Search Keywords”
- Go the search home page and edit the page.
- Add a Content editor web part in to the page.
- Click on “Click here to add new content” as shown in the below image:
- Now in the ribbon control click on HTML -> Edit HTML Source as shown below:
- In the HTML source editor window copy the content of the AutoSuggectionLandPage.js which would be present in the folder unzipped in step 1.
- Click on “Save & Close” under the page tab in the top ribbon.
- Go to the search results page of you SharePoint site and edit it.
- Repeat step 6 to 10. But instead of copying the content of AutoSuggectionLandPage.js, copy the content of AutoSuggestionResultsPage.js.
- Search with different queries twice or thrice to see them getting suggested as you type in the search text box.