简体   繁体   中英

Why do these 2 MySQL queries return different results

I'm running a MySQL query to search a DB of jobs. I'm using MATCH and AGAINST to be able to order results be relevance. I'm confused however as to why these 2 queries return different results:

SELECT SQL_CALC_FOUND_ROWS *, MATCH (`title`) 
            AGAINST ("assistant") 
            AS Relevance 
            FROM jobs2 
            WHERE MATCH (`title`) 
            AGAINST ("assistant") AND date  >= CURDATE() - INTERVAL 28 DAY GROUP BY jobref ORDER BY Relevance DESC LIMIT 0,50

which as I understand will default to natural language mode, but returns 0 results, whereas:

SELECT SQL_CALC_FOUND_ROWS *, MATCH (`title`) 
            AGAINST ("assistant" IN BOOLEAN MODE) 
            AS Relevance 
            FROM jobs2 
            WHERE MATCH (`title`) 
            AGAINST ("assistant" IN BOOLEAN MODE) AND date  >= CURDATE() - INTERVAL 28 DAY GROUP BY jobref ORDER BY Relevance DESC LIMIT 0,50

returns 4 results as expected, but the relevance is always 1, so ordering by relevance isn't actually possible?

my DB has these jobs for testing:

|date               |title                                                          |jobref|

|2016-04-08 07:21:19|Assistant Management Accountant                                |12345 |
|2016-04-08 07:21:19|Assistant Accountant                                           |12346 |
|2016-04-08 07:19:15|Assistant Finance Manager                                      |12347 |
|2016-04-08 07:20:38|Accounts Assistant / Purchase Ledger Clerk / Accounts Payable  |12348 |

Basically, why is natural language mode returning 0 results?

From the MySQL documentation for natural language search:

In addition, words that are present in 50% or more of the rows are considered common and do not match.

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

It looks like your sample data exceeds that 50% match rate.

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