Custom Search
Customizes the default Drupal search form with advanced options including content type filtering, taxonomy selectors, language filters, and customizable search paths.
custom_search
Overview
Custom Search is a powerful module that extends and customizes the default Drupal search functionality. It provides a highly configurable search block that allows site administrators to control every aspect of the search experience.
The module enables users to add content type selectors, taxonomy vocabulary filters, and language options directly in the search form, rather than requiring users to navigate to the advanced search page. All form elements can be displayed as dropdown lists, checkboxes, or radio buttons, and their order can be rearranged using a drag-and-drop interface.
Additional features include customizable labels and placeholder text, the ability to use an image instead of a submit button, advanced search criteria fields (OR, phrase, negative), and support for custom search paths with token replacement. The module also provides options to customize search results display, including content type filtering links.
Features
- Customizable search box with configurable label, placeholder text, hint text, size, and maximum length
- Submit button customization with text or image options
- Content type selector allowing users to filter searches by specific node types, with support for select, multi-select, checkboxes, or radio button display
- Content type exclusion to hide certain types from search results
- Taxonomy vocabulary filters with configurable depth, label, and selector type for each vocabulary
- Language filter allowing searches to be restricted to specific languages or the current language
- Advanced search criteria fields including OR (containing any words), phrase (exact phrase), and negative (excluding words)
- Custom search paths with token support for [key], [types], [terms], and [current_path] replacement
- Drag-and-drop ordering of all search form elements
- Popup region for hiding secondary options until the search field is focused
- Search results customization controlling display of content type, author, and date information
- Results filtering with content type filter links positioned above or below results
- Search API Page integration for using Search API as the search backend
- JavaScript enhancements for form validation, popup display, and checkbox handling
- Custom templates for search results and individual result items
Use Cases
Content-specific search for multi-type sites
On a website with multiple content types (articles, events, products, FAQ), use Custom Search to allow visitors to filter their search to specific content types. Configure the block to show content type checkboxes or a dropdown, letting users search only within their desired content category.
Taxonomy-filtered search for categorized content
For a site with content organized by taxonomy (e.g., topics, categories, tags), add vocabulary selectors to the search form. Users can search within a specific category or topic, such as finding all articles tagged with 'Technology' that contain their search terms.
Multilingual site search
On multilingual websites, enable the language selector to allow users to search within specific languages or restrict searches to the current interface language. This helps users find content in their preferred language.
Advanced search with criteria fields
Enable the OR, phrase, and negative criteria fields to provide power users with advanced search options directly in the search block. Users can search for pages containing any of certain words, an exact phrase, or excluding specific terms.
Custom search paths for external or specialized searches
Configure custom search paths to route searches to different destinations based on user selection. For example, route product searches to a commerce search page, or integrate with external search services using URL tokens like [key] for the search terms.
Minimalist search with popup options
Use the popup region feature to keep the main search interface clean. Place the search box and submit button in the main block region, and move content type filters, taxonomy selectors, and other options to the popup region. They appear only when users focus on the search field.
Branded search button
Replace the default text-based submit button with a custom image that matches your site's design. Upload a search icon or branded button image in the block configuration.
Tips
- Use the 'Force - Any - to be displayed' option when you have only one content type selected but still want users to see the selector
- Configure the '- Any - restricts search' option to limit searches to only the content types shown in the selector, rather than searching all content
- Place less frequently used options in the Popup region to keep the main search form clean while still providing advanced options on demand
- Use custom paths with the [current_path] token to create context-aware searches that stay within the current section of your site
- When using multiple select or checkboxes, the arguments separator setting determines how multiple selections are combined in the search query
- The module automatically adds new content types and languages to search page configurations when they are created
- For image buttons, you can specify public:// paths, relative paths, or stream wrapper URIs for flexibility in image location
Technical Details
Admin Pages 1
/admin/structure/block
Place and configure the Custom Search form block. Access block settings by clicking Configure on any placed Custom Search form block.
Hooks 5
hook_entity_bundle_create
Automatically adds new node types to the results settings configuration when a new content type is created.
hook_form_alter
Alters search page add/edit forms to add Custom Search settings, and modifies the search form on results pages to apply configured options.
hook_preprocess_block
Adds role='search' attribute and container-inline class to Custom Search blocks.
hook_theme
Defines custom theme hooks for search results and individual result items.
hook_theme_registry_alter
Overrides core search result templates with Custom Search templates.
Troubleshooting 5
Ensure the Search module is properly configured and content is indexed. Check that the selected search page in block configuration matches your site's search setup. Clear Drupal caches after configuration changes.
Verify that the vocabulary has terms and that the depth setting is not set to 0 (which limits depth). Check that the vocabulary selector type is not set to 'Disabled' in the block configuration.
Ensure paths are entered in the correct format: path|label, one per line. Verify that tokens like [key], [types], [terms] are spelled correctly. Check that the destination path exists and is accessible.
Clear your browser cache and Drupal caches. Ensure the custom_search/custom_search.front library is loading correctly. Check for JavaScript errors in the browser console.
Configure the Results information settings on the search page configuration form (Administration > Configuration > Search pages > Edit). Enable the desired info fields (Content type, Author, Date).