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 38 to 53

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 18th March 2025 14:35 Europe/London time based on the source file dated 11th March 2025 14:15 Europe/London time.