Collections functions
General functions
Render functions
Theme permission 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 2052 to 2082

Definition

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

    global 
$quoted_string$stemming;
    
$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=sql_value("select ref value from keyword where keyword='" trim(escape_check($keyword)) . "'",false);
    if (
$return===false && $create)
        {
        
# Create a new keyword.
        
debug("resolve_keyword: 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;
    }

This article was last updated 25th May 2022 05:35 Europe/London time based on the source file dated 10th May 2022 09:10 Europe/London time.