I have a content type called "product". This "product" has an on/off checkbox to flag whether or not the product in question is able to be viewed on the web. I would like to index only the products that have this "web_catalog" field turned on. I have tried using preprocess_search_result to limit the returned result to no avail. Any ideas or suggestions would be greatly appreciated, thank you.

  • maybe this link could help you, the article describes in detail how you could setup a form for types to ignore and a hook_form_alter implementation on your search to bring the required output, though the content is indexed its not revealed in search result.. suggest considering Apache Solr Search which provides selective indexing based on content type with hooks to implement logic for selective indexing Sep 17 '12 at 14:50
  • Thank you for the reply. We eventually figured this out. We created a simple module that utilizes _query_alter(QueryAlterableInterface &$query) to append a subquery to the search query.
    – Joe
    Sep 17 '12 at 17:53

I wanted to thank everyone for their input. In the end we created a small module that will alter the query instead of trying to alter the index of the site. To do this we utilized hook_query_alter() to add a subquery to the search. Below is the final version of our hook for reference should someone else have a similar issue.

function product_view_display_query_alter(QueryAlterableInterface &$query) {
  $is_search = FALSE;
  $tables =& $query->getTables();
  foreach($tables as $table) {
    if ($table['table'] == 'search_index') {
      $is_search = TRUE;
  if ($is_search) {
    $subquery = db_select('field_data_product_web_catalog','pwc')->fields('pwc',array('entity_id'))->condition('product_web_catalog_value',1);

Maybe not publishing the node can help you. It wont appear on your search results, or anywhere on your site to the "end users". Administrators can still view the unpublished content, but it wont appear for the normal users.


You can do this with Views. In your view use the "Filter Criteria" to show only the products that have their "web_catalog" field checked. And even the Administratos wont see the hidden products.

It seems like you are new into Drupal and Views is the most installed module for drupal. You must learn it so you can unleash the true Drupal power. Seach on youtube about views tutorials or visit this page http://nodeone.se/en/taming-the-beast-learn-views-with-nodeone.

  • Thanks for the reply. The idea of setting the content as "unpublished" did occur to me. However, I am trying to make this as user friendly as possible. In the end the client will be administering the site. I figured a single (clearly defined) check box is better than explaining the vertical tab system on the nodes. I am using the views module to display the content on the actual product pages. My problem lies in the return search results as they are indexed by Drupal's default search capabilities. In the end we created a module to utilize hook_query_alter(QueryAlterableInterface &$query)
    – Joe
    Sep 17 '12 at 17:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.