Hi!
How about to add a taxonomy search to drupal7 (or even to drupal 6.3)?
I wrote some Code to search the taxonomy for drupal6:
/**
* Implementation of hook_search().
*/
function taxonomy_search($op = 'search', $keys = NULL, $vid=NULL) {
switch ($op) {
case 'name':
{
return t('Taxonomy');
}
case 'search':
{
$find = array();
if (!$vid){
$db_result = db_query(db_rewrite_sql("SELECT t.tid, t.* FROM {term_data} t WHERE LOWER(t.name) LIKE LOWER('%%%s%%')", 't', 'tid'), trim($keys));
}
else {
$db_result = db_query(db_rewrite_sql("SELECT t.tid, t.* FROM {term_data} t WHERE LOWER(t.name) LIKE LOWER('%%%s%%') AND t.vid=%d", 't', 'tid'), trim($keys), $vid);
}
while ($term = db_fetch_object($db_result))
{ $find[] = array('tid'=>$term->tid, 'title'=>$term->name, 'link'=>'/taxonomy/term/'.$term->tid);}
return $find;
}
}
}
Although i added some code to taxonomy_form_alter() to support the search-module
if ($form_id == 'search_form' && $form['module']['#value'] == 'taxonomy') {
$vocabs=taxonomy_get_vocabularies();
$vop=array();
foreach($vocabs as $voc)
{
$vop[$voc->vid]= $voc->name;
}
$form['vocabulary'] = array(
'#type' => 'checkboxes',
'#title' => t('In the vocabulary'),
'#prefix' => '<div class="criterion">',
'#size' => 10,
'#suffix' => '</div>',
'#options' => $vop,
'#multiple' => TRUE,
'#name' => 'vid',
);
}
TODO:
- how is this added to the search lick "Content" and "Users" are?
- how do i add the criteroin "vid"?
- some permission rules to search specific vocabularys.
tell me what you think!
Comments
Comment #1
Susurrus commentedI think this would be a great addition to the standard search. It will need to be rolled up as a patch for Drupal 7 for it to really get any attention. Be sure to follow the coding standards also, which is easy to do by using coder.module.
Comment #2
catch#172812: Implement SearchPlugin for taxonomy