Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource functions

resolve_keyword()

Description

Resolve keyword

Parameters

ColumnTypeDefaultDescription
$keyword string The keyword to resolve
$create bool false If keyword not found, should we create it instead?
$normalize bool true Should we normalize the keyword before resolving?
$stem bool true Should we use the keywords' stem when resolving?

Return

int|bool Returns the keyword reference for $keyword, or false if no such keyword exists.

Location

include/search_functions.php lines 2314 to 2360

Definition

 
function resolve_keyword($keyword,$create=false,$normalize=true,$stem=true)
    {
    
debug_function_call("resolve_keyword"func_get_args());

    
// Create a cache to ensure we find new nodes subsequently if in a transaction
    
global $resolve_keyword_cache;
    global 
$quoted_string$stemming;
    
$kwhash md5($keyword) . md5("!" $keyword . ($normalize "NORM" "") . ($stem "STEM" ""));
    if(isset(
$resolve_keyword_cache[$kwhash]))
        {
        return 
$resolve_keyword_cache[$kwhash];
        }
    
$keyword=mb_strcut($keyword,0,100); # Trim keywords to 100 chars for indexing, as this is the length of the keywords column.
            
    
if(!$quoted_string && $normalize)
        {
        
$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.
    
    
if ($stem && $stemming && function_exists("GetStem"))
        {
        
$keyword=GetStem($keyword);
        }

    
$return=ps_value("SELECT ref value FROM keyword WHERE keyword = ?",array("s",trim($keyword)),0);
    if (
$return===0)
        {
        if(
$create)
            {
            
# Create a new keyword.
            
debug("resolve_keyword: Creating new keyword for " $keyword);
            
ps_query("insert into keyword (keyword,soundex,hit_count) values (?,left(?,10),0)",array("s",$keyword,"s",soundex($keyword)));
            
$return=sql_insert_id();
            }
        else
            {
            return 
false;
            }
        }
    
    
$resolve_keyword_cache[$kwhash] = $return;
    return 
$return;
    }

This article was last updated 19th March 2024 10:35 Europe/London time based on the source file dated 15th March 2024 17:00 Europe/London time.