Question

I have a table with 2 columns as Email and ID. I want to search exact matching Email value in column.

I have setup my Table with MyISAM Engine and set Email column with FullText index. When I run query to search for exact match it sometimes work and sometimes it fails.

this is my table definition

CREATE TABLE `tbl_email` (
    `email` varchar(60),
    `uid` int(11)
    FULLTEXT KEY `EmailIndex` (`email`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1

And this is my Query to match against my email value

select uid from tbl_email where MATCH(email) AGAINST ('abcdefghi@yahoo.com') 
limit 1;

It sometimes work and sometimes it fails to return matching result even though there is a matching result in table. Am I doing anything wrong? What should I do to match exact value in FullText searching?

I also tried using IN BOOLEAN MODE but that is same no use like this

select uid from tbl_email where MATCH(email) AGAINST ('abcdefghi@yahoo.com' 
IN BOOLEAN MODE) limit 1;
Was it helpful?

Solution

As far as I know that FullText index searching interprets the search string as a phrase in natural human language and breaks words if necessary for searching as said on http://dev.mysql.com/doc/refman/5.5/en/fulltext-search.html and most important look here

*The stopword list applies. In addition, words that are present in 50% or more of the rows are considered common and do not match. *

And I believe that your every email will have .com (. as stopword) in it meaning your whole table will be matched against your provided search.

You better go with simple indexing with InnoDB as it will be better for faster inserting of records and make simple where clause.

I don't know what algorithm is used for FullText searching as opposed to normal index for string search but suppose if you are doing it with FullText indexing, I guess due to different interpretations it will take more than normal index because then it will have to look every email value as all have stop words like @ and .com etc. But this is just my understanding I am not a Data Search Algorithm Maker.

OTHER TIPS

You don't have to match using full text, you can simply run:

SELECT uid FROM tbl_email WHERE email='abcedfghi@yahoo.com' LIMIT 1;

That query should return exactly what you want to fetch.

According to the MySQL 5.5 reference page when using FULLTEXT to find exact phrases you would enclose them in single and double quotes. The single quotes are delimiters while the double quotes encapsulate your query.

e.g. : ... MATCH(email) AGAINST('"someone@example.com"') ...

However, echoing what others have already said, a simple WHERE clause outta get you by from the looks of your query. I think FULLTEXT is better suited to find keywords in heaps of information within a record, not single value fields like an email field.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top