0
votes

Hey, Having a small issue that I don't quite understand with MYSQL fulltext search. I have this:

 $data = mysql_query("SELECT * FROM posts WHERE MATCH (article) AGAINST ('news')"); 

 while($result = mysql_fetch_array( $data )) 
 { 
 echo $result['title']; 
 echo "<br><br> "; 
 echo $result['article']; 
 echo "<br><br>"; 
 } 

 $anymatches=mysql_num_rows($data); 
 if ($anymatches == 0) 
 { 
 echo "Sorry, but we can not find an entry to match your query<br><br>"; 
 } 

 echo "<b>Searched For:</b> " .$search_term; 

This works fine. It pulls the title, and the article from the database, and echo's out all the information for each item in the database. Only pulls the information from 'article' columnthough..... (If "news" is in the title only, it won't show in the results.) And this happens vise versa. If I query MATCH (title), it'll only find posts with the given search term in the title, not the article

However, when I change the MATCH clause too: MATCH (title,article), I get zero results. Basically, I'm stuck MATCHing to only one column.

Here is my table schema for the posts table: (this is from an export)

CREATE TABLEposts (
id int(55) unsigned NOT NULL auto_increment,
title varchar(255) collate latin1_german2_ci default NULL,
article text collate latin1_german2_ci,
post_type varchar(255) collate latin1_german2_ci default NULL,
day text collate latin1_german2_ci,
user varchar(55) collate latin1_german2_ci default NULL,
month text collate latin1_german2_ci,
year int(4) default NULL,
member_id int(55) default NULL,
published tinyint(1) NOT NULL default '0',
draft tinyint(1) default '0',
slug varchar(255) collate latin1_german2_ci default NULL,
event_month varchar(255) collate latin1_german2_ci default NULL,
event_day1 int(2) default NULL,
event_day2 int(2) default NULL,
PRIMARY KEY (id),
FULLTEXT KEY title (title),
FULLTEXT KEY article (article)
) ENGINE=MyISAM ;

Anyone have any idea why it wouldn't like the second column to look in?

1

1 Answers

5
votes

Well define fulltext index on both fields:

FULLTEXT KEY title_article_fx (title, article)