ShadowZzz
ShadowZzz

Reputation: 415

Full text Search not working

I'm trying to implement a full text search, as I want to allow the users to type in a string of texts and find a result that matches the most. I have made one using online tutorials, but they do not appear to work.

Here is the database create statement: delimiter $$

CREATE TABLE `word_list` (
  `item_id` int(11) NOT NULL,
  `item_name` text,
  `item_tags` text,
  `item_description` varchar(255) NOT NULL DEFAULT 'none',
  `item_added_by` varchar(45) NOT NULL DEFAULT 'system',
  `item_display` int(1) NOT NULL DEFAULT '1',
  PRIMARY KEY (`item_id`),
  FULLTEXT KEY `word_list` (`item_name`,`item_tags`),
  FULLTEXT KEY `item_name` (`item_name`,`item_tags`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1$$

and here is my code:

<?php
error_reporting(E_ALL ^ E_NOTICE);

$_POST['search'] = 'red';
//if we got something through $_POST
if (isset($_POST['search'])) {
$searchQ = $_POST['search'];
$link = mysql_connect('localhost', '', '');
mysql_select_db("", $link);
$res = mysql_query("SELECT * from word_list WHERE MATCH (item_name, item_tags) AGAINST('$searchQ')", $link);
echo mysql_errno($link) . ": " . mysql_error($link) . "\n";

$ant = mysql_num_rows($res);
    if ($ant > 0) { // query provided results – display results
    echo ("<br/><h2>Search results for \"$searchQ\":</h2>");
        while ($result = mysql_fetch_array($res)) {
            echo ("<h3>{$result['name']} ({$result['score']})</h3>{$result['description']}<br/><br/>");
        }
    } else { // query provided 0 results – display 0 hit message
    echo ("Sorry... Searching for \"$searchQ\" gave no results");
    }
}
?>

Please let me know what I'm doing wrong.

Upvotes: 0

Views: 247

Answers (1)

deepu sankar
deepu sankar

Reputation: 4455

I think the issue is - MySQL Ignoring Small Words in Full-Text Search Using MATCH AGAINST, Take a look at this blog http://biostall.com/mysql-ignoring-small-words-in-full-text-search-using-match-against.

Upvotes: 1

Related Questions