0

I'm trying to implement a database search, by using match, against and fulltext indexing. So, when I did the search, it did not work as expect, no errors and no results was given. I'm querying by using Codeigniter.

Here is my PHP query code:

$clean_keyword = trim($keywords); //$keyword is passed to the function`
$this->db->select('question, answer')
         ->from('QA')
         ->where('MATCH(question) AGAINST("'.$clean_keyword.'")', null, FALSE);  
$query = $this->db->get(); //execute the previous statement and save the result in a variable. 

No errors from codeigniter/MySQL was given.

I tried to debug the $query variable by doing var_dump($query), see the results (N.B. The important part is result_array with size=0):

object(CI_DB_mysql_result)[19]
  public 'conn_id' => resource(30, mysql link persistent)
  public 'result_id' => resource(38, mysql result)
  public 'result_array' => 
    array (size=0)
      empty
  public 'result_object' => 
    array (size=0)
      empty
  public 'custom_result_object' => 
    array (size=0)
      empty
  public 'current_row' => int 0
  public 'num_rows' => int 0
  public 'row_data' => null

MySQL table schema:

CREATE TABLE `QA` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `question` varchar(200) CHARACTER SET utf8 NOT NULL,
  `answer` varchar(500) CHARACTER SET utf8 NOT NULL,
  `u_id` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  FULLTEXT KEY `question` (`question`)
) ENGINE=MyISAM
4

1 に答える 1

1

There was no errors in my code/database schema or anything, I just realized that FULLTEXT search doesn't show matches that only contains 1 word, example:
if I query this:
SELECT * FROM QA WHERE MATCH(question) AGAINST('drive');
and there is one question with the word drive ONLY, ill get no matches.
But if i alter the drive question column, to something like how to drive ill get a match.

于 2012-06-10T05:27:32.477 に答える