开发者

Linq (or SQL): Get a search query and sort it order by best result [closed]

开发者 https://www.devze.com 2023-03-06 13:27 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_如何学Python Closed 11 years ago.

I want to create a search page for my website. The logic is the user enters some keywords and I should search those words then sort the result by best matches. i.e: The user enters: "MVC Microsoft WPF ASP.Net". I want to show those results which contain most matches, such as:

Best Matches:

Learning Microsoft ASP.Net MVC

How to host a WPF form in Microsoft ASP.Net

Partial matches:

Microsoft MVC

Microsoft WPF

Microsoft ASP.Net

ASP.Net MVC

Keyword Matches:

MVC

Microsoft

WPF

ASP.Net


Try out Lucene.NET, it sorts search results by relevance by default


Finally I found the actual solution.

That's "FullText Index".

A complete tutorial is here:

http://blog.sqlauthority.com/2008/09/05/sql-server-creating-full-text-catalog-and-index/


Depending on what / how you are searching, a simple solution is to build your website so it is fully indexed on Google and take advantage of Google Custom Search API.


Here's a basic strategy; it would require a stored proc:

  1. Split your keyword string on spaces, and pad with '%'s.
  2. For each search term, perform an insert-select to the same in-memory temp table. You'll get duplicate rows, one per record per "hit" on a search term.
  3. Select from this temp table each distinct result, with a count of the number of times that result appears in the temp table. This is your "relevance", by which you can sort.
0

精彩评论

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

关注公众号