简体   繁体   English

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

[英]PHP/MySQL Search not returning ALL results

So I have a form which searches through a list of companies to see if that particular company is registered on the site. 因此,我有一个搜索公司列表的表单,以查看该公司是否已在网站上注册。

When the company name is three or less characters and I can see it is in the database the results wont show. 当公司名称是三个或更少的字符,并且我可以看到它在数据库中时,结果将不会显示。

For example, if the company's name is "ABB Eutech" and the search is for ABB, then the search returns 0. 例如,如果公司名称为“ ABB Eutech”,而搜索是针对ABB,则搜索返回0。

However if you search for Eutech then the search returns the result. 但是,如果您搜索Eutech,则搜索将返回结果。

Here's the code I'm using: 这是我正在使用的代码:

    <?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>";
                }
            }
        }
    ?>

Any help greatly received! 任何帮助大受好评! ...Be gentle, it's my first time. ...温柔,这是我的第一次。

Words that contain three characters or less are omitted from a fulltext index in MySQL by default. 默认情况下,MySQL全文索引中会忽略三个或三个以下字符的单词。

The minimum and maximum lengths of words to be indexed are defined by the ft_min_word_len and ft_max_word_len system variables. 要索引的单词的最小和最大长度由ft_min_word_len和ft_max_word_len系统变量定义。 (See Section 5.1.3, “Server System Variables”.) The default minimum value is four characters; (请参见第5.1.3节“服务器系统变量”。)默认的最小值是四个字符;默认值为4个字符。 the default maximum is version dependent. 默认最大值取决于版本。 If you change either value, you must rebuild your FULLTEXT indexes. 如果更改这两个值,则必须重建FULLTEXT索引。 For example, if you want three-character words to be searchable, you can set the ft_min_word_len variable by putting the following lines in an option file: [mysqld] ft_min_word_len=3 例如,如果希望可搜索三个字符的单词,则可以通过将以下行放在选项文件中来设置ft_min_word_len变量:[mysqld] ft_min_word_len = 3

Then restart the server and rebuild your FULLTEXT indexes. 然后重新启动服务器并重建您的FULLTEXT索引。 Note particularly the remarks regarding myisamchk in the instructions following this list. 请特别注意此列表后面的说明中有关myisamchk的备注。

http://dev.mysql.com/doc/refman/5.0/en/fulltext-fine-tuning.html 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