简体   繁体   中英

How to (quickly) search through a long text field for a certain string (field is up to 500 chars long)

I have a field, called 'message' and it can hold a string of up to 500 characters in length. It's basically for an in-site inbox system.

A user has a capacity of 250 messages in their inbox.

If a user wanted to search their inbox for messages with the string 'men fashion', I would want the MySQL query to limit the query down to the 250 messages associated to that user before even searching through the 'message' field.

I would want the query to also determine and return the query results in order of how well the search string matches the content of the message. So a message that had 'men's fashion' appear thrice would appear on top; one that had 'fashion' would appear next and one that had 'men' would appear at the bottom.

How do you:

  1. Make sure it doesn't drain the server
  2. Do the whole sort by how well the messages match the search string thing?

You could take a look at MySql Full Text Search function. It could return search results by relevancy.

http://dev.mysql.com/doc/refman/5.6/en/fulltext-search.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM