Ok, so writing a function which will give a higher result on better
matches is maybe a good way to solve this.
Mymatch(match, against)
returnvalue:
The sum of
1, or every matching character in the right place,
0.4, for every charachter matching in the wrong place.
This function should ('almost') do that:
DROP FUNCTION IF EXISTS MyMatch;
delimiter //
CREATE FUNCTION MyMatch (v_match TEXT, v_against TEXT)
RETURNS real
BEGIN
DECLARE v_score REAL;
DECLARE v_index INT;
SET v_score = 0;
SET v_index = 1;
WHILE v_index <= LENGTH(v_against) DO
IF substr(v_match,v_index,1) = substr(v_against,v_index,1) THEN
SET v_score = v_score + 1.0;
ELSE
IF LOCATE(substr(v_match,v_index,1),
concat(substr(v_against,1,v_index-1),substr(v_against,v_index+1)))>0 THEN
SET v_score = v_score + 0.4;
END IF;
END IF;
SET v_index = v_index + 1;
END WHILE;
RETURN v_score;
END//
delimiter ;
SELECT Mymatch('door','poop'), 2, '';
SELECT Mymatch('poop','poop'), 4, '';
SELECT Mymatch('poop','poor'), 3, 'wrong result 3.4';
SELECT Mymatch('roop','poor'), 2.8, '';
SELECT Mymatch('rood','poor'), 2.4, '';