Custom Search Module for Drupal

tutuploadsmedia_1332978557735.png

The Drupal core provides a Search module that is great for many sites. However, it doesn’t provide some of the more sophisticated features that some sites need. The Custom Search module is a good alternative if you want more control over what gets searched, who gets to search, and what results you see.

The Custom Search module adds layers of control and sophistication to the core search module. It’s easy to install and will give you more control over the search functions on your site. It also integrates with other search modules and APIs.

The Core Search function and the Custom Search module

tutuploadsmedia_1332978557735.png

The basic elements of the core search module are:

  • A block for front-end display. There is very little configuration available for this block. I’ve named this one “Core Search Block” to make it easy to distinguish from the customized one We’ll be creating.
  • Advanced search is available on search results page. If a user clicks Advanced Search on the results page, a form opens up so you can refine your search. (When using the Garland Template).

This gives you a sophisticated search, but little control over how it’s implemented throughout the site. A good way to expand on this is to add the Custom Search Module. Here’s a summary of the added options.

Basic options:

  • Select which content type(s) to search,
  • Select which specific module search to use (node, help, user or any module that implements search),
  • advanced criteria

Advanced options:

  • change the default search box label,
  • add a default text in the search box,
  • add advanced search criteria,
  • change the default submit button text,
  • use an image instead of the submit button,
  • change the order of all the elements,
  • include some elements in a popup block,
  • add a filter to the results page,
  • show/hide basic and/or advanced search in the results page,
  • show/hide meta data in the results page,
  • multiple search paths

Step 1. Download and install the module

Step 2. Enable the module and its sub-modules

tutuploadsmedia_1332974776069.png

There are three included sub-modules:

  • Custom Search Taxonomy: taxonomy options for the search block.
  • Custom Search Blocks: provides additional search blocks, with different settings.
  • Custom Search Internationalization.

Step 3. Set Permissions for users and administrators

tutuploadsmedia_1332974833304.png
  • The confirmation message will have a link to the permissions. Click it to go directly to the permission settings.

tutuploadsmedia_1332975091365.png
  • Set user and admin permissions for two modules. I wanted everyone to be able to search so I gave anonymous users and authenticated users permissions by checking the boxes
  • You have four sets of permissions to set. 
    • Custom Search
      • Admin
      • User
    • Custom Search Blocks
      • Admin
      • User

Step 4. Configure the module

tutuploadsmedia_1332975243521.png
  • Return to the Modules page and click Configure. You can also get to the configuration screen by going to Configure > Custom Search

 

tutuploadsmedia_1332975841984.png
  • When you land on the configuration page the selected tab will be highlighted. You will be going through all the tabs to complete the full configuration. So when you complete the first page, choose another tab and continue
  • I’m not going to go through every single configuration step. The choices are easy. If you have a need to create refined searches, they will make sense to you. If not, trial and error is the best way to get familiar with them. In this demo I’m going to enable everything.
  • There is one section that may need a little explanation – the Search Blocks tab:

tutuploadsmedia_1332981680985.png
  • Select the number of blocks. One of the great things about this module is that every block can have it’s own configuration settings. Suppose you wanted a block on the home page that searched the entire site, but not the forum. On the forum page you want a block that only searches the forum. In that case you would create two blocks. If you wanted anonymous users to be able to search just some forum topics, and registered users to have more option, you would create 3 blocks, and control which one shows by who’s logged in.
  • I’m just going to create one for this demo. Once you decide on this, add blocks to your site.
  • Be sure to save before moving on.

Step 5. Add blocks to your site

tutuploadsmedia_1332982028297.png
  • Go to Structure > Blocks.

Step 6. Assign blocks to regions

tutuploadsmedia_1332976654551.png
  • The custom search blocks you created will be visible and numbered.
  • Choose the regions for the blocks.

tutuploadsmedia_1332982219714.png
  • The new block is added.
  • The original block created by the core is still there. It’s default label is Search Form. I can’t think of a reason why you would want both of them on the same page unless you’re writing a tutorial, so you can remove the original if you want.
  • Be sure to Save Blocks before you try any configuration.

Step 7. Customize the blocks from the front end

tutuploadsmedia_1332982785885.png

Here are both blocks, the original core search block and the one I just added. Compare the look of the Core one with the first image. You’ll see that some custom features have been added. The first picture just shows an entry field and a search button. Now we can search tags and forums. This is because the new module makes those capabilities available to all the modules.

It also makes customization very simple. When you are viewing the module from the front end, mouse over the title and you will see an icon that looks like a cog from a gear.

tutuploadsmedia_1332983164241.png

This will give you access to the configuration for this particular module. It makes it much simpler if you are going to have multiple search boxes with different types of search. You can define each one while you are on it’s page. It saves time and prevents mistakes.

Step 8. Configure Visibility

tutuploadsmedia_1332983345582.png
  • Clicking Configure will allow you to change the visibility and normal block function.

tutuploadsmedia_1332977044916.png
  • Clicking Custom Search configuration will give you access to define the search box itself.

Step 9. Configure each block to have custom features

tutuploadsmedia_1332983579145.png

From here you can configure what’s include and what type of search you want.

Result

tutuploadsmedia_1332983702278.png

Above you can see what the original search block looks like after I’ve configured some additional elements to show. This will allow you to present a highly customized search experience to your the public and authorized users.

 

Author

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x