Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How ranking sql result with many words?

Author  Topic 

bargan
Starting Member

4 Posts

Posted - 2015-04-14 : 22:45:08
[sql server rank result in multiple words in query
I using classic ASP

Field "searchFor" search in:

articleDescription
articleDescriptionSecundary
articleInternalCode
articleBarCode

CODE :
this code show results for Id order but i Need for more matches

<%
a=Split (Request("searchFor"))
for each x in a

strSQL = "SELECT * FROM article WHERE articleDescription COLLATE SQL_LATIN1_GENERAL_CP1_CI_AI LIKE '%" & x & "%' AND articleActive = 1 OR articleDescriptionSecundary COLLATE SQL_LATIN1_GENERAL_CP1_CI_AI LIKE '%" & x & "%' AND articleActive = 1 OR articleInternalCode LIKE '%" & x & "%' AND articleActive = 1 OR articleBarCode LIKE '%" & x & "%' AND articleActive = 1 "
Set rs = Server.CreateObject("ADODB.recordset")
next
%>


I want that the result appears ranked when the client put three words in the search form EXAMPLE "white desk chair" first Result Containing the three words after two and after the one word

white desk chair (3 matches)
red desk chair (2 matches)
black desk (1 match)

thanks

djj55
Constraint Violating Yak Guru

352 Posts

Posted - 2015-04-20 : 14:33:45
I think you need to add parenthesis. This is what SQL server is expecting
SELECT * 
FROM article
WHERE (articleDescription LIKE '%value%' AND articleActive = 1)
OR (articleDescriptionSecundary '%value%' AND articleActive = 1)
OR (articleInternalCode LIKE '%value%' AND articleActive = 1)
OR (articleBarCode LIKE '%value%' AND articleActive = 1)


As to the count, I believe a CASE statement might help.

djj
Go to Top of Page
   

- Advertisement -