Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using Full-Text feature of SQL server 2008 R2 to find data based upon keyword entered by user. I would like to have most relevant data to be returned at the TOP of SEARCH RESULT.

For Example: I have three data row in search table in below order

Row 1: Computer
Row 2: Class
Row 3: Computer Class

Whenever User perform a search for keyword "Computer Class", I would like data to be returned in below order

Result 1: Computer Class
Result 2: Computer
Result 3: Class

But I get data in below order with my current query

Result 1: Computer
Result 2: Class
Result 3: Computer Class

I am using below query

SQL
Select * from Search_Table WHERE FREETEXT(Subjects_Column,'"COMPUTER CLASS"')


How would I get the expected result?
Posted

1 solution

Don't use SELECT * then.

From the example you give, your query should be :

SQL
SELECT [Computer Class], [Computer], [Class] FROM [Search_Table] WHERE ...


It also means than you have to construct your query from the search text.

Note : SELECT * is, in general, a bad practice.
 
Share this answer
 
Comments
sam7one 28-Aug-13 13:05pm    
[Computer Class], [Computer], [Class] are data values contained in column "Subjects", they are not actual columns.

You misunderstood the question or I was not able to explain it properly. Its not about Select clause, its about where clause using Fulltext search option and finding data with relevance. my search query would be

Select Subjects(column) from Search(table) WHERE FREETEXT(Subjects(Column),'"COMPUTER CLASS"')

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