I'm working on a "nice search" for my users.
I'm looking for a way to search some items using the terms and scoring the search on the same SQL-Server query.
I've got some references googling it.
One of the best that I've found was: http://techforpassion.blogspot.com.br/2013/03/how-to-split-comma-separated-string-and.html
And I've copied part of this, using my data, as follows:
DECLARE @valueList varchar(255)
DECLARE @pos INT
DECLARE @len INT
DECLARE @value varchar(100)
SET @valueList = 'how,does,it,works'
SET @pos = 0
SET @len = 0
WHILE CHARINDEX(',', @valueList, @pos + 1) > 0
BEGIN
SET @len = CHARINDEX(',', @valueList, @pos+1) - @pos
SET @value = SUBSTRING(@valueList, @pos, @len)
SELECT
@value AS TERMO
,IFAQ.nome AS NOME
,IFAQ.faqid AS ID
FROM
itemsfaq AS IFAQ
WHERE
IFAQ.nome LIKE '%' + @value + '%'
SET @pos = CHARINDEX(',', @valueList, @pos+@len) +1
END
I get the result which is fine, but I don't know how to merge all the data tables in a single table, resulting the score of the item within the name and what else is needed.
The idea was:
- Get the terms from the searchbar
- Split it
- Loop through the words
- Know what items are displayed in this word, it gets one point
- At the end, a table showing the items searched, ordered by the score.
The score is a way to show the user the relevance of the item in the actual search.
---- EDIT
As follows, the image with the actual result
The expected: All the tables merged, with the score sum. Like:
como, Como funciona o FAQ ; 00000-00000-00000-000; 2;