split_keywords()

Parameters

ColumnTypeDefaultDescription
$search
$index false
$partial_index false
$is_date false
$is_html false
$keepquotes false
$preserve_separators bool false

Location

include/search_functions.php lines 2110 to 2201

Definition

 
function split_keywords($search$index false$partial_index false$is_date false$is_html false$keepquotes falsebool $preserve_separators false)
{
    
# Takes $search and returns an array of individual keywords.
    
global $permitted_html_tags$permitted_html_attributes;

    if (
$index && $is_date) {
        
# Date handling... index a little differently to support various levels of date matching (Year, Year+Month, Year+Month+Day).
        
$s explode("-"$search);
        if (
count($s) >= 3) {
            return array(
$s[0],$s[0] . "-" $s[1],$search);
        } elseif (
is_array($search)) {
            return 
$search;
        } else {
            return array(
$search);
        }
    }

    
# Remove any real / unescaped lf/cr
    
$search str_replace("\r"" "$search);
    
$search str_replace("\n"" "$search);
    
$search str_replace("\\r"" "$search);
    
$search str_replace("\\n"" "$search);

    if (
$is_html || (substr($search01) == "<" && substr($search, -11) == ">")) {
        
// String can't be in encoded format at this point or string won't be indexed correctly.
        
$search html_entity_decode($search);
        if (
$index) {
            
// Clean up html for indexing
            // Allow indexing of anchor text
            
$allowed_tags array_merge(array("a"), $permitted_html_tags);
            
$allowed_attributes array_merge(array("href"), $permitted_html_attributes);
            
$search strip_tags_and_attributes($search$allowed_tags$allowed_attributes);

            
// Get rid of the actual html tags and attribute ids to prevent indexing these
            
foreach ($allowed_tags as $allowed_tag) {
                
$search str_replace(array("<" $allowed_tag ">","<" $allowed_tag,"</" $allowed_tag), " "$search);
            }
            foreach (
$allowed_attributes as $allowed_attribute) {
                
$search str_replace($allowed_attribute "="" "$search);
            }
            
// Remove any left over tag parts
            
$search str_replace(array(">""<","="), " "$search);
        }
    }

    
$ns trim_spaces($search);

    if (!
$index && strpos($ns":") !== false) { # special 'constructed' query type
        
if ($keepquotes) {
            
preg_match_all('/("|-")(?:\\\\.|[^\\\\"])*"|\S+/'$ns$matches);
            
$return trim_array($matches[0], ",");
        } elseif (
strpos($ns"startdate") !== false || strpos($ns"enddate") !== false) {
            
$return explode(","$ns);
        } else {
            
$ns cleanse_string($ns$preserve_separators, !$index$is_html);
            
$return explode(" "$ns);
        }
        
// If we are not breaking quotes we may end up a with commas in the array of keywords which need to be removed
        
if ($keepquotes) {
            
$return trim_array($return",");
        }
        return 
$return;
    } else {
        
# split using spaces and similar chars (according to configured whitespace characters)
        
if (!$index && $keepquotes && strpos($ns"\"") !== false) {
            
preg_match_all('/("|-")(?:\\\\.|[^\\\\"])*"|\S+/'$ns$matches);

            
$splits $matches[0];
            
$ns = array();
            foreach (
$splits as $split) {
                if (!(
substr($split01) == "\"" && substr($split, -11) == "\"") && strpos($split",") !== false) {
                    
$split explode(","$split);
                    
$ns array_merge($ns$split);
                } else {
                    
$ns[] = $split;
                }
            }
        } else {
            
# split using spaces and similar chars (according to configured whitespace characters)
            
$ns explode(" "cleanse_string($nsfalse, !$index$is_html));
        }

        if (
$keepquotes) {
            
$ns trim_array($ns",");
        }

        if (
$index && $partial_index) {
            return 
add_partial_index($ns);
        }
        return 
$ns;
    }
}

This article was last updated 9th July 2025 08:35 Europe/London time based on the source file dated 29th June 2025 21:20 Europe/London time.