0

What should I use, to search for a keyword with mysql ?

I have a word and in the query I have

wordless
something word something
someword some
else
other
wordother
thingword

I want to output everything that has the word inside it, but the output to be like first outputed rows to be that rows with word as first letter on them, for example

wordless - will be the first because word are first characters of the word wordless and the wordother to be outputed to to the first outputed rows, then after them to output something word something and etc, every word that contains the name word, but again to output first that rows that have the word at the first characters.

EDIT:

SELECT *,MATCH(add_songName) AGAINST('d' IN BOOLEAN MODE) asscoreFROM songs WHERE MATCH(add_songName) AGAINST('d') ORDER BYscoreDESC , Here i'm searching for d but it gives me an error -

Can't find FULLTEXT index matching the column list   SELECT *,MATCH(add_songName) AGAINST('d' IN BOOLEAN MODE) as `score` FROM songs WHERE MATCH(add_songName) AGAINST('d') ORDER BY `score` DESC
gambozygame
  • 489
  • 2
  • 9
  • 14

1 Answers1

0

Try to use Levenshtein algorithm in MySQL.

Levenshtein matching is a metric for measuring the amount of difference between two sequence, here it is strings. By default MySQL does not have this function, but you can write and add one.

Please take a look at the code here and add that code as a system function in MySQL, please see the example below on how to get the similarity of two strings.

Please see: https://github.com/rakesh-sankar/Tools/blob/master/MySQL/Levenshtein.txt

Example:
SELECT column1, LEVENSHTEIN(column1, 'matchme') AS perfectmatch FROM sometable ORDER BY perfectmatch DESC

Rakesh Sankar
  • 9,337
  • 4
  • 41
  • 66