Collections functions
General functions
Render functions
Theme permission functions
Resource functions

add_keyword_to_resource()

Description

Create a resource / keyword mapping

Parameters

ColumnTypeDefaultDescription
$ref int ID of resource
$keyword string Keyword to be added
$resource_type_field int ID of resource type field
$position int
$optional_column string ''
$optional_value string ''
$normalized boolean false Normalize the keyword?
$stemmed boolean false Use stemming?

Return

void

Location

include/resource_functions.php lines 2124 to 2175

Definition

 
function add_keyword_to_resource(int $ref,$keyword,$resource_type_field,$position,$optional_column='',$optional_value='',$normalized=false,$stemmed=false)
    {
    global 
$unnormalized_index,$stemming,$noadd;
    
    
debug("add_keyword_to_resource: resource:" $ref ", keyword: " $keyword);
    if(!
$normalized)
        {
        
$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,$stemmed);
            }
        }

    
$kworig=$keyword// Store non-stemmed word
    
if (!$stemmed && $stemming && function_exists("GetStem"))
        {
        
$keyword=GetStem($keyword);debug("Using stem " $keyword " for keyword " $kworig);
        if(
$keyword!=$kworig)
            {
            
// $keyword has been changed by stemming, also index the original value
            
add_keyword_to_resource($ref,$kworig,$resource_type_field,$position,$optional_column,$optional_value,$normalized,true);
            }
        }
    
    if (!(
in_array($kworig,$noadd))) // Original (non stemmed) word not in the stop list?
            
{
            
$keyref=resolve_keyword($keyword,true,false,false); // 3rd param set to false as already normalized. Do not stem this keyword as stem has already been added in this function
            
debug("Indexing keyword $keyword - keyref is " $keyref ", already stemmed? is " . ($stemmed?"TRUE":"FALSE"));

            
$sql_extra_select "";
            
$sql_extra_value "";
            if(
$optional_column != '' && $optional_value != '')
                {
                
$sql_extra_select ", `{$optional_column}`";
                
$sql_extra_value ", '" escape_check($optional_value) . "'";
                }
            
$ref escape_check($ref);
            
$keyref escape_check($keyref);
            
$position escape_check($position);
            
$resource_type_field escape_check($resource_type_field);
            
sql_query("INSERT INTO resource_keyword(resource, keyword, position, resource_type_field {$sql_extra_select})
                            VALUES ('
$ref', '$keyref', '$position', '$resource_type_field{$sql_extra_value})");

            
sql_query("update keyword set hit_count=hit_count+1 where ref='$keyref'");
            
            
# Log this
            
daily_stat("Keyword added to resource",$keyref);
            }      
    }

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