Search module: an internal site search system

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.

Search Query Types

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

AND Searches
To get results that 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 that may contain one of a few terms, but not necessarily all of the terms, enter the keyword OR between each search term: "dogs OR cats" or "dogs OR cats OR birds".

Note: The keyword "OR" must be capitalized. The search module will treat the lowercase "or" as another word to find. Because "or" is smaller than the default search word length (3 characters), the search module will ignore "or" to create an "AND" search instead.

Exclusionary Searches
You can even filter for things that don't exist. For example, if you want to find pet stores that 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".

Advanced Search
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 modify the way this is done.

The search engine indexes 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 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.)

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 do not have it, ask your systems administrator to make sure it's granted to you.

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.

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

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

Add the block content into the node, but hide this from the teaser / full display modes.
Add this content it to the search display modes
Using CCK Field Blocks or a related module, add the content to the block.

Note that this only works if the block is limited to the page that contains the node.

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.

How does one disable a wildcard search (Drupal 6 Search module). Or put another way - is it possible to prevent wildcard searches and deliver only what is searched for, or a "not found" message?
thanks

OK so my company has a few outside contractors who operate within our building. Specifically, there is a gift shop, a cafe, and a souvenir photo booth. As they are not part of my company, they have their own websites that I do not manage. Occasionally, a visitor to our site will try to find information about one of these contractors via the search function. They do not appear in the search because they are separate from us and I have no nodes for these contractors. My question is, can I configure the search function to include these three websites?

I know a quick solution would be to create a quick node with links to the three of these contractors, but I think it would be better if the websites just appeared in the search queries. is there a module that can allow this? Can I configure search to find these specific three sites?

Hi Alan,
I can't figure out how to make this thing work : I've done what you told me in the one sentence tut :) so now i can make more precise search on the custom fields of my custom type, but the problem is the AND/OR filter criteria logic. It's not working in case i do not insert data ( i.e. i have a Group1 filters all in OR logic , and if i do not insert any data in this Group1 than is FALSE => (Group1)AND(Group2)=FALSE ) ... If i use everywhere the OR than i get to much general results, if i use AND i get no results. What i'm missing here?

On the site http://www.forniturealberghiere.tv/ I discovere today that the table search_index was eating so many searches that now it eached more of 200mb!
1) How I can get it into a strong diet? It's simplyenough to delete all reords of the table or bettr to take care about something else?
I have also checked that from this custom theme I can't hide the search box from blocks administration.
2) Is there a way to limit the log of searches or something like that?

Search sometimes returns one "Anonymous" user row, sometimes none, sometimes more than one.
Each Anonymous row links to the http://site/user/ url
I looked in phpmyadmin and I could find only 1 anonymous user, as expected.

I've found the culprit in my case, is that we were using the Backup and Migrate module for ease of export/import data from local to live. By default, it was set to ignore 2 tables search_index and search_data. We now do not ignore these and everything is good.

I have search enabled on a couple of production sites and although I have Chinese and English content on the sites (which are 100% indexed), I only receive search results for English searches.

Strangely, I also have a local install of Drupal which returns results in both languages so I'm wondering if it's something at the server level that could be causing this? I have Drupal installed on IIS6.

Has anyone experienced any similar issues or have any idea what the problem could be?

I have a multilingual site using i18n. Searching a taxonomy term doesn't give the same result as searching using its translation, meaning that my taxonomy terms are not indexed the same way as its translation. Does anyone has a clue on how to resolve that ?