简体   繁体   English

php mysql匹配没有结果

[英]php mysql match against no results

Alright, so I'm trying to do a Full Text search on my mysql table. 好吧,所以我正在尝试在我的mysql表上进行全文搜索。 Here is the query 这是查询

SELECT *,
       MATCH (title, joke) AGAINST ('welcome') AS relevance,
       MATCH (title) AGAINST ('welcome') AS title_relevance
FROM jokes
WHERE MATCH (title, joke) AGAINST ('welcome') 
AND flags < 5
ORDER BY title_relevance + relevance + ups DESC, downs ASC LIMIT 0, 30

and here is my table 这是我的桌子

CREATE TABLE IF NOT EXISTS `jokes` (
  `jid` varchar(24) NOT NULL,
  `uid` int(11) NOT NULL,
  `title` mediumtext NOT NULL,
  `joke` longtext NOT NULL,
  `ups` int(11) NOT NULL DEFAULT '0',
  `downs` int(11) NOT NULL DEFAULT '0',
  `flags` int(11) NOT NULL DEFAULT '0',
  `createddate` int(11) NOT NULL,
  `editdate` int(11) NOT NULL,
  PRIMARY KEY (`jid`),
  FULLTEXT KEY `searcher` (`title`,`joke`),
  FULLTEXT KEY `title` (`title`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

I have a couple rows that contain either welcome in the title, or in the joke, but I don't seem to get any results. 我有几行在标题或笑话中包含欢迎,但我似乎没有得到任何结果。 It doesn't matter what word I search for. 我搜索的是什么词并不重要。

I've also tried removing AND flags < 5 and also ups DESC, downs ASC LIMIT 0,30 我也尝试删除AND flags < 5并且还ups DESC, downs ASC LIMIT 0,30

Both don't seem to work. 两者似乎都不起作用。

This is what I do with the php code 这就是我用php代码做的事情

if($st->prepare($SearchQuery))
{
    if(!$st->execute())
        ChromePhp::log("Execute Error: " . $st->error);
    else
    {
        $results = fetchAll($st);
        $ret = new stdClass();
        $ret->TotalCount = 0;
        $ret->Results = $results;
        return $ret;
    }
}

and this is fetchAll(which has worked for every other query I've tossed at it). 这是fetchAll(它已经适用于我抛出的每一个其他查询)。

function fetchAll($result)
    {    
        $array = array();

        if($result instanceof mysqli_stmt)
        {
            $result->store_result();

            $variables = array();
            $data = array();
            $meta = $result->result_metadata();

            while($field = $meta->fetch_field())
                $variables[] = &$data[$field->name]; // pass by reference

            call_user_func_array(array($result, 'bind_result'), $variables);

            $i=0;
            while($result->fetch())
            {
                $array[$i] = array();
                foreach($data as $k=>$v)
                    $array[$i][$k] = $v;
                $i++;

                // don't know why, but when I tried $array[] = $data, I got the same one result in all rows
            }
        }
        elseif($result instanceof mysqli_result)
        {
            while($row = $result->fetch_assoc())
                $array[] = $row;
        }

        return $array;
    }

Anyone have any ideas what I'm doing wrong here? 任何人都有任何想法,我在这里做错了什么?

Thanks. 谢谢。

I'm not too sure if it will make much of a difference, but have you tried using Boolean Mode? 我不太确定它是否会产生很大的影响,但你尝试过使用布尔模式吗? Like this: 像这样:

AGAINST ('welcome' IN BOOLEAN MODE)

Because 'welcome' is a STOPWORD , so that MySQL skips to search for this word. 因为'welcome'是一个STOPWORD ,所以MySQL跳过来搜索这个单词。

See the stopword list of MySQL Full text search here 请在此处查看MySQL全文搜索的禁用词列表

http://dev.mysql.com/doc/refman/5.5/en/fulltext-stopwords.html http://dev.mysql.com/doc/refman/5.5/en/fulltext-stopwords.html

And please remind the length of words in the search phrase also, if its length less than 4, by default MySQL will skips for search it too. 请提醒搜索短语中的单词长度,如果长度小于4,默认情况下MySQL也会跳过进行搜索。

For example "the way I am", "usa", "php", "job" etc (read more about ft_min_word_len ) 例如“我的方式”,“美国”,“php”,“工作”等(了解更多关于ft_min_word_len

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM