Book Image

Drupal 7 Cookbook

By : Dylan Spencer James
Book Image

Drupal 7 Cookbook

By: Dylan Spencer James

Overview of this book

<p>Drupal 7 is a modern Content Management System famed for its flexibility and power. Using Drupal you can easily create custom functionality that would otherwise have to be purchased in many of the other leading CMSs.<br /><br />"Drupal 7 Cookbook" is filled with recipes to help you to do more with Drupal and improve your skills. Chapters range from content creation, to theming, to managing your site. You will learn how to create your own content types and use them to create Views, Blocks, and Pages. This book will take you from novice to pro in just 12 chapters.<br /><br />In a wide variety of practical recipes, you will learn how to work with views and panels, how to provide translations for your content to create a multilingual site, and to integrate your site with social media. You can develop the Zen starter theme or learn how to create custom cross-browser compatible Drupal themes, including themes for mobile devices. The Drupal 7 Cookbook contains all of the means necessary to take your skills from those of a novice Drupal user to a proficient site builder.</p>
Table of Contents (18 chapters)
Drupal 7 Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface

Setting up site search


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.

How to do it...

  1. 1. Log in to your site and select Modules from the admin menu.

  2. 2. Locate the Search module, which is under the Core category, and make sure the checkbox is selected.

  3. 3. To enable the module, scroll to the bottom of the page and click on Save configuration.

  4. 4. Select Configuration from the admin menu.

  5. 5. Select Search settings from the SEARCH AND METADATA category.

  6. 6. Under INDEXING THROTTLE leave the Number of items to index per cron run at 100.

  7. 7. Under the INDEXING SETTINGS leave the Minimum word length to index as 3 and leave Simple CJK handling checked.

  8. 8. Under Active search modules ensure that Node and User are checked.

  9. 9. Under Default search module ensure that node is selected.

  10. 10. Under CONTENT RANKING set Keyword relevance to 1.

  11. 11. Click on Save configuration and close the admin panel when the save is complete.

  12. 12. To place the Search form in the header, select Structure from the admin menu.

  13. 13. Select Blocks from the Structure menu to go to the blocks management page.

  14. 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. 15. Scroll down the page and click on Save blocks.

How it works...

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.