Hi,
My suggestion would be to create a cross-reference table where you have a list of all the words that appear in your head and body columns. See the following layout.
CREATE TABLE page (
page_id int(10) unsigned NOT NULL auto_increment,
page_url varchar(200) NOT NULL default '',
PRIMARY KEY (page_id)
) TYPE=MyISAM;
CREATE TABLE word (
word_id int(10) unsigned NOT NULL auto_increment,
word_word varchar(50) NOT NULL default '',
PRIMARY KEY (word_id)
) TYPE=MyISAM;
CREATE TABLE occurrence (
occurrence_id int(10) unsigned NOT NULL auto_increment,
word_id int(10) unsigned NOT NULL default '0',
page_id int(10) unsigned NOT NULL default '0',
PRIMARY KEY (occurrence_id)
) TYPE=MyISAM;
Then when you area searching for a specific words you can say
SELECT p.page_url AS url,
COUNT(*) AS occurrences
FROM page p, word w, occurrence o
WHERE p.page_id = o.page_id AND
w.word_id = o.word_id AND
w.word_word = \"$keyword\"
GROUP BY p.page_id
ORDER BY occurrences DESC
LIMIT 5
And then you will not have to search the database using the "where something like '%blah%'" this is what is killing the database perforamcne. You sould notice a 1500% increase in speed.
This is not my idea it is fully outlined here http://www.onlamp.com/lpt/a/2753 and it also includes sample code to extract the words and insert the data into a database. From here if you use indexes this should improve speed even more.
Hope this helps,
- Justin