Search: an internal site search system

Last modified: January 18, 2009 - 18:55

The search module lets users search for specific content on your site. You can search both for users and for particular words.

With a regular search, if you enter more than one search term the search module will look for content that has all the terms you've entered. If instead you want either one term or another, join your terms with "or." If you're looking for an exact phrase, enclose it in quotation marks.

With Advanced Search you can also look for "any of these words" or "this phrase," or both, you can rule out words you don't want, and you can choose content types within which to confine your search.

You can enable the search module on the modules page (administer >> modules).

Drupal's search engine indexes the text of your site and the names of your users. You can tweak the way it does this.

The search engine does its indexing at intervals you choose by setting "cron runs." Cron (which stands for chronograph) is not a part of Drupal. It's a scheduler that resides on your server and runs tasks (called "cron jobs") at intervals, which you specify. The jobs can run weekly, daily, hourly, or whatever you like.

What you want to do is schedule a "cron job" that has a browser on your server regularly visit your "cron page." For instance, if your site were www.example.com your cron page would be http://www.example.com/cron.php. (This page is automatically set up for you when you install Drupal.)

Whenever such a visit occurs, the search engine will take up the work of indexing. You need to set up those cron runs before your search engine will work.

For a modest personal site to which you post now and then, you might set up such a cron job to run once a day. For a more active site you'd likely want to run that job more often--perhaps every few hours or every hour.

With Linux or Unix you can schedule your cron jobs by setting up what's called a "crontab." (You might rely on helper programs like C-Panel to make setting up your cron jobs easier.)

For further guidance on cron you can see Drupal's handbook page configuring cron jobs (or, if your server is running Windows, configuring Windows cron jobs). Your hosting company may also help guide you.

On your settings page for Search (administer >> settings >> search) you can limit how many items should be indexed in a single cron run. This can help keep your system from getting overloaded with work. (If you get a message that cron is timing out or PHP is running out of memory, lower the number of items to index per run.) You also have a few more search settings you can choose.

If both the search module and the menu module are enabled, from the menus page (administer >> menus) you can enable on the Navigation Menu the item Search. The option to show this menu item may be disabled by default, but you can enable it. (And you can rename "Search" to whatever you wish.)

You can also place a link to Search among your site's primary and secondary links, or on any other menu as well. (Click "add menu item," and when you fill in the "path" field on the dialogue page just enter "search.")

On your blocks page (administer >> blocks) for most themes there's also a Search form you can enable, and you can choose where you want it to display.

On your access control page (administer >> access control) you can decide who can do searches and who can administer the search settings. By default, anonymous users cannot perform searches.

A technical note: To use the search module the database user needs the create temporary table permission. If you seem not to have it, ask your systems administrator to make sure it's granted to you.

You can

  • read about how your site uses cron in the administer >> help >> system.
  • run your cron job manually at your sites cron page.
  • read about configuring cron jobs.
  • configure search at administer >> settings >> search.

Search enhancements

grn - July 30, 2008 - 06:18

Enhancements for the core search engine:
Porter-Stemmer: http://drupal.org/project/porterstemmer

*EDIT* 2008-07-30 at the time I find the partial search patch for Drupal 6.3 core search very valueable (http://drupal.org/node/103548#comment-880849)

/grn

This core search engine can not find CCK?

emas - December 11, 2008 - 15:02

This core search engine can not find contens created by Content Construction Kit (CCK) 6.x-2.1?

Emas, the core search engine

aufumy - December 12, 2008 - 23:17

Emas, the core search engine should work fine with the cck module. If you are having an issue, search all open issues and if none found related to your problem, create a new issue.

http://drupal.org/project/issues/cck

Search comments?

Vako - April 30, 2009 - 19:21

Can we configure the search to search comments as well?

How to exclude single pages/nodes from being indexed?

balabushka - May 13, 2009 - 12:51

Do I have to hack the module? Or is there any other chance?

Use of AND and OR in Regular Search

DeeZone - May 28, 2009 - 15:54

I find the paragraph in the text in the handbook page above vague.

With a regular search, if you enter more than one search term the search module will look for content that has all the terms you've entered. If instead you want either one term or another, join your terms with "or." If you're looking for an exact phrase, enclose it in quotation marks.

I would suggest the following based on the text in the excellent article by CivicActions.com: http://civicactions.com/blog/search/part_2

Search Query Types

Search queries can be done in a variety of different ways. Drupal's search allows the user create very powerful search by merely adding a few key words or symbols.

AND Searches

To get results which match multiple words, simply type the words that you want to find. This is the default behavior of Drupal's search.

OR Searches

To search for data which may contain one of a few terms, but not necessarily all of the terms, you need an OR search. Use the keyword OR in between each search term: "dogs OR cats" or "dogs OR cats OR birds".

Notice that the keyword "OR" must be capitalized. If you use the lower case "or" instead, search module thinks that this is another word to search for, and since it is probably smaller than the search word length (the default is 3 characters), search module simply ignores it and does a "AND" search on the two words.

Exclusionary Searches

You can search for things that don't exist. For example, if you wanted to search pet stores which do not have chickens, you need an exclusionary search. Drupal allows you to do this using the minus "-" sign. For example "pet stores -chickens" finds all nodes with "pet" and "stores that do not also contain the words "chickens".

does anyone know how to make

khawkc - June 5, 2009 - 18:06

does anyone know how to make those content in blocks can be searchable?

 
 

Drupal is a registered trademark of Dries Buytaert.