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

sorthighlights()

Description

Comparison function for sorting highlights by their length.

This function is used to sort keyword highlights for the `str_highlight` function.
It ensures that keywords are sorted based on their length, with shorter keywords
coming before longer ones. If the lengths are equal, it sorts them alphabetically.

This fixes an odd problem for str_highlight related to the order of keywords.

Parameters

ColumnTypeDefaultDescription
$a string The first string to compare.
$b string The second string to compare.

Return

int Returns 0 if lengths are equal, -1 if $a is shorter than $b, and 1 if $a is longer than $b.

Location

include/search_functions.php lines 2706 to 2712

Definition

 
function sorthighlights($a$b)
    {
    if (
strlen($a) < strlen($b)) {
        return 
0;
        }
    return (
$a $b) ? -1;
    }

This article was last updated 14th December 2024 20:35 Europe/London time based on the source file dated 12th December 2024 10:30 Europe/London time.