Collections functions
General functions
Render functions
Theme permission functions
Resource functions

index_collection()

Description

Update the keywords index for this collection

Parameters

ColumnTypeDefaultDescription
$ref integer
$index_string string ''

Return

integer How many keywords were indexed?

Location

include/collections_functions.php lines 1243 to 1281

Definition

 
function index_collection($ref,$index_string='')
    {
    
# Remove existing indexed keywords
    
ps_query("delete from collection_keyword where collection=?",array("i",$ref)); # Remove existing keywords
    # Define an indexable string from the name, themes and keywords.

    
global $index_collection_titles;

    if (
$index_collection_titles)
        {
            
$indexfields 'c.ref,c.name,c.keywords,c.description';
        } else {
            
$indexfields 'c.ref,c.keywords';
        }
    global 
$index_collection_creator;
    if (
$index_collection_creator)
        {
            
$indexfields .= ',u.fullname';
        } 
        
    
    
// if an index string wasn't supplied, generate one
    
if (!strlen($index_string) > 0){
        
$indexarray ps_query("select $indexfields from collection c left join user u on u.ref=c.user where c.ref = ?",array("i",$ref));
        for (
$i=0$i<count($indexarray); $i++){
            
$index_string "," implode(',',$indexarray[$i]);
        } 
    }

    
$keywords=split_keywords($index_string,true);
    for (
$n=0;$n<count($keywords);$n++)
        {
        if(
trim($keywords[$n])==""){continue;}
        
$keyref=resolve_keyword($keywords[$n],true);
        
ps_query("insert into collection_keyword values (?,?)",array("i",$ref,"i",$keyref));
        }
    
// return the number of keywords indexed
    
return $n;
    }

This article was last updated 5th October 2022 04:05 Europe/London time based on the source file dated 4th October 2022 09:50 Europe/London time.