You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
967 B

  1. <?php
  2. namespace TomLingham\Searchy\Matchers;
  3. /**
  4. * Matches Studly Case strings using the first letters of the words only.
  5. *
  6. * For example a search for 'hp' would match; 'HtmlServiceProvider' or 'HashParser' but not 'hasProvider'
  7. *
  8. * Class StudlyCaseMatcher
  9. */
  10. class StudlyCaseUnicodeMatcher extends BaseMatcher
  11. {
  12. /**
  13. * @var string
  14. */
  15. protected $operator = 'LIKE BINARY';
  16. /**
  17. * @param $searchString
  18. *
  19. * @return string
  20. */
  21. public function formatSearchString($searchString)
  22. {
  23. $results = [];
  24. preg_match_all('/./u', mb_strtoupper($searchString, 'UTF-8'), $results);
  25. return implode('%', $results[0]).'%';
  26. }
  27. public function buildQueryString($column, $searchString)
  28. {
  29. return "IF( CHAR_LENGTH( TRIM( $column )) = CHAR_LENGTH( REPLACE( TRIM( $column ), ' ', '')) AND $column {$this->operator} '{$this->formatSearchString($searchString)}', {$this->multiplier}, 0)";
  30. }
  31. }