Posted by DRagonRage on January 8, 2008 at 3:52pm
slight change to a query from taxonomy module at drupal 5 makes autocomplete search synonym made possible.
here is the change to function: taxonomy_autocomplete
line:1498 => old:
<?php
$result = db_query_range(db_rewrite_sql("SELECT t.tid, t.name FROM {term_data} t WHERE t.vid = %d AND LOWER(t.name) LIKE LOWER('%%%s%%')", 't', 'tid'), $vid, $last_string, 0, 10);
?>new:
<?php
$result = db_query_range(db_rewrite_sql("SELECT t.tid, t.name FROM {term_data} t,{term_synonym} ts WHERE t.vid = %d AND LOWER(t.name) LIKE LOWER('%%%s%%') OR ts.tid = t.tid AND ts.name LIKE LOWER('%%%s%%')", 't', 'tid'), $vid, $last_string, 0, 10);
?>
Comments
Try form_altering
Useful. To avoid patching core, you could in a custom module, register a process callback for textfields using
hook_elements()) to assign a different autocomplete_path calling your callback. Something like:<?php
function mymodule_menu($may_cache) {
$items = array();
if (!$may_cache) {
$items[] = array(
'path' => 'mymodule/autocomplete',
'title' => t('Autocomplete taxonomy'),
'callback' => 'mymodule_autocomplete',
'access' => user_access('access content'),
'type' => MENU_CALLBACK);
);
}
return $items;
}
function mymodule_autocomplete() {
// your modified version of taxonomy_autocomplete().
}
function mymodule_elements() {
$type = array();
$type['textfield'] = array('#process' => array('mymodule_set_autocomplete_path' => array()));
return $type;
}
function mymodule_set_autocomplete_path($element) {
if (isset($element['#autocomplete_path']) && substr($element['#autocomplete_path'], 0, 22) == 'taxonomy/autocomplete/') {
$element['#autocomplete_path'] = 'mymodule/autocomplete/'. substr($element['#autocomplete_path'], 22);
}
return $element;
}
?>
Thanks:
thak you very much , and yes i kinda feel bad for changin core and I suspect i did some dmg to infrastructure(results coming wrong) ,
im a PHP developper and drupal has its oun code or "ethics" that i find to addopt for my current drupal baset project - i cant find the right guide -- the handbooks are great but too specific and therefore allot to read the terminology is really differnt from joomla, iil be glad if you point me to an article called :drupal for the old school php developper ;)
thanks again iil search for form_altering+drupal+hook on google ,
-----
cheers! Leon.
Correction
I think this code was not correct, it must be
<?php$result = db_query_range(db_rewrite_sql("SELECT t.tid, t.name FROM {term_data} t LEFT JOIN {term_synonym} ts ON t.tid = ts.tid WHERE t.vid = %d AND ((LOWER(t.name) LIKE LOWER('%%%s%%')) OR (LOWER(ts.name) LIKE LOWER('%%%s%%')))", 't', 'tid'), $vid, $last_string, $last_string, 0, 10);
?>
See http://drupal.org/node/405048#comment-2973600