Collections functions
Encryption functions
General functions
Theme permission functions
Resource functions

add_node_keyword()

Description

Adds node keyword for indexing purposes

Parameters

ColumnTypeDefaultDescription
$node integer ID of the node (from node table) the keyword should be linked to
$keyword string Keyword to index
$position integer The position of the keyword in the string that was indexed
$normalize true
$stem true
$normalized boolean If this keyword is normalized by the time we add it, set as true

Return

boolean

Location

include/node_functions.php lines 906 to 952

Definition

 
function add_node_keyword($node$keyword$position$normalize true$stem true)
    {
    global 
$unnormalized_index$noadd$stemming;

    
debug("add_node_keyword: node:" $node ", keyword: " $keyword ", position: " $position ", normalize:" . ($normalize?"TRUE":"FALSE") . ", stem:" . ($stem?"TRUE":"FALSE"));
    if(
$normalize)
        {
        
$original_keyword $keyword;
        
$kworig          normalize_keyword($keyword);
        
// if $keyword has changed after normalizing it, then index the original value as well
        
if($keyword != $kworig && $unnormalized_index)
            {
            
add_node_keyword($node$kworig$positionfalse$stem);
            }
        }
        
     if (
$stem && $stemming && function_exists("GetStem"))
        {
        
$unstemmed=$keyword;
        
$keyword=GetStem($keyword);
        if(
$keyword!=$unstemmed)
            {
            
// $keyword has been changed by stemming, also index the original value
            
debug("add_node_keyword - adding unstemmed: " $unstemmed);
            
add_node_keyword($node$unstemmed$position$normalize,false);
            }
        }
        
        
    
// $keyword should not be indexed if it can be found in the $noadd array, no need to continue
    
if(in_array($keyword$noadd))
        {
        
debug('Ignored keyword "' $keyword '" as it is in the $noadd array. Triggered in ' __FUNCTION__ '() on line ' __LINE__);
        return 
false;
        }

    
$keyword_ref resolve_keyword($keywordtrue,$normalize,false); // We have already stemmed

    
sql_query("INSERT INTO node_keyword (node, keyword, position) VALUES ('" escape_check($node) . "', '" escape_check($keyword_ref) . "', '" escape_check($position) . "')");
    
sql_query("UPDATE keyword SET hit_count = hit_count + 1 WHERE ref = '" escape_check($keyword_ref) . "'");

    
log_activity("Keyword {$keyword_ref} added for node ID #{$node}"LOG_CODE_CREATED$keyword'node_keyword');

    
clear_query_cache("schema");

    return 
true;
    }

This article was last updated 14th July 2020 06:05 Europe/London time based on the source file dated 6th July 2020 18:09 Europe/London time.