Community Documentation

Search: an internal site search system

Last updated April 29, 2010. Created by aj045 on December 18, 2003.
Edited by jhodgdon, LeeHunter, Damien Tournoud, AjK. Log in to edit this page.

The search module lets users search for specific content on your site. You can search both for users and for particular words. When you are on the "content" tab of Search, you will be able to search for words appearing in the default rendering of node content on your site, which would include the default rendering of any CCK fields, Location fields, Taxonomy, etc., as well as comments. When you are on the "users" tab of Search, you will be able to search the user names of registered users on your site, and if you have sufficient permissions, also their email addresses.

In Content 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 in Drupal 7; administer >> site building >> modules in earlier versions of Drupal).

Note that by default, content search only finds exact matches for the keywords in your content. You can install a contributed stemming or n-gram module to modify this behavior.

Indexing

Drupal's search engine indexes the text content of the nodes on your site. 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 in Drupal 6 and earlier versions; in Drupal 7, you need to visit the Status Report to find the exact URL to use on your site for external runs of cron, because there is a suffix on the URL.

Whenever a visit to the cron URL 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 >> site configuration >> search settings in Drupal 6, or administer >> configuration >> search and metadata >> search settings in Drupal 7) 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.

Reindexing content

Content-related actions on your site (creating, editing, or deleting content and comments) automatically cause affected content items to be marked for indexing or reindexing at the next cron run. When content is marked for reindexing, the previous content remains in the index until cron runs, at which time it is replaced by the new content.

Unlike content-related actions, actions related to the structure of your site do not cause affected content to be marked for reindexing. Examples of structure-related actions that affect content include deleting or editing taxonomy terms, enabling or disabling modules that add text to content (such as Taxonomy, Comment, and field-providing modules), and modifying the fields or display parameters of your content types. If you take one of these actions and you want to ensure that the search index is updated to reflect your changed site structure, you can mark all content for reindexing by clicking the "Re-index site" button on the Search settings page (administer >> site configuration >> search settings in Drupal 6, or administer >> configuration >> search and metadata >> search settings in Drupal 7).

Accessing Search

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 >> site building >> blocks in Drupal 6, and administer >> structure >> blocks in Drupal 7) there's also a Search form you can enable, and you can choose where you want it to display.

On your permissions page (administer >> user management >> permissions in Drupal 6, or People >> Permissions in Drupal 7) 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.

Comments

Search enhancements

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

Use of AND and OR in Regular Search

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".

Search does not retrieve text contained in blocks

Hi, I just found out that, when searching for keywords that are contained in blocks text, no results are found.

For example, in my site I have a side bar block containing the list of products, that I display on each product image gallery.

When I look for words "veneziane per interno" which are contained in this block, no result is displayed.

Search works normally when I look for text contained in pages.

Can anyone help me?

Thank you

As far as I know, the search

As far as I know, the search function searches node content. So, no, it won't find block content. You may need an external solution for this.

What about titles in forum posts?

I have newest drupal 6, and right out of the box search can't find text in the title of a forum, unless the forum has at least one post in it that contains the key phrase. Check it out: http://animalnepal.org/drupal_hum id= tester , pw = tester but I guess as said, it just searches node content? huh? Cheers,
jigs

From www.phoenixstudios.com.np, A Small A/V Studio in Kathmandu Nepal

I have a similar issue.

I have a similar issue. I wonder if it is something that can be changed in the Site Configuration/Search Settings?

Hi:

I just confirmed that my cron is working fine and my search_index table has keywords and relevancy values from a node I just added.

BUT, when I try to search using the search form on a site page for something I SEE in the search_table, I get 0 results. How can this be? And, how do I fix it?

For example, here's what I see in my phpmyadmin in search_index when I search for "gaida":

word sid type score
gaida 2 node 1

BUT, this is what I get when I search in the site itself: http://www.bigbearhorrorfilmfest.com/search/node/gaida

Thank you,
~Todd

.

Same problem here. Reindexing did not help neither. User permissions correctly set. See also this forum post

Search not working

Do you have status on Drupal out-of-the-box searching?

it doesn't work.

Similar problem

I am also experiencing a similar problem. I have imported a number of images using the image module yet i cannot search for the images by name using the search module. I have reindexed the site and also done a number of cron runs yet nothing. Any idea what i could be doing wrong.

Search setup

Is it possible to search only within a section of pages?

For example- if in "mysite.com/town1" only search "/town1" pages - "mysite.com/town2" and only search "/town2" pages and so on...

Same

Titles are not searched, only content

You will have to try this module

nobody click here