/*Usage example: This function takes S. O. L. I. D. as input and returns SOLID. And similarly removes single quotes, hyphens and slashes from input*/
CREATE DEFINER=`root`@`localhost` FUNCTION `SanitiseNameForSearch`(Name nvarchar(100)) RETURNS varchar(100) CHARSET utf8
BEGIN
RETURN REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(Name, ' ', ''), '.', ''), '''', ''), '-', ''), '/', '');
END
Using this function here in a procedure, applied the function on search input and on column. Works fine, but definitely not scalable.
CREATE DEFINER=`root`@`localhost` PROCEDURE `Search`(SearchFilter nvarchar(20))
BEGIN
SET @SearchFilter = `SanitiseNameForSearch`(SearchFilter);
SELECT t.TermId, t.Name
FROM Terminology AS t
WHERE `SanitiseNameForSearch`(Name) Like @SearchFilter
ORDER BY length(Name) asc
LIMIT 5;
END;
Is it ideal to implement this functionality via function or add a separate column/table that holds the column values after the function is applied i.e. hold precalculated value of SanitiseNameForSearch(Name)
so that it can be indexed?