Download & Extend

Advanced search specifically for terms should also work with synonyms

Project:Synonyms
Version:6.x-1.0
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Issue tags:Science Collaboration

Issue Summary

Because synonyms works by adding synonyms to the general index, when using advanced search to specifically search for the category (which someone looking for content tagged with a synonym of a term is rather likely to do), it does not show content that it does find by normal search.

Have not looked into this feasibility but it would be good to have Drupal core advance search and/or Views Fast Search etc. understand that terms have synonyms.

Comments

#1

Well it would be nice to implement an overwrite of the taxonomy autocomlete function into this module. Here I just changed the sql query.

So if a synonym is search by the autocomplete the original term will be suggested.


<?php
/**
* Helper function for autocompletion
*/
function taxonomy_autocomplete($vid, $string = '') {
 
// The user enters a comma-separated list of tags. We only autocomplete the last tag.
 
$array = drupal_explode_tags($string);

 
// Fetch last tag
 
$last_string = trim(array_pop($array));
 
$matches = array();
  if (
$last_string != '') {
   
$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);

   
$prefix = count($array) ? implode(', ', $array) .', ' : '';

    while (
$tag = db_fetch_object($result)) {
     
$n = $tag->name;
     
// Commas and quotes in terms are special cases, so encode 'em.
     
if (strpos($tag->name, ',') !== FALSE || strpos($tag->name, '"') !== FALSE) {
       
$n = '"'. str_replace('"', '""', $tag->name) .'"';
      }
     
$matches[$prefix . $n] = check_plain($tag->name);
    }
  }

 
drupal_json($matches);
}
?>

nobody click here