tags:

views:

171

answers:

1

Is there a way to select entries from fulltext index in MySQL?

A: 

No, not that I know of. It would be a great feature though.

I built a search interface with autocomplete on top of MySQL. I run a daily job that scans all columns in all tables that I want to search in, extract words with regular expressions, then store the words in a separate table. I also have a many-to-many table with one column to hold the id of the object, and one column to hold the id of the word so as to record the fact that "word is part of text belonging to object".

The autocomplete works by taking the words typed into the box, and then generating a query that goes like:

SELECT     obj.title
FROM       obj_word
INNER JOIN obj
ON         obj_word.obj_id = obj.id
INNER JOIN word
ON         obj_word.word_id = word.id
WHERE      word.word IN ('word1', 'word2', 'word3') -- generated dynamically, word1 etc     are typed by the user
GROUP BY   obj.id
HAVING COUNT(DISTINCT word.id) = 3 -- the 3 is generated, because user typed 3 words.

This works fairly well for me, but I don't have huge amounts of data to work with.

(the actual implementation is slightly fancier, beause the last word is matched with LIKE to allow partial matches)

EDIT:

I just learned that the myisam_ft_dump utility may be used to extract a list of words from the index file. The command line goes something like this:

myisam_ftdump -d film_text 1  > D:\tmp\out.txt

Here, -d means dump (get a list of all entries), film_text is the name of a MyISAM table with a full text index, 1 is one, and ordinal identifying which index you want to dump.

I must say, the utility works, but I am not surer it is fast enough to use this for pulling a live list for autocompletion. You could of course have a periodical job that runs the command and dumps it to file. Unfortunately this dumps index entries not individual, unique words.

My hunch is you could use this utility as a means to extract the words, but it will need processing to turn it into a proper autocomplete list.

Roland Bouman
yeah this is almost what needed. live queries arent that necessary.thanks a lot!
joox