Hi,

I'm running drupal 6 and trying to create a custom search. By custom i dont mean modifying the text or whatever. I need to add taxonomy terms as a drop down. So that users select a category in which to search in and then the text... Or they can select search in all categories.

Any help would be appreciated.

Cheers.

Comments

asd123asd5’s picture

Hi rusdvl,

You can use the views module to create a custom search.

1) Create a new view
2) Set a filter called 'search terms'
3) Expose the filter
4) Make sure it isn't set to 'optional'
5) Set another filter called 'taxonomy terms'
6) Set it to 'drop down'
7) Select the vocabulary you want to use
8) Expose it
9) Set a sort criteria called 'search score'
10) Select the fields you want to feature (ie, node: title, node: teaser)
11) customize however you want with the page/block settings...
12) save

rusdvl’s picture

Thanks.

I have a bit of an issue with this... I can see the two fields in the preview, but when I click save and allocate that block a place to sit in. (right sidebar) I cannot see the form. Both fields are exposed... so not sure why its not showing up... any ideas?

Here is the exported view:

$view = new view;
$view->name = 'main_search';
$view->description = 'Main search';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
  'title' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'link_to_node' => 1,
    'exclude' => 0,
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'relationship' => 'none',
  ),
  'body' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 1,
      'max_length' => '100',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'exclude' => 0,
    'id' => 'body',
    'table' => 'node_revisions',
    'field' => 'body',
    'relationship' => 'none',
  ),
));
$handler->override_option('sorts', array(
  'score' => array(
    'order' => 'ASC',
    'id' => 'score',
    'table' => 'search_index',
    'field' => 'score',
    'relationship' => 'none',
  ),
));
$handler->override_option('filters', array(
  'keys' => array(
    'operator' => 'required',
    'value' => '',
    'group' => '0',
    'exposed' => TRUE,
    'expose' => array(
      'use_operator' => 0,
      'operator' => 'keys_op',
      'identifier' => 'keys',
      'label' => 'Search: Search Terms',
      'optional' => 0,
      'remember' => 0,
    ),
    'id' => 'keys',
    'table' => 'search_index',
    'field' => 'keys',
    'override' => array(
      'button' => 'Override',
    ),
    'relationship' => 'none',
  ),
  'tid' => array(
    'operator' => 'or',
    'value' => array(),
    'group' => '0',
    'exposed' => TRUE,
    'expose' => array(
      'use_operator' => 0,
      'operator' => 'tid_op',
      'identifier' => 'tid',
      'label' => 'Taxonomy: Term',
      'optional' => 1,
      'single' => 1,
      'remember' => 0,
      'reduce' => 0,
    ),
    'type' => 'select',
    'limit' => TRUE,
    'vid' => '1',
    'id' => 'tid',
    'table' => 'term_node',
    'field' => 'tid',
    'hierarchy' => 1,
    'relationship' => 'none',
    'reduce_duplicates' => 0,
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler = $view->new_display('block', 'Block', 'block_1');
$handler->override_option('block_description', '');
$handler->override_option('block_caching', -1);
asd123asd5’s picture

set:

Exposed form in block: Yes

and then add the block into your theme

rusdvl’s picture

thanks. that worked. but now when i click search it just redirects me to the home page but doesnt display any results on its own page. is there something that im suppose to choose to make it go to its own search results page?

thanks ahead

UPDATE: I figured it out. Had to add a 'page' display to that view and give it a path, in my case 'ad-search/%'

asd123asd5’s picture

sweeet, glad it all worked out for you.

webdesigncapetown’s picture

Thanks this is exactly what i was looking for.

Edward.H’s picture

thanks,but is it possible to add one option name" all" within the select box to let user search entire taxomony rathan than just choosing 1 or more terms of the taxomony?

rusdvl’s picture

It has an automatic option of < any > (that is if you made it optional and not mandatory). You can change the string to 'all' using the 'string replace' module.