Relevance method for sorting MYSQL full-text search results
P粉938936304
P粉938936304 2023-08-24 12:03:52
0
2
547
<p>I am relatively new to MYSQL and have a problem that has been bothering me for a while. I've tried searching for answers in various places, but haven't found an acceptable solution yet. </p> <p>This is the query I currently run to find the best match for a given search term: </p> <pre class="brush:php;toolbar:false;">$query="SELECT * from `vocabulary` WHERE translation = 'word' OR translation LIKE '%word%'";</pre> <p>The results it returns are comprehensive, including all relevant rows. However, they are not sorted in any particular order and I would like when printing the results in PHP to show the exact matches first. Like this: </p> <hr /> <p>1 | word <-exact match</p><p> 2 | crossword <-alphabetical partial match /</p><p> 3 | words</p><p> 4 | wordsmith</p> <hr /> <p>Thank you very much for your help in advance. </p> <p>-macspacejunkie</p>
P粉938936304
P粉938936304

reply all(2)
P粉090087228

LIKE is not Full text search. In full-text search, MATCH(...) AGAINST(...) returns a match score that approximates relevance.

P粉039633152
SELECT * from vocabulary 
WHERE translation like 'word'  
union all
SELECT * from vocabulary 
WHERE translation LIKE '%word%' and translation not like 'word'

Exact matches will be listed first

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template