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

resolve_keyword()

Description

Resolve keyword

Parameters

ColumnTypeDefaultDescription
$keyword string The keyword to resolve
$create bool false If keyword not found, should we create it instead?
$normalize bool true Should we normalize the keyword before resolving?
$stem bool true Should we use the keywords' stem when resolving?

Return

int|bool Returns the keyword reference for $keyword, or false if no such keyword exists.

Location

include/search_functions.php lines 2189 to 2229

Definition

 
function resolve_keyword($keyword$create false$normalize true$stem true)
{
    
debug_function_call("resolve_keyword"func_get_args());

    
// Create a cache to ensure we find new nodes subsequently if in a transaction
    
global $resolve_keyword_cache;
    global 
$quoted_string$stemming;
    
$kwhash md5($keyword) . md5("!" $keyword . ($normalize "NORM" "") . ($stem "STEM" ""));
    if (isset(
$resolve_keyword_cache[$kwhash])) {
        return 
$resolve_keyword_cache[$kwhash];
    }
    
$keyword mb_strcut($keyword0100); # Trim keywords to 100 chars for indexing, as this is the length of the keywords column.

    
if (!$quoted_string && $normalize) {
        
$keyword normalize_keyword($keyword);
        
debug("resolving normalized keyword " $keyword  ".");
    }

    
# Stemming support. If enabled and a stemmer is available for the current language, index the stem of the keyword not the keyword itself.
    # This means plural/singular (and other) forms of a word are treated as equivalents.

    
if ($stem && $stemming && function_exists("GetStem")) {
        
$keyword GetStem($keyword);
    }

    
$return ps_value("SELECT ref value FROM keyword WHERE keyword = ?", array("s",trim($keyword)), 0"keyword");
    if (
$return === 0) {
        if (
$create) {
            
# Create a new keyword.
            
debug("resolve_keyword: Creating new keyword for " $keyword);
            
ps_query("insert into keyword (keyword,soundex,hit_count) values (?,left(?,10),0)", array("s",$keyword,"s",soundex($keyword)));
            
$return sql_insert_id();
            
clear_query_cache("keyword");
        } else {
            return 
false;
        }
    }

    
$resolve_keyword_cache[$kwhash] = $return;
    return 
$return;
}

This article was last updated 11th February 2025 20:35 Europe/London time based on the source file dated 10th February 2025 15:05 Europe/London time.