Collections functions
Encryption functions
General 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 2027 to 2095

Definition

 
function add_keyword_to_resource($ref,$keyword,$resource_type_field,$position,$optional_column='',$optional_value='',$normalized=false,$stemmed=false)
    {
    global 
$unnormalized_index,$stemming,$noadd,$use_mysqli_prepared;
    
    
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);
            }
        }
        
    if (!
$stemmed && $stemming && function_exists("GetStem"))
        {
        
$kworig=$keyword;
        
$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($keyword,$noadd)))
            {
            
$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"));

            
$stm_bind_data = array('iiii'$ref$keyref$position$resource_type_field);
            
$stm_prep_values "?,?,?,?";

            
$sql_extra_select "";
            
$sql_extra_value "";
            if(
$optional_column != '' && $optional_value != '')
                {
                
$sql_extra_select ", `{$optional_column}`";
                
$sql_extra_value ", '" escape_check($optional_value) . "'";

                
$stm_prep_values .= ",?";
                
$stm_bind_data[0] .= "s";
                
$stm_bind_data[] = $optional_value;
                }

            
# create mapping, increase hit count.
            
if(isset($use_mysqli_prepared) && $use_mysqli_prepared)
                {
                
sql_query_prepared("INSERT INTO `resource_keyword`(`resource`,`keyword`,`position`,`resource_type_field` {$sql_extra_select}) VALUES ($stm_prep_values)",
                    
$stm_bind_data);
                }
            else
                {
                
$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 11th July 2020 02:05 Europe/London time based on the source file dated 10th July 2020 16:06 Europe/London time.