Collections functions
Encryption functions
General functions
Theme permission functions
Resource functions

refine_searchstring()

Parameters

ColumnTypeDefaultDescription
$search

Location

include/search_functions.php lines 471 to 547

Definition

 
function refine_searchstring($search)
    {
    
# This function solves several issues related to searching.
    # it eliminates duplicate terms, helps the field content to carry values over into advanced search correctly, fixes a searchbar bug where separators (such as in a pasted filename) cause an initial search to fail, separates terms for searchcrumbs.
    
    
global $use_refine_searchstring$dynamic_keyword_and;
    
    if (!
$use_refine_searchstring){return $search;}
    
    if (
substr($search,0,1)=="\"" && substr($search,-1,1)=="\"") {return $search;} // preserve string search functionality.
    
    
global $noadd;
    
$search=str_replace(",-",", -",$search);
    
$search=str_replace ("\xe2\x80\x8b","",$search);// remove any zero width spaces.
    
    
$keywords=split_keywords($searchfalsefalsefalsefalsetrue);

    
$orfields=get_OR_fields(); // leave checkbox type fields alone
    
$dynamic_keyword_fields=sql_array("SELECT name value FROM resource_type_field where type=9""schema");
    
    
$fixedkeywords=array();
    foreach (
$keywords as $keyword)
        {
        if (
strpos($keyword,"startdate")!==false || strpos($keyword,"enddate")!==false)
            {
            
$keyword=str_replace(" ","-",$keyword);
            }
             
        if(
strpos($keyword,"!collection") === 0)
            {
            
$collection=intval(substr($search,11));
            
$keyword "!collection" $collection;
            }
    
        if (
strpos($keyword,":")>0)
            {
            
$keywordar=explode(":",$keyword,2);
            
$keyname=$keywordar[0];
            if (
substr($keyname,0,1)!="!")
                {
                if(
substr($keywordar[1],0,5)=="range"){$keywordar[1]=str_replace(" ","-",$keywordar[1]);}
                if (!
in_array($keyname,$orfields) && (!$dynamic_keyword_and || ($dynamic_keyword_and && !in_array($keyname$dynamic_keyword_fields))))
                    {
                    
$keyvalues=explode(" ",str_replace($keywordar[0].":","",$keywordar[1]));
                    }
                else
                    {
                    
$keyvalues=array($keywordar[1]);
                    }
                foreach (
$keyvalues as $keyvalue)
                    {
                    if (!
in_array($keyvalue,$noadd))
                        { 
                        
$fixedkeywords[]=$keyname.":".$keyvalue;
                        }
                    }
                }
            else if (!
in_array($keyword,$noadd))
                {
                
$keywords=explode(" ",$keyword);
                
$fixedkeywords[]=$keywords[0];
                } 
// for searches such as !list
            
}
        else
            {
            if (!
in_array($keyword,$noadd))
                { 
                
$fixedkeywords[]=$keyword;
                }
            }
        }
    
$keywords=$fixedkeywords;
    
$keywords=array_unique($keywords);
    
$search=implode(", ",$keywords);
    
$search=str_replace(",-"," -",$search); // support the omission search
    
return $search;
    }

This article was last updated 12th July 2020 04:35 Europe/London time based on the source file dated 7th July 2020 15:22 Europe/London time.