Hola,

Will there be a Drupal 6.x / 7.x version of this module developed?

Cheers,
Danielle

CommentFileSizeAuthor
#25 search_config-patched-for-6.x.zip3.39 KBar-jan
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

canen’s picture

Yes, eventually. I just haven't moved to Drupal 6 yet. Sorry :(

Dinis’s picture

Thanks for the response Canen.

I've not moved yet either, getting close now though :)

dargrego’s picture

This is very useful module for me in D5. I wanted it for D6 and decided to port it with deadwood module to be compatible with D6. It works for me now. Here is search_config.module for D6:

<?php
//$Id: search_config.module,v 1.8.2.5 2007/10/21 02:37:25 canen Exp $

/**
 * @file
 * Allows admins to configure the advanced search form.
 *
 * In general the search_config module allows users to decide which fields
 * to show on the advanced search form. This does not stop astute users from
 * placing the search criteria directly in the search text fields. The module
 * also provides three (3) new permissions but for the time being won't do much
 * good.
 *
 * You also have the option of selecting which node types not to index. These are
 * also automatically removed from the search form. 
 *
 * Admins will be able to decide if the following fields or selected members 
 * of their groups are removed from the search form.
 *  - keywords
 *  - categories
 *  - node types
 *
 * What this module achieves at the moment can also be achieved by theming the
 * search form. Also, it does not control what can be searched.
 *
 * @author Nesta Campbell
 * @todo Look at multiple hierarchy taxonomies
 * 
 */

/**
 * Implementation of hook_perm()
 *
 * At the moment this module does not control access to what can be searched,
 * only what fields are displayed to the user. Therefore, these permissions
 * don't really do much but allow the displaying of form fields per role.
 */
function search_config_perm() {
  return array('search by node type', 'search by category', 'use keyword search');
}

/**
 * Implementation of hook_form_alter()
 */
function search_config_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'search_form') {
    if (arg(1) == 'node') {
      
      // Keywords
      if (user_access('use keyword search')) {
        if (variable_get('search_config_disable_or', 0)) {
          unset($form['advanced']['keywords']['or']);
        }
        if (variable_get('search_config_disable_phrase', 0)) {
          unset($form['advanced']['keywords']['phrase']);
        }
        if (variable_get('search_config_disable_negative', 0)) {
          unset($form['advanced']['keywords']['negative']);
        }
      }
      // Remove all the keyword search fields
      else { 
        unset($form['advanced']['keywords']);
      }

      // Node types
      // We will need to rebuild the checkboxes for the node types
      $remove = variable_get('search_config_disable_type', array());

      if ($remove['all'] || !user_access('search by node type')) {
        unset($form['advanced']['type']);
      }
      else {
        $types = node_get_types('names');
        
        foreach ($types as $module => $type) {
          if ($remove[$module]) {
            unset($types[$module]);
          }
        }
      
        // Rebuild form item -- copied from node.module
        if (count($types) == 1) {
          $type_keys = array_keys($types);
          $form['advanced']['type'] = array(
            '#type' => 'hidden',
            '#default_value' => $type_keys[0],
          );
        } 
        else {
          $form['advanced']['type'] = array(
            '#type' => 'checkboxes',
            '#title' => t('Only of the type(s)'),
            '#prefix' => '<div class="criterion">',
            '#suffix' => '</div>',
            '#options' => $types,
          );
        }
      }

      if ($taxonomy = module_invoke('taxonomy', 'form_all', 1)) {
        // Taxonomy
        if (variable_get('search_config_disable_category_all', 0) || !user_access('search by category')) {
          unset($form['advanced']['category']);
        }
        else {
          $terms = variable_get('search_config_disable_category', array());

          if (module_exists('og_vocab')) {
            $groupnode = og_get_group_context();
            $sql = "SELECT t.tid FROM {vocabulary} v, {term_data} t LEFT JOIN {og_vocab} ov ON v.vid = ov.vid WHERE (v.module = 'og_vocab' AND ov.nid != %d) AND t.vid=v.vid";
            $result = db_query($sql, $groupnode->nid);

            while ($row = db_fetch_object($result)) {           
              $terms[$row->tid] = $row->tid;
            }         
          }

          // FIXME: What about multiple hierarchy categories?
          foreach ($taxonomy as $vocab => $term) {
            foreach ($term as $k => $v) {
              if(in_array($k, $terms)) {
                unset($taxonomy[$vocab][$k]);
              }
            }
            // Remove empty vocabs
            if (count($taxonomy[$vocab]) == 0) {
              unset($taxonomy[$vocab]);
            }
          }

          if (count($taxonomy) == 0) {
            unset($form['advanced']['category']);
          }
          else {
            // Taxonomy box:
            $form['advanced']['category'] = array(
              '#type' => 'select',
              '#title' => t('Only in the category(s)'),
              '#prefix' => '<div class="criterion">',
              '#size' => 10,
              '#suffix' => '</div>',
              '#options' => $taxonomy,
              '#multiple' => TRUE,
            );
          }
        }
      }
    }
  }
}

