开发者

How to filter records by words in SQL server?

开发者 https://www.devze.com 2023-03-27 20:40 出处:网络
How to get results from SQL table. In my application I used fulltext search. I want to get: for example If user enter word like \"Great Events\". Then result should be comes as below sequence.

How to get results from SQL table.

In my application I used fulltext search.

I want to get:

for example If user enter word like "Great Events". Then result should be comes as below sequence.

  1. first result related to whole word "Great Events" and then
  2. "Great" related result then
  3. "Events" related result.

The first results should be all updates with the entire search term "Great Events".

Only after you show these results, then display updates with term "Great Events", "Greater Events" etc.

Basically words that contain the terms "Great Events".

Then show results from updates that have both words "Great" and "Events", and its variations.

Finally, show results from updates that have one of the two words...

My table likes: Columns

UserUpdates


UpdateID - int

UserID - int

MsgText - nvarchar(500) 开发者_StackOverflow中文版

CreatedOn - datetime

How to do using SQL script.. ?


You could create a fulltext catalog and add a fulltext index on your table to solve this.

Do do this , you might create a simple parser in c# to take the search terms and create a search keyword; turning the search for "great events" to something like :

'"great events" OR (Great AND Events)'

You can than create a query like this, based on that search keyword:

SELECT * FROM CONTAINSTABLE ([YourFullTextIndexTable], *, '"great events" OR (Great AND Events)' , 2057,0) ORDER BY RANK DESC

The above is for british english (2057) and the default stoplist (0).

This would return records with "Great Events" as a phrase first followed by records with Great and Events in there somewhere.

0

精彩评论

暂无评论...
验证码 换一张
取 消