I need to know what’s the best way to search tables with million records. I have a table called <people> and this table has the column: <status>
Status might be more than one word like:
“I am happy today and the weather is nice”.
Also, it might be in different languages.
Records in table are represented by UTF-8.
I need to search for a sub-word, word, or even some words out of the whole sentence like for example (according the status above):
Search 1: keyword = “ppy”
Search 2: keyword = “am weather”
Search 3: keyword = “nice”
Search 4: keyword = “day weath”
I would greatly appreciate if you hint me to the best method to apply a robust search. As far as I know using “LIKE” is not practical for huge records. I heard about the full text index but never used that.
I will go for the full text index search. I would appreciate if you clear the right equivalent statement in full text search for the below:
$sql = ’ SELECT people.status, people.id FROM people WHERE
people.status LIKE “%‘.$keySearch.’%” AND people.id != “‘.$this->myId.’” ORDER BY people.time ASC LIMIT '.$limit;
Also, what shall I do to the table in mysql? I never worked on this so your detailed answer is much appreciated.
I have changed the column “status” to full text index and the engine is MyISAM. I have tried the below sql but it is not working I am getting the error:
“test” AND people.id != “‘.$this->myId.’” ORDER BY people.time ASC LIMIT '.$limit;
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near “test”
$keySearch=“test”;
$limit=10;
$this->myId=1;
$sql = ’ SELECT people.status, people.id FROM people WHERE MATCH (people.status) AGAINST “‘.$keySearch.’” AND people.id != “‘.$this->myId.’” ORDER BY people.time ASC LIMIT '.$limit;
But “sello” is same case. Please look at the two tables. When searching for “sello”, I am getting 4 hits, while when searching for “hello” I am getting 0 hits! WHY!!
Sorry & thanks. So the full text search should be applied on the huge records, and before getting huge records, we can apply the “LIKE” then we convert.