On this page
Removing specific content type(s) from search results
Last updated on
30 April 2025
If you do not want specific content types to be included in your search results, you will want to add the following filter statement(s) in your module.
The TRUE is set to exclude this type of content type. If you want your search results to ONLY include a specific content type you would not include the TRUE.
/**
* Implementation of hook_apachesolr_modify_query().
*/
function mymodule_apachesolr_modify_query(&$query, &$params, $caller) {
$query->add_filter('type', 'profile', TRUE); // Does not include profile content types in search results.
$query->add_filter('type', 'story', TRUE); // Does not include profile content types in search results.
}
NOTE: If you do not include the TRUE to exclude a content type (or other results information) you can only have one filter per type, or hash, etc.
For Drupal 7
function MYMODULE_apachesolr_query_prepare($query) {
$query->addFilter('bundle', 'story', $exclude = TRUE);
}
Help improve this page
Page status: Not set
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion