customSearch::searchSort

Description

Callback for usort used to sort the search results.

Syntax

int customSearch::searchSort (string $a, string $b)



Parameter $a

Expected type: String
Description: A search term to compare



Parameter $b

Expected type: String
Description: Another search term to compare to the first one



Return value

Expected type: Enumerated Integer
Description: -1 if $b has a higher weight than $a, 0 if they're equal or 1 if $a has a higher weight than $b

Possible integer values
Allowed values Description
-1 $b has a higher weight than $a
0 $a and $b are of equal weight
1 $a has a higher weight than $b


Notes

  • Sorts larger words before smaller words
  • Sorts words that are included in the search before those that aren't
  • Compares the length of the two words
  • Weight is determined by finding the length of the word and subtracting 1000 if it's in the array of excluded terms
Advertisement: