繁体   English   中英

PHP / MySQL搜索未返回所有结果

[英]PHP/MySQL Search not returning ALL results

因此,我有一个搜索公司列表的表单,以查看该公司是否已在网站上注册。

当公司名称是三个或更少的字符,并且我可以看到它在数据库中时,结果将不会显示。

例如,如果公司名称为“ ABB Eutech”,而搜索是针对ABB,则搜索返回0。

但是,如果您搜索Eutech,则搜索将返回结果。

这是我正在使用的代码:

    <?php 
        $out = '';
        if ((isset($_POST['companysearch-name'])) && ($_POST['companysearch-name']==NULL)) {
            $out .= '<h3>No matches. Please enter a company name.</h3>';
        } else if (isset($_POST['companysearch-name'])) {
            $queryString = htmlspecialchars($_POST['companysearch-name'],ENT_QUOTES);                   
            if(strlen($queryString) >0) {
                $query = $wpdb->get_results("SELECT DISTINCT (company_name) FROM wp_companies WHERE MATCH (company_name) AGAINST ('$queryString')");
                $searchStr = "%" . $queryString . "%";
                $searchStr = str_replace(" ","%",$searchStr);
                $numresults = count($query);
                if($query) {
                    $out .= '<div><ul>';
                    foreach($query as $result):

                    $out .= '<li>'.$result->company_name.'</li>';
                    endforeach;
                    $out .= '</ul></div>';
                    $out .= "<p>Is your company on this list? If YES, your company already has the scheme in place and you can setup a donation right now.</p>";
                    $out .= '<a class="button" href="/donate/"><span>Start Giving</span><b></b></a>';
                } else {
                    $out .= '<h3>No matches found.</h3>';
                    $out .= "<p>Can't find your employer? They may have only just signed up - <a href='/contact-us/'>contact us</a> and we'll check it out for you.</p>";
                }
            }
        }
    ?>

任何帮助大受好评! ...温柔,这是我的第一次。

默认情况下,MySQL全文索引中会忽略三个或三个以下字符的单词。

要索引的单词的最小和最大长度由ft_min_word_len和ft_max_word_len系统变量定义。 (请参见第5.1.3节“服务器系统变量”。)默认的最小值是四个字符;默认值为4个字符。 默认最大值取决于版本。 如果更改这两个值,则必须重建FULLTEXT索引。 例如,如果希望可搜索三个字符的单词,则可以通过将以下行放在选项文件中来设置ft_min_word_len变量:[mysqld] ft_min_word_len = 3

然后重新启动服务器并重建您的FULLTEXT索引。 请特别注意此列表后面的说明中有关myisamchk的备注。

http://dev.mysql.com/doc/refman/5.0/en/fulltext-fine-tuning.html

暂无
暂无

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

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