2

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?

1
  • Have you considered FULLTEXT searches? I would give more information on them myself, but I'm not great at MySQL, really! A quick google will tell give you more information on them, though, if you are interested. Commented Aug 22, 2011 at 10:54

4 Answers 4

3

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...

Sign up to request clarification or add additional context in comments.

Comments

0

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

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

Comments

0

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.