Skip to content

Commit

Permalink
#14 検索を改善
Browse files Browse the repository at this point in the history
  • Loading branch information
fumikito committed Feb 23, 2024
1 parent 2dcc129 commit 6c975cf
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions lib/WCTokyo/WpCheckin/Tickets.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,22 @@ public static function search( $query = '', $page = 1 ) {
return ! $not_found;
} ) );
} elseif ( $query ) {
// This is string search.
$tickets = array_values( array_filter( self::tickets( false ), function( $ticket ) use ( $query ) {
// Flatten array.
$str = implode( '', $ticket );
return str_contains( $str, $query );
} ) );
$query = array_values( array_filter( preg_split( '/[  +]/u', $query ) ) );
$tickets = self::tickets( false );
if ( ! empty( $query ) ) {
// This is string search.
$tickets = array_values( array_filter( $tickets, function( $ticket ) use ( $query ) {
// Flatten array.
$str = implode( '', $ticket );
$matched = 0;
foreach ( $query as $q ) {
if ( str_contains( $str, $q ) ) {
$matched++;
}
}
return count( $query ) === $matched;
} ) );
}
} else {
$tickets = self::tickets( false );
}
Expand Down

0 comments on commit 6c975cf

Please sign in to comment.