Akos
Akos

Reputation: 2007

MySql select question

I have a search engine. I have to select some data from a table when a user types in the search keywords.

I want to find an alternative to 'LIKE':

SELECT id,text FROM example WHERE text LIKE '$search'

Because the text column has usually loads of words in it and the search term always contains a few words, I don't get accurate results. Is there any other way of doing this?

Upvotes: 2

Views: 86

Answers (4)

Cybercartel
Cybercartel

Reputation: 12592

Usually a search engine is using a tree data structure for fast lookups and some sort of a graph to weight the search result. Maybe you want to look into a trie data structure and space-filling-curve. The latter is useful if you want to compare 2 documents. For example if you sort and count all the words you can do a heat map.

Upvotes: 0

Nicholas Smith
Nicholas Smith

Reputation: 11754

You could take a look at the MySQL Fulltext mechanism, it provides natural language searches in a fairly easy to use way.

Upvotes: 0

Michael Berkowski
Michael Berkowski

Reputation: 270609

If your table is MyISAM, you can enable full text searching:

ALTER TABLE table ADD FULLTEXT idx_text (`text`);

Upvotes: 0

Maxim Krizhanovsky
Maxim Krizhanovsky

Reputation: 26699

It's called full-text indexing, but currently it's not supported in InnoDB, only in MyISAM. Alternative is to use third-party indexing, like Lucene, Solr (which provides web service access on top on Lucene), Sphinx...

Upvotes: 3

Related Questions