I have a table with two fields in an sql server database and my asp.net application calls a stored procedure with a '@SearchString' parameter and the stored procedure finds all records where the @Searchstring value is found in the concatenation of two fields in the table, call them 'Field1' and 'Field2'
So the logic looks like this(I have simplified the actual query):
CREATE PROCEDURE [dbo].[sp_FindMatches] @SearchString varchar(30)
AS
SELECT * FROM Table1 WHERE Field1+Field2 LIKE @SearchString
I would like to improve this rather basic matching algorithm so that it is not so restrictive in the records it matches. For example if the user enters "DOG HOUSE" as a parameter, the rather basic logic in the existing SP will return records where it finds the exact string. I would like for it to also return records just with "DOG" and "HOUSE" even if the strings aren't exactly next to each other.
Even better if there was a way to rank the records in terms of 'best match' it would be even better, i.e. if "DOG HOUSE" is found it is an exact match, if "DOG" and "HOUSE" are found, second best match, if "dog but not 'house' or 'house' but not 'dog' third best etc.
Is there a generic algorithm that does much of what I want?