/**
 * Implementation of hook_search()
 */
function search_config_search($op) {
  switch ($op) {
    case 'admin':
      $form['search_config'] = array(        
        '#type' => 'fieldset',
        '#title' => t('Advanced search configuration'),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
      );

      // Keyword boxes:
      $form['search_config']['keywords'] = array(
        '#type' => 'fieldset',
        '#title' => t('Keywords'),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE ,
        '#description' => t('Configuration for which keyword search fields should not be displayed.')
      );
      
      $form['search_config']['keywords']['search_config_disable_or'] = array( 
        '#type' => 'checkbox',
        '#title' => t('Containing any of the words'),
        '#default_value' => variable_get('search_config_disable_or', 0)
      );
      
      $form['search_config']['keywords']['search_config_disable_phrase'] = array(
        '#type' => 'checkbox',
        '#title' => t('Containing the phrase'),
        '#default_value' => variable_get('search_config_disable_phrase', 0)
      );
      
      $form['search_config']['keywords']['search_config_disable_negative'] = array(
        '#type' => 'checkbox',
        '#title' => t('Containing none of the words'),
        '#default_value' => variable_get('search_config_disable_negative', 0)
      );
      
      // Taxonomy box
      if ($taxonomy = module_invoke('taxonomy', 'form_all', 1)) {
        $form['search_config']['category'] = array(
          '#type' => 'fieldset',
          '#title' => t('Categories'),
          '#collapsible' => TRUE,
          '#collapsed' => TRUE ,
          '#description' => t('Categories to display')
        );

        $form['search_config']['category']['search_config_disable_category_all'] = array(
          '#type' => 'checkbox',
          '#title' => t('Disable category search'),
          '#default_value' => variable_get('search_config_disable_category_all', 0)
        );

        $form['search_config']['category']['search_config_disable_category'] = array(
          '#type' => 'select',
          '#title' => t('Categories'),
          '#options' => $taxonomy,
          '#size' => 10,
          '#multiple' => TRUE,
          '#default_value' => variable_get('search_config_disable_category', array()),
          '#description' => t('Disable searching by the selected categories')
        );
      }

      // Node types 
      $types = node_get_types('names');
      $types = array_merge(array('all' => 'Disable all'), $types);

      $form['search_config']['type'] = array(
        '#type' => 'fieldset',
        '#title' => t('Node types'),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE ,
        '#validate' => array('search_config_validate' => array())
      );
      
      $form['search_config']['type']['form'] = array(
        '#type' => 'fieldset',
        '#title' => t('Search Form'),
        '#collapsible' => FALSE,
        '#description' => t('Node types that users shouldn\'t be allowed to search by using the advanced search form.')
      );

      $form['search_config']['type']['search_config_disable_type'] = array(
        '#type' => 'checkboxes',
        '#options' => $types,
        '#default_value' => variable_get('search_config_disable_type', array())
      );
      
      $form['search_config']['type']['index'] = array(
        '#type' => 'fieldset',
        '#title' => t('Search Index'),
        '#collapsible' => FALSE,
        '#description' => t('Node types that should not be indexed by the search module. Any node type set to not be indexed will also be removed from the search form. If you select all available node types to not be index, then the search module will be rendered unusable as no nodes will be indexed.')
      );

      // If all node types are disabled then the search module is useless.
      unset($types['all']);
      reset($types);

      $form['search_config']['type']['index']['search_config_disable_index_type'] = array(
        '#type' => 'checkboxes',
        '#options' => $types,
        '#default_value' => variable_get('search_config_disable_index_type', array())
      );

      return $form;
  }
}

