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

suggest_refinement()

Description

Suggests search refinements based on common keywords from a set of resource references.

This function analyzes the provided array of resource references and the original search query.
It identifies common keywords associated with the specified resources and suggests new search queries
by appending these keywords to the original search query, provided they are not already included in it.

Parameters

ColumnTypeDefaultDescription
$refs array An array of resource references to analyze.
$search string The original search query.

Return

array An array of suggested search refinements. Returns an empty array if no refinements can be suggested.

Location

include/search_functions.php lines 40 to 55

Definition

 
function suggest_refinement($refs,$search)
    {
    if (
count($refs)==0) {return array();} // Nothing to do, nothing to return
    
$in=ps_param_insert(count($refs));
    
$suggest=array();
    
# find common keywords
    
$refine=ps_query("SELECT k.keyword,count(k.ref) c FROM resource_node rn LEFT JOIN node n ON n.ref=rn.node LEFT JOIN node_keyword nk ON nk.node=n.ref LEFT JOIN keyword k on nk.keyword=k.ref WHERE rn.resource IN ($in) AND length(k.keyword)>=3 AND length(k.keyword)<=15 AND k.keyword NOT LIKE '%0%' AND k.keyword NOT LIKE '%1%' AND k.keyword NOT LIKE '%2%' AND k.keyword NOT LIKE '%3%' AND k.keyword NOT LIKE '%4%' AND k.keyword NOT LIKE '%5%' AND k.keyword NOT LIKE '%6%' AND k.keyword NOT LIKE '%7%' AND k.keyword NOT LIKE '%8%' AND k.keyword NOT LIKE '%9%' GROUP BY k.keyword ORDER BY c DESC LIMIT 5",ps_param_fill($refs,"i"));
    for (
$n=0;$n<count($refine);$n++)
        {
        if (
strpos($search,$refine[$n]["keyword"])===false)
            {
            
$suggest[]=$search " " $refine[$n]["keyword"];
            }
        }
    return 
$suggest;
    }

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.