Jump to content

Recommended Posts

Hello. I have a table which is called [info], I store my members information there. Inside this table, there is a row called [interests] which contains all the members’ interests.

 

I am creating a search tool & I wish MySQL to match as many keywords as possible.

 

So if the user searches for: LOVE TO GO OUT AND HAVE COFFEE mySQL will display the member who has as many keywords of this search term as possible

 

These quires search for exact terms only…

 

$q = "SELECT * FROM info WHERE  interests LIKE '%{$search_term}%' ORDER BY RAND() ";

$q = "SELECT * FROM info WHERE  interests  =  ‘$search_term' ORDER BY RAND() ";

 

 

I need a MySQL query which will match as many keywords as possible and order the results according to most matching. Is this possible? Or is it a complicated story? Help please.

 

Link to comment
https://forums.phpfreaks.com/topic/262505-mysql-search/
Share on other sites

That could get pretty complicated.

 

I suppose if you exploded the search terms into each keyword, and also query each user, then have them all in an array and display the highest number of results first......it's possible.

But that would be pretty intensive usage to do that for all your users.

 

I would suggest looking into mysql fulltext search in boolean mode, and read about the minimum word length, creating indexes

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

 

The following query will display a result if it contains at least one or more of the keywords in the search term.

 

$q = "SELECT * FROM info WHERE MATCH (interests) AGAINST ('$search_term' IN BOOLEAN MODE) ORDER BY RAND() ";

Link to comment
https://forums.phpfreaks.com/topic/262505-mysql-search/#findComment-1345330
Share on other sites

Full text has stop words (words that are ignored in a fulltext search), and if you are using shared hosting, you probably cannot change them.

 

in your example the only words that would have been matched are "Love" and "Coffee"

 

http://dev.mysql.com/doc/refman/5.1/en/fulltext-stopwords.html

Link to comment
https://forums.phpfreaks.com/topic/262505-mysql-search/#findComment-1345387
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.