Owl\Libraries\FtsUtils::createMatchWord PHP Method

createMatchWord() public static method

convert search words into ngram favored search words
public static createMatchWord ( $word )
    public static function createMatchWord($word)
    {
        $searchWords = array();
        $words = preg_split("/( | )/", trim($word));
        foreach ($words as $word) {
            $searchWords[] = self::toNgram($word);
        }
        return implode(' ', $searchWords);
    }

Usage Example

Example #1
0
    /**
     * get tags data by string for FullTextSearch.
     *
     * @param string $string
     * @param int $limit
     * @param int $offset
     * @return array
     */
    public function match($str, $limit = 10, $offset = 0)
    {
        $query = <<<__SQL__
            SELECT
              ta.name
            FROM
              tags_fts fts 
            INNER JOIN
              tags ta ON ta.id = fts.tag_id
            WHERE
              fts.words MATCH :match
            ORDER BY
              ta.updated_at DESC
            LIMIT 
              {$limit} 
            OFFSET
              {$offset} 
__SQL__;
        return \DB::select(\DB::raw($query), array('match' => FtsUtils::createMatchWord($str)));
    }
All Usage Examples Of Owl\Libraries\FtsUtils::createMatchWord