app/Http/Controllers/SearchController.php
private function extractSearchTerms(string $query): array
    {
        $search_terms = [];

        // Words in double quotes stay together
        while (preg_match('/"([^"]+)"/', $query, $match)) {
            $search_terms[] = trim($match[1]);
            $query          = str_replace($match[0], '', $query);
        }

        // Other words get treated separately
        while (preg_match('/[\S]+/', $query, $match)) {
            $search_terms[] = trim($match[0]);
            $query          = str_replace($match[0], '', $query);
        }

        return $search_terms;
    }
private function extractSearchTerms(string $query): array
    {
        $search_terms = [];

        // Words in double quotes stay together
        while (preg_match('/"([^"]+)"/', $query, $match)) {
            $search_terms[] = trim($match[1]);
            $query          = str_replace($match[0], '', $query);
        }

        // Other words get treated separately
        while (preg_match('/[\S]+/', $query, $match)) {
            $search_terms[] = trim($match[0]);
            $query          = str_replace($match[0], '', $query);
        }

        return $search_terms;
    }
private function extractSearchTerms ( string $ query ) : array { $ search_terms = [ ] ; // Words in double quotes stay together while ( preg_match ( '/"([^"]+)"/' , $ query , $ match ) ) { $ search_terms [ ] = trim ( $ match [ 1 ] ) ; $ query = str_replace ( $ match [ 0 ] , '' , $ query ) ; } // Other words get treated separately while ( preg_match ( '/[\S]+/' , $ query , $ match ) ) { $ search_terms [ ] = trim ( $ match [ 0 ] ) ; $ query = str_replace ( $ match [ 0 ] , '' , $ query ) ; } return $ search_terms ; }
Convert the query into an array of search terms

@param string $query

@return string[]
Convert the query into an array of search terms