开发者

how to search text in threads?

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

i am wondering what functi开发者_运维问答on 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?


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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