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

get_suggested_keywords()

Description

Suggests complete existing keywords based on a partial search term.

This function fetches keywords that match the given partial word, returning
suggestions from the keyword database. It also considers user permissions by
excluding indexed fields that are hidden from the user. Additionally, it can
restrict results to a specific resource type field.

Parameters

ColumnTypeDefaultDescription
$search string The partial keyword to search for.
$ref string "" (optional) The resource type field to restrict suggestions to.

Return

array An array of suggested keywords matching the search criteria.

Location

include/search_functions.php lines 2726 to 2761

Definition

 
function get_suggested_keywords($search,$ref="")
    {
    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 4th December 2024 08:35 Europe/London time based on the source file dated 27th November 2024 09:40 Europe/London time.