Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource functions

get_suggested_keywords()

Parameters

ColumnTypeDefaultDescription
$search
$ref ""

Location

include/search_functions.php lines 2551 to 2587

Definition

 
function get_suggested_keywords($search,$ref="")
    {
    
# For the given partial word, suggest complete existing keywords.
    
global $autocomplete_search_items,$autocomplete_search_min_hitcount;
    
    
# Fetch a list of fields that are not available to the user - these must be omitted from the search.
    
$hidden_indexed_fields=get_hidden_indexed_fields();
    
    
$restriction_clause_node ""
    
$params=array("s",$search "%");

    if (
count($hidden_indexed_fields) > 0)
        {
        
$restriction_clause_node .= " AND n.resource_type_field NOT IN (" ps_param_insert(count($hidden_indexed_fields)) . ")";
        
$params=array_merge($params,ps_param_fill($hidden_indexed_fields,"i"));
        }
    
    if ((string)(int)
$ref == $ref)
        {
        
$restriction_clause_node .= " AND n.resource_type_field = ?";
        
$params[]="i";$params[]=$ref;
        }    
    
    
$params[]="i";$params[]=$autocomplete_search_items;

    return 
ps_array("SELECT ak.keyword value
        FROM
            (
            SELECT k.keyword, k.hit_count
            FROM keyword k
            JOIN node_keyword nk ON nk.keyword=k.ref
            JOIN node n ON n.ref=nk.node
            WHERE k.keyword LIKE ? " 
$restriction_clause_node "
            ) ak
        GROUP BY ak.keyword, ak.hit_count 
        ORDER BY ak.hit_count DESC LIMIT ?"
,$params);
    }

This article was last updated 19th March 2024 11:35 Europe/London time based on the source file dated 15th March 2024 17:00 Europe/London time.