views:

32

answers:

2

i am coding my first forum and wants to have a search field.

i am wondering what function i should use to search for specific threads in database.

should i use

WHERE title LIKE '%keyword%' OR body LIKE '%keyword%'

is that the common search algorithm for thread contents?

+2  A: 

With multiple fields to be searched that is pretty standard.

You might want to have a look at

Full-Text Search Functions

and

Using MySQL Full-text Searching

astander
it said that full-text-search only works for myisam tables. ive got them in innodb...some comments on that?
weng
thx for the latter article...i have just read the beginning but it seems to be very helpful
weng
+1  A: 

is that the common search algorithm for thread contents?

There is no such.
You should choose the one you need and the one that fits best in your requirements.

But some considerations for you are:

  • Search on both Title and Body (easier to find but will be slooow with many threads).
  • If the body can contan formatted text (maybe HTML) it will also be included in search.
  • Using SQL Like is the first step for SQL Injection. Carefully escape all the input.
  • Search using LIKE is very sloooow operations in all SQL Databases. You user better use Full-text search or index the data using a 4rd tool.
Dmytrii Nagirniak