tags:

views:

31

answers:

2

how to do a mysql search for the following scenario?

search term example: great state

Mysql field,

  • row 1 contains: great, city
  • row 2 contains: awesome state
  • row 3 contains: great state, and city

So, on search, over the given term, it shud give me all the three rows above.

what I want to achieve is, mysql shud search for the words in my search term, and if any word is found in the field, show it....

the mysql fields may contain a comma between words or may not contain.....

Also, cannot use full text feature, cause that requires the table engine to be myisam, and i cannot have myisam engine because i need to use foreign key relations on my tables

+1  A: 

Try BOOLEAN FULL TEXT search http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html

Mchl
If I try to use full text feature, i need to change the table type to myisam, which i cannot do, because i have foreign key constraints on my tables,so, si there any other way out for this problem???
tecks
@tecks, a common pattern is to create a separate set of tables just for the purpose of searching using FULLTEXT. It's a sloppy workaround, but it does work.
Charles
You can also implment external FULL TEXT search engine like Sphinx or Lucene.
Mchl
A: 

Your schema is not set up for text searching (implying that you're not an expert in this) but you say you require "foreign key relations on my tables" - which is either a very naive or very sophisticated requirement. I would suggest you think about which applies.

the mysql fields may contain a comma between words or may not contain.....

You're certainly going to have to build some sort of front end where you can at least normalise the parameters, I would recommend using a text search optimized schema, e.g.

base_data
---------
some_primary_key
some_text
some_other_stuff
...

base_data_words
---------------
bd_pk references base_data.some_primary_key
word
index(word)

then split up the words contained in base_data.some_text into base_data_words.word then finding stuff is simple and efficient.

C.

symcbean
Iam naive in a way that, I thought there might be some easy or direct way of achieving this, but otherwise I believe I can think of some logical way to achieve this......but certainly, your answer is quiet sophisticated, so Iam going to try that way, thanks a lot....
tecks