MySQL Fulltext Boolean Mode search returns too many results

I'm having an issue with my fulltext search query and I've pretty much gone through all the forums and threads I could find but I'm still having this issue.

I am using the MySQL Fulltext Boolean Mode search to return matching rows based on two columns (artist name and track title). The user can enter any phrase they wish into the search bar, and the results are supposed to be only rows that contain ALL parts of the search query in EITHER of the columns.

This is the query I have so far, and it works with most queries but for some it return results too loosely and I'm not sure why.

SELECT * FROM tracks WHERE MATCH(artist, title) AGAINST('+paul +van +dyk ' IN BOOLEAN MODE)

This query however, returns rows containing Paul, without the 'Van' or 'Dyk'. Again, I want the query to return only rows that contain ALL of the keywords in EITHER the Artist or Track Name column.

Thanks in advance


To enhance sorting of the results in boolean mode you can use the following:

SELECT column_names, MATCH (text) AGAINST ('word1 word2 word3')
AS col1 FROM table1
WHERE MATCH (text) AGAINST ('+word1 +word2 +word3' in boolean mode) 
order by col1 desc;

Using the first MATCH() we get the score in non-boolean search mode (more distinctive) . The second MATCH() ensures we really get back only the results we want (with all 3 words) .

So your query will become:

SELECT *, MATCH (artist, title) AGAINST ('paul van dyk')
    AS score FROM tracks
    WHERE MATCH (artist, title) 
    AGAINST ('+paul +van +dyk' in boolean mode) 
    order by score desc;

Hopefully; you will get better results now.

If it works or do not work; please let me know.


Piggybacking off of @Avidan's answer. These are the operations that can be performed on full-text searches to help create the query you desire.

The following examples demonstrate some search strings that use boolean full-text operators:

'apple banana'

Find rows that contain at least one of the two words.

'+apple +juice'

Find rows that contain both words.

'+apple macintosh'

Find rows that contain the word “apple”, but rank rows higher if they also contain “macintosh”.

'+apple -macintosh'

Find rows that contain the word “apple” but not “macintosh”.

'+apple ~macintosh'

Find rows that contain the word “apple”, but if the row also contains the word “macintosh”, rate it lower than if row does not. This is “softer” than a search for '+apple -macintosh', for which the presence of “macintosh” causes the row not to be returned at all.

'+apple +(>turnover

Find rows that contain the words “apple” and “turnover”, or “apple” and “strudel” (in any order), but rank “apple turnover” higher than “apple strudel”.

'apple*'

Find rows that contain words such as “apple”, “apples”, “applesauce”, or “applet”.

'"some words"'

Docs: https://dev.mysql.com/doc/refman/5.5/en/fulltext-boolean.html

链接地址: http://www.djcxy.com/p/75294.html

上一篇: 排序布尔全文搜索在MySQL中的相关性,解释?

下一篇: MySQL Fulltext布尔模式搜索返回太多结果