In reply to: Damian Paluch
Daniel,
you're right, in case you presented it works properly, but I need check if every single word of "Description" value can be matched on any 'Keyword'.
Following your example, I want to make the business rule, which return a correct product, when my input is for example "line lorem ipsum" (same as in your screenshot "line").
Hi Damian,
I'm sorry, I really did not understand your request correctly and I have to admit I still aren't sure whether I understood your use case correctly this time.
If the users enters 5 words you want to return any product which matches at least one word?
If this is the case you could this approach below to initialize an item list. For me this makes no sense. If I want a black bike, I would want only these products where I have a match for each word. Than again, if the user would really write a sentence, We won't get any match as there will be words, which are not a tag. So we would need to work around this and test the tags of each products against the string which. This could return any number of products with a varying number of "tag" matches.
While a description field could be easier, I would opt to store the tags in a separate dictionary and use a multi choice field for the order as well as the products. In this case you won't need to handle any spelling errors or such things. In case the users need to add freely tags, you could also use this approach. This would allow the user to stay on the form. Although I have to admit, that the new dictionary entry probably cant be added automatically with the current options. It would probably replace all existing entries.
https://daniels-notes.de/posts/2022/modal-dialog#adding-a-new-entry-to-a-dictionary
Best regards,
Daniel
declare @description varchar(max) = 'I need a, black bike with white. elements'
DECLARE @Products TABLE (ProdID INT,ProductName VARCHAR(20),Tags varchar(1000))
insert into @Products (ProdID,ProductName,Tags)
values
(1,'Child bike 12"', 'bike, black, small'), (2,'Child bike 24"', 'bike, black, small,boy'),
(3,'Hemlet boy"', 'boy, white, helm, security'), (4,'Cards"', 'game, white'),
(5,'Cards"', 'game, purple'), (6,'Cards"', 'xyz')
select *
from @Products join
dbo.SplitToTable(
Replace(
-- removing any non word characters
Replace(Replace(@description,',',''),'.','')
-- split to table seems to have a problem when using ' ' as a delimiter -> replace ' ', by ','
,' ',',')
-- split by ,'
,',')
as wordTokens
-- SplitTotable returns a column named item
on Tags like '%'+item+'%'
select distinct ProdID, ProductName, Tags
from @Products join
dbo.SplitToTable(Replace(Replace(Replace(@description,',',''),'.',''),' ',','),',') as wordTokens
on Tags like '%'+item+'%'