Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video functions
Resource functions

reindex_resource()

Parameters

ColumnTypeDefaultDescription
$ref

Location

include/resource_functions.php lines 5476 to 5525

Definition

 
function reindex_resource($ref)
    {
    global 
$index_contributed_by$index_resource_type,$FIXED_LIST_FIELD_TYPES;
    
# Reindex a resource. Delete all resource_keyword rows and create new ones.
    
    # Delete existing keywords
    
sql_query("DELETE FROM resource_keyword WHERE resource = '{$ref}'");

    
# Index fields
    
$data=get_resource_field_data($ref,false,false); # Fetch all fields and do not use permissions.
    
for ($m=0;$m<count($data);$m++)
        {
        if (
$data[$m]["keywords_index"]==&& !in_array($data[$m]["type"],$FIXED_LIST_FIELD_TYPES))
            {
            
#echo $data[$m]["value"];
            
$value=$data[$m]["value"];
            if (
$data[$m]["type"]==|| $data[$m]["type"]==2)
                {
                
# Prepend a comma when indexing dropdowns
                
$value="," $value;
                }
            
            
# Date field? These need indexing differently.
            
$is_date=($data[$m]["type"]==|| $data[$m]["type"]==6);

            
$is_html=($data[$m]["type"]==8);                    
            
add_keyword_mappings($ref,i18n_get_indexable($value),$data[$m]["ref"],$data[$m]["partial_index"],$is_date,'','',$is_html);        
            }
        }
    
    
# Also index contributed by field, unless disabled
    
if ($index_contributed_by)
        {
        
$resource=get_resource_data($ref);
        
$userinfo=get_user($resource["created_by"]);
        
add_keyword_mappings($ref,$userinfo["username"] . " " $userinfo["fullname"],-1);
        }

        
# Also index the resource type name, unless disabled
    
if ($index_resource_type)
        {
        
$restypename=sql_value("select name value from resource_type where ref in (select resource_type from resource where ref='" escape_check($ref) . "')","");
        
add_keyword_mappings($ref,$restypename,-2);
        }
                
    
# Always index the resource ID as a keyword
    
add_keyword_mappings($ref$ref, -1);
    
    
hook("afterreindexresource","all",array($ref));
    }

This article was last updated 30th November 2020 09:35 Europe/London time based on the source file dated 27th November 2020 14:50 Europe/London time.