function search_config_validate($form, &$form_state) {
  if ($form_state['values']['#post']['form_id'] == 'search_admin_settings' && $form_state['values']['#post']['op'] == 'Save configuration') {
    $post_values = $form_state['values']['#post'];
    $node_types = node_get_types('names');

    if (!isset($post_values['search_config_disable_index_type'])) {
      return;
    }
    
    $index_types = $post_values['search_config_disable_index_type'];

    if (!isset($post_values['search_config_disable_type'])) {
      $post_values['search_config_disable_type'] = array();
    }
    
    $form_types = $post_values['search_config_disable_type'];

    if (count($index_types) != 0 && count($index_types) == count($node_types)) {
      form_set_error('search_config_disable_index_type', t('You can not set all node types to be not indexed by the search module. Disable the search module if that is what you want.'));
    }

    if (isset($post_values['search_config_disable_type']['all'])) {
      return;
    }
    
    $type_diff = array_diff($index_types, $form_types);

    if (count($type_diff)) {
      $node_errors = array();
      foreach ($type_diff as $type) {
        $node_errors[] = $node_types[$type];
      }
      form_set_error('search_config_disable_type', t('Search index node types do not match form node types. Please check the setting for %nodes.', array('%nodes' => implode(', ', $node_errors))));
    }
 }
}

/**
 * Implementation of hook_update_index()
 */
function search_config_update_index() {
  // This hook is only called when the search module is enabled
  // The function_exists check can be removed, but there is no harm in leaving it in
  if (function_exists('search_wipe')) {
    $types = node_get_types('names');
    $remove = variable_get('search_config_disable_index_type', array());
    foreach ($remove as $type => $value) {
      if (isset($types[$type]) && $value === $type) {
        $result = db_query("SELECT n.nid FROM {node} n INNER JOIN {search_dataset} s ON n.nid=s.sid WHERE n.type = '%s'", $type);
        while ($data = db_fetch_object($result)) {
          search_wipe($data->nid, 'node');
        }
      }
    }
  }
}

File search_config.info should be changed to fix version info and so on.

momper’s picture

Title: Drupal 6 Version? » Drupal 6 Version of Search config?
JeremyL’s picture

Anyone else tested this out? I'm about to start testing 6 and wondering what if any bugs have been found.

Dinis’s picture

It's on my "todo" list, but at the moment there are a few too many essential modules for me to fully consider D6, so it's still a back burner for me.

a1lostnomad’s picture

dargod's port works perfectly... just had to spruce up module.info a bit. Mine looks like this...

name = Search config
description = Configure display of the advanced search form
package = Search
core = 6.x

version = "6.x-1.3"
project = "search_config"

Sounds like you have everything you need to start a 6.x branch. Come'on... for the community's benefit? :)

canen’s picture

a1lostnomad,

I've actually started working on search config again so expect a 6 version soon.

scottrigby’s picture

Version: 5.x-1.3 » master

Hi Canen, great! will keep an eye out for that :)

But what about the 6.x port posted above - do you see any major problems with it?

Also, how does this compare to using views + views_fastsearch to build "section search" or custom advanced search pages?
(see lulabot podcast on this: http://www.lullabot.com/audiocast/podcast-50-drupal-tips-and-tricks ...this particular tip #17 starts at 28:30 by btw).

scottrigby’s picture

Version: master » 5.x-1.x-dev

oops, wrong version ;)

canen’s picture

scottrigby,

I have done zip with Drupal 6 so I honestly couldn't tell how good the port above is. A new feature has been contributed to the latest 5 version that allows you to choose which default search to use if you have more than one installed. The port would need to include this as well.

views+views_fastsearch is not really comparable since search config is used to control the site-wide search operation while views_fastsearch is used to create your own search 'type' and provide more control over the results. I've used both together on projects before.

scottrigby’s picture

Ok cool - that sounds like a great feature :)

BTW, should new feature requests go in this issue now? Or in the general issue queue (and just pick 5.x-1.x-dev as the version on those as seperate issues for now)?

Thanks canen

canen’s picture

