I've reworked patch with your suggestion. In this version I found a little slowdown in comparison with previous version:
SELECT * FROM words WHERE levenshtein_less_equal(a, 'extensize', 2) <= 2;
48,069 ms => 57,875 ms
SELECT * FROM words2 WHERE levenshtein_less_equal(a, 'клубничный', 3) <= 2;
100,073 ms => 113,975 ms
select * from phrases where levenshtein_less_equal('kkkknucklehead courtliest sapphires be coniferous emolument antarctic Laocoon''s deadens unseemly', a, 10) <= 10;
22,876 ms => 24,721 ms
test=# select * from phrases2 where levenshtein_less_equal('таяй раскупорившийся передислоцируется юлианович праздничный лачужка присыхать опппливший ффехтовальный уууудобряющий', a, 10) <= 10;
55,405 ms => 57,760 ms
I think it is caused by multiplication operation for each bound movement. Probably, this slowdown is ignorable or there is some way to achieve the same performance.
----With best regards,Alexander Korotkov.