get_related_keywords()

Description

Retrieves keywords related to a given keyword reference.

This function checks a cache for related keywords associated with the provided
keyword reference. If not found in the cache, it queries the database for related
keywords. The relationship can be one-way or bidirectional based on the
configuration. It returns an array of related keyword references.

Parameters

ColumnTypeDefaultDescription
$keyref int The reference ID of the keyword for which to find related keywords.

Return

array An array of related keyword references.

Location

include/search_functions.php lines 2562 to 2582

Definition

 
function get_related_keywords($keyref)
{
    
debug_function_call("get_related_keywords"func_get_args());

    
# For a given keyword reference returns the related keywords
    # Also reverses the process, returning keywords for matching related words
    # and for matching related words, also returns other words related to the same keyword.
    
global $keyword_relationships_one_way$related_keywords_cache;

    if (isset(
$related_keywords_cache[$keyref])) {
        return 
$related_keywords_cache[$keyref];
    } else {
        if (
$keyword_relationships_one_way) {
            
$related_keywords_cache[$keyref] = ps_array("SELECT related value FROM keyword_related WHERE keyword = ?", array("i"$keyref), "keywords_related");
            return 
$related_keywords_cache[$keyref];
        } else {
            
$related_keywords_cache[$keyref] = ps_array("SELECT keyword value FROM keyword_related WHERE related = ? UNION SELECT related value FROM keyword_related WHERE (keyword = ? OR keyword IN (SELECT keyword value FROM keyword_related WHERE related = ?)) AND related <> ?", array("i"$keyref"i"$keyref"i"$keyref"i"$keyref), "keywords_related");
            return 
$related_keywords_cache[$keyref];
        }
    }
}

This article was last updated 18th April 2025 14:35 Europe/London time based on the source file dated 17th April 2025 18:30 Europe/London time.