Click here to Skip to main content
15,905,558 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In semanctic database:
SQL
set @str='java and sql and unix devloper or php and fox devloper'

SELECT K.RANK, AddressLine1, City
FROM Person.Address AS A
  INNER JOIN
  CONTAINSTABLE(Person.Address, AddressLine1,@str) AS K
  ON A.AddressID = K.[KEY]


above code fetches the rank of complete string when string str is passed to function CONTAINSTABLE.
but I need it separates all the words and fetches the rank of all the words. Separator should be 'AND' or 'OR'.
Output should be in format of commseperated rank with every word like this

word             rank
java              23
sql               21
unix devloper     20
php               30
fox devloper      23


I want to get rank of every word. Please help me.
Posted
Updated 6-Jan-16 8:33am
v2
Comments
Maciej Los 6-Jan-16 15:42pm    
I don't believe it's possible.
PLease, see: Limit Search Results with RANK especially How Search Query Results Are Ranked section.

1 solution

I'm almost sure it's impossible to achieve by using CONTAINSTABLE statement. The only way to achieve that is to write custom function which will get comma-separated list of words and return the sum of occurrences of each word in one record.

I found this: c# - SQL Server best method to match word phrases and order relevence - Stack Overflow[^]. An author of most valuable answer (4 upvotes) shows a way how to get the number of occurrences of each word from sentence in a specific column of searched table.

This might be helpful too:
Quantifying Text differences in TSQL[^]
Pattern Matching: the Gestalt Approach | Dr Dobb's[^]
Limit Search Results with RANK[^] - How Search Query Results Are Ranked section.
 
Share this answer
 
Comments
payaljain123 8-Jan-16 9:04am    
Please give me another option this solution is not working properly
Maciej Los 8-Jan-16 9:59am    
What eaxctly does not work?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900