0

在这个 ssql 查询中,我%AGAINST子句中使用了 a。

            SELECT firstname,lastname,middlename,company_name, 
                    primary_emailaddress,alternate_emailaddress,personal_address_line1,
                    personal_address_line2,personal_address_city,facebook_username,
                    twitter_username,googleplus_username,linkedin_username,
                    personal_website_url,birthday_month,notes,personal_address_zipcode,
                    company_address_zipcode,home_phonenumber,company_phonenumber,
                    cell_phonenumber,birthday_day,birthday_year,hash,image_file
             FROM contacts
             WHERE (
                MATCH(
                    firstname,middlename,lastname,
                    primary_emailaddress,alternate_emailaddress,personal_address_line1,
                    personal_address_city,company_name,
                    company_address_line1,company_address_city,
                    facebook_username,twitter_username,googleplus_username,linkedin_username,
                    personal_website_url,birthday_month,notes
                )
                AGAINST ('someemail@email.com%' IN BOOLEAN MODE) 
                OR personal_address_zipcode REGEXP('(someemail@email.com*)') 
                OR company_address_zipcode REGEXP('(someemail@email.com*)') 
                OR home_phonenumber REGEXP('(someemail@email.com*)') 
                OR company_phonenumber REGEXP('(someemail@email.com*)') 
                OR cell_phonenumber REGEXP('(someemail@email.com*)') 
                OR birthday_day REGEXP('(someemail@email.com*)') 
                OR birthday_year REGEXP('(someemail@email.com*)') 
            ) 
            AND addressbook_id = 4

在这个 ssql 查询中,我*AGAINST子句中使用了 a。

            SELECT firstname,lastname,middlename,company_name, 
                    primary_emailaddress,alternate_emailaddress,personal_address_line1,
                    personal_address_line2,personal_address_city,facebook_username,
                    twitter_username,googleplus_username,linkedin_username,
                    personal_website_url,birthday_month,notes,personal_address_zipcode,
                    company_address_zipcode,home_phonenumber,company_phonenumber,
                    cell_phonenumber,birthday_day,birthday_year,hash,image_file
             FROM contacts
             WHERE (
                MATCH(
                    firstname,middlename,lastname,
                    primary_emailaddress,alternate_emailaddress,personal_address_line1,
                    personal_address_city,company_name,
                    company_address_line1,company_address_city,
                    facebook_username,twitter_username,googleplus_username,linkedin_username,
                    personal_website_url,birthday_month,notes
                )
                AGAINST ('someemail@email.com*' IN BOOLEAN MODE) 
                OR personal_address_zipcode REGEXP('(someemail@email.com*)') 
                OR company_address_zipcode REGEXP('(someemail@email.com*)') 
                OR home_phonenumber REGEXP('(someemail@email.com*)') 
                OR company_phonenumber REGEXP('(someemail@email.com*)') 
                OR cell_phonenumber REGEXP('(someemail@email.com*)') 
                OR birthday_day REGEXP('(someemail@email.com*)') 
                OR birthday_year REGEXP('(someemail@email.com*)') 
            ) 
            AND addressbook_id = 4

两者都不会返回内容精确等于 atleast 的位置someemail@email.com。它通过 com 或电子邮件或其他方式返回所有内容。我需要做哪些改变?FULLTEXT匹配列上有一个索引。

4

2 回答 2

1

最好将地址放在引号中,并且根本不使用通配符:

AGAINST ('"someemail@email.com"' IN BOOLEAN MODE)

像那样。

而且我认为您不需要布尔模式。

于 2013-07-31T20:29:17.260 回答
0

您的全文搜索不起作用,因为@and .(实际上是大多数非字母数字字符)是单词分隔符。因此 1. 电子邮件被索引为三个单独的单词和 2. 单词分隔符从您的搜索字符串中被忽略。

只需在列上创建一个常规的多列索引,然后使用标准搜索LIKE

WHERE firstname LIKE 'someemail@email.com%' OR ...

此查询将能够使用索引并且搜索将非常有效。

另外,摆脱这些REGEXP(). 它们是无用的(冗余的)并且会扼杀你的表现(不能使用索引)。

于 2013-07-31T21:17:55.080 回答