如何根据首先找到的关键字数量对搜索结果进行排序?

I have this php code and i can not make my search results to show me first the listings with the most number of keywords i have type. How can do that?

$search_array = array_unique(explode(' ', $search));
            foreach ($search_array as $k => $v)
            {
                $w = trim($v);
                 if ($w)
                {
                    $result[$i]['title'] = preg_replace('/(' . preg_quote($w, '/') . ')/siU', '<b>\\1</b>', $result[$i]['title']);
                    $result[$i]['description'] = preg_replace('/(' . preg_quote($w, '/') . ')/siU', '<b>\\1</b>', $result[$i]['description']);
                }
            }