In this recipe, we will see how to configure Drupal's native site search. The search feature is a part of the Drupal core module set. We will start by enabling the module, and then proceed to set up the search index. Finally, we will move the search block to the header.
1. Log in to your site and select Modules from the admin menu.
2. Locate the Search module, which is under the Core category, and make sure the checkbox is selected.
3. To enable the module, scroll to the bottom of the page and click on Save configuration.
4. Select Configuration from the admin menu.
5. Select Search settings from the SEARCH AND METADATA category.
6. Under INDEXING THROTTLE leave the Number of items to index per cron run at 100.
7. Under the INDEXING SETTINGS leave the Minimum word length to index as 3 and leave Simple CJK handling checked.
8. Under Active search modules ensure that Node and User are checked.
9. Under Default search module ensure that node is selected.
10. Under CONTENT RANKING set Keyword relevance to 1.
11. Click on Save configuration and close the admin panel when the save is complete.
12. To place the Search form in the header, select Structure from the admin menu.
13. Select Blocks from the Structure menu to go to the blocks management page.
14. Search through the blocks list to find the Search form block and set its position to header by updating the drop-down menu.
15. Scroll down the page and click on Save blocks.
The site search works by periodically indexing the pages of a site. The indexing is activated by a cron job at a predetermined interval.
Cron is the process that periodically activates tasks such as search indexing, checking for updates, and clearing the cache. Drupal 7 has its own method to periodically call the cron script; however, it's more preferable to call Drupal's cron script directly from the server by setting up a crontab for optimum performance.
It is important that you ensure that the cron is configured to run at a suitable interval. If you have lots of frequently changing content, then you will want to configure the cron to run more frequently, or less frequently if your content changes rarely. It's a trade-off between server load and search results freshness.
The Indexing status category on the search configuration page displays the percentage of content indexed. This indicates how much of the eligible content is indexed for the search function. Don't worry if your content isn't immediately indexed. The indexer is configured to only index a finite number of pages per cron run. The number of pages indexed per run is set in the Indexing throttle category. You must be careful that the throttle is not set so high that it can overload your server.
You can manually activate the cron job, and therefore, activate the search indexing procedure, by going to Configuration | Cron | Run cron.
The Content ranking option will determine the prominence of each of the listed factors; a weight of 0 being no prominence and a weight of 10 being highest prominence. The actual settings that you choose for this should depend on the type of search results you or your organization favor.
The search form block will be set to display in the first column by default. Moving it to the header is just a personal preference, with the added purpose of demonstrating how easy it is to move the block.