Create an issue per request please. I would actually love to hear how people are using the module and what they expect from it. It has long pass what I intended to use it for :)

ar-jan’s picture

Thanks for posting this initial port to 6. It worked for me on 6.4 :)

mimhakkuh’s picture

I'd also appreciate a D6 port very much! :)

TheRec’s picture

Subscribing. Seems that all the work is done already ? I must test the above code, but hearing others it seems all good.
**EDIT**
Tested it... it seems all good to me, really useful ! I hope for an official release :)

jrabeemer’s picture

Title: Drupal 6 Version of Search config? » Port Drupal 6 version of Search Config
Version: 5.x-1.x-dev » master
Category: support » task
Priority: Normal » Critical
Status: Active » Needs review

This D6 build needs to be tarballed and submitted for approval. I have the above patch on my D6 site and it seems to be working.

jrabeemer’s picture

More testing done with the D6 patch. It seems if you go to the http://yoursite/search node, the category and type fields appear regardless if you turn off the permission. But if you do a search, the resulting output under Advanced Search does respect the setting.

nextpulse’s picture

Not working for me on D6.6. Seems like its not picking up any of the info entered on the adv form.

* warning: array_shift() [function.array-shift]: The argument should be an array in /mnt/drupal/includes/form.inc on line 1320.
* warning: array_shift() [function.array-shift]: The argument should be an array in /mnt/drupal/includes/form.inc on line 1320.
* Please enter some keywords.

Update: me bad. It does work.

The silly thing is that drupal requires the basic search field too - even though the advanced is being used - thats 'clunky'.

HS’s picture

Waiting for D6 port as well.

HS’s picture

Tried the above port. Not working on D6 6.8. in admin/build/modules I get the following: This version is incompatible with the 6.8 version of Drupal core.

I copied over all the info as above to my search_config.module file and the info file. What am i doing wrong? Any help is appreciated.

jrabeemer’s picture

Did you make the .info file mentioned in #7?

jrabeemer’s picture

To slybud and canen module owners, is there a branch for D6? If not, could you make one? I'm willing to make a D6 patch from the code above and post it here. Unless there has been work already done on a D6 port, we need to push this patch forward.

HS’s picture

@Momendo

Yes i made the search_config.info. Maybe I did something wrong. I would appreciate a zipped file for D6 for us newbs.

ar-jan’s picture

Here's my patched search_config module folder, working with D6.8 for me.

HS’s picture

Thanks Arjan!

Will give it a try.

HS’s picture

#25 works on Drupal 6.8. Thanks!

mimhakkuh’s picture

Thank you so much, ArjanLikesDrupal! Works perfect for me - just the module I needed. Still wondering why this is no function included in core ...

momper’s picture

+1 to core

DamienMcKenna’s picture

This functionality should really be in core :-| Will test out the v6 patch, thanks.

Rosamunda’s picture

+1 for adding this to core!

canen’s picture

Hello,

Thanks for your patience. I've started work on the 6 version, you can find the development release here http://drupal.org/node/354804. It should be packaged soon.

There is a bug, also present in the latest 5.x version, which I am trying to sort out soon and then do an official release.

canen’s picture

Bug should be fixed in the dev version for 6.

joey santiago’s picture

subscribing... this module's functionality is very useful... it should be in core! :)

thanks guys for your work, Drupal's community is great!

Stephen Scholtz’s picture

subscribing...is the dev version stable?

jeffschuler’s picture

How can we help get the D6 version to stable, canen?

greg.harvey’s picture

subscribing, and echoing #36 ^^

rickvannierop’s picture

subscribing

canen’s picture

OK. I finally got around to fixing a nagging issue, not cleanly (http://drupal.org/cvs?commit=216032), and should be ready for a release now.

The dev version should be pretty stable but I would love some feedback before I do an actual release.

Coupled with the fact that I haven't used search config on a live site in over a year, laziness and that there is no proper way to not index content in Drupal this has taken a lot longer than it should. Thanks for the patience.

ar-jan’s picture

Thanks for your work on this module. I've been using the 6.x-1.x-dev from day 1, and it seems to work fine.

canen’s picture

Well that's 1. I'll make a release about Friday either way.

canen’s picture

Status: Needs review » Closed (fixed)

Release tagged.