function resolve_keyword($keyword, $create = false) { debug("resolving keyword " . $keyword . ". Create=" . ($create ? "true" : "false")); $keyword = substr($keyword, 0, 100); # Trim keywords to 100 chars for indexing, as this is the length of the keywords column. global $quoted_string; if (!$quoted_string) { $keyword = normalize_keyword($keyword); debug("resolving normalized keyword " . $keyword . "."); } # Stemming support. If enabled and a stemmer is available for the current language, index the stem of the keyword not the keyword itself. # This means plural/singular (and other) forms of a word are treated as equivalents. global $stemming; if ($stemming && function_exists("GetStem")) { $keyword = GetStem($keyword); } # Returns the keyword reference for $keyword, or false if no such keyword exists. $return = sql_value("select ref value from keyword where keyword='" . trim(escape_check($keyword)) . "'", false); if ($return === false && $create) { # Create a new keyword. debug("Creating new keyword for " . $keyword); sql_query("insert into keyword (keyword,soundex,hit_count) values ('" . escape_check($keyword) . "',left('" . soundex(escape_check($keyword)) . "',10),0)"); $return = sql_insert_id(); } return $return; }
function add_keyword_to_resource($ref, $keyword, $resource_type_field, $position, $optional_column = '', $optional_value = '', $normalized = false) { if (!$normalized) { global $unnormalized_index; $kworig = $keyword; $keyword = normalize_keyword($keyword); if ($keyword != $kworig && $unnormalized_index) { // $keyword has been changed by normalizing, also index the original value add_keyword_to_resource($ref, $kworig, $resource_type_field, $position, $optional_column, $optional_value, true); } } global $noadd; if (!in_array($keyword, $noadd)) { debug("adding " . $keyword); $keyref = resolve_keyword($keyword, true); # create mapping, increase hit count. if ($optional_column != '' && $optional_value != '') { sql_query("insert into resource_keyword(resource,keyword,position,resource_type_field,{$optional_column}) values ('{$ref}','{$keyref}','{$position}','{$resource_type_field}','{$optional_value}')"); } else { sql_query("insert into resource_keyword(resource,keyword,position,resource_type_field) values ('{$ref}','{$keyref}','{$position}','{$resource_type_field}')"); } sql_query("update keyword set hit_count=hit_count+1 where ref='{$keyref}'"); # Log this daily_stat("Keyword added to resource", $keyref); } }