Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test 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 2142 to 2193

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})");

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

This article was last updated 28th June 2022 15:05 Europe/London time based on the source file dated 27th June 2022 12:50 Europe/London time.