如何在ASP.NET MVC应用程序中实现搜索功能

时间:2022-04-27 01:38:18

I can imagine many ways of implemeting search features in an ASP.NET MVC application but since I can't find much documentation I was wondering if you have any common pattern, technology or common approach to implement search features in a ASP.NET MVC application (similar to *). Some technologies that I have in mind are:

我可以想象在ASP.NET MVC应用程序中实现搜索功能的许多方法,但由于我找不到太多文档,我想知道你是否有任何常见的模式,技术或通用方法来实现ASP.NET MVC应用程序中的搜索功能(类似于*)。我想到的一些技术是:

  • SQL Server full-text search
  • SQL Server全文搜索
  • External search engine (like Search Server 2008)
  • 外部搜索引擎(如Search Server 2008)
  • Lucene.NET
  • Lucene.NET

...but what is the best approach to integrate them with ASP.NET MVC?

...但是将它们与ASP.NET MVC集成的最佳方法是什么?

Ideas?

想法?

2 个解决方案

#1


5  

It's not entirely clear what you are specifically asking, but, in general:

目前还不完全清楚你具体要求的是什么,但总的来说:

  1. Write a view helper or partial view which returns a search form. Call that within your other pages wherever you need to display a search box. Make the form action GET, not POST.
  2. 编写一个返回搜索表单的视图助手或部分视图。在您需要显示搜索框的任何地方的其他页面中调用它。使表单操作GET,而不是POST。
  3. For a site search, you'll probably want to have a search controller. For searching within one particular type of data, you can add an action to an existing controller or an argument to an existing action. For the most part, the only thing that we have to add is an argument to the general-purpose "List" action for a specific datatype. The search form calls "List" and sets an argument with the search query string.
  4. 对于网站搜索,您可能希望拥有一个搜索控制器。要在一种特定类型的数据中进行搜索,您可以向现有控制器添加操作或向现有操作添加参数。在大多数情况下,我们必须添加的唯一内容是针对特定数据类型的通用“List”操作的参数。搜索表单调用“List”并使用搜索查询字符串设置参数。
  5. The actual searching is done within your Repository. That's the only part of the application which knows about things like SQL Server or Lucene. For trivial cases a controller could append a .Where to an IQueryable<T> returned by a Repository.
  6. 实际搜索在您的存储库中完成。这是应用程序中唯一知道SQL Server或Lucene等内容的部分。对于普通情况,控制器可以将一个。附加到存储库返回的IQueryable

#2


2  

I believe in one of his blog posts Jeff Atwood talks about how he used sitemaps in order to let google handle most of the searching capabilities on stack overflow. Why write your own searching algorithms when people are likely just going to use google anyway?

我相信他的一篇博客文章Jeff Atwood谈到他如何使用站点地图来让google处理堆栈溢出时的大部分搜索功能。当人们可能只是想使用谷歌时,为什么要编写自己的搜索算法呢?

#1


5  

It's not entirely clear what you are specifically asking, but, in general:

目前还不完全清楚你具体要求的是什么,但总的来说:

  1. Write a view helper or partial view which returns a search form. Call that within your other pages wherever you need to display a search box. Make the form action GET, not POST.
  2. 编写一个返回搜索表单的视图助手或部分视图。在您需要显示搜索框的任何地方的其他页面中调用它。使表单操作GET,而不是POST。
  3. For a site search, you'll probably want to have a search controller. For searching within one particular type of data, you can add an action to an existing controller or an argument to an existing action. For the most part, the only thing that we have to add is an argument to the general-purpose "List" action for a specific datatype. The search form calls "List" and sets an argument with the search query string.
  4. 对于网站搜索,您可能希望拥有一个搜索控制器。要在一种特定类型的数据中进行搜索,您可以向现有控制器添加操作或向现有操作添加参数。在大多数情况下,我们必须添加的唯一内容是针对特定数据类型的通用“List”操作的参数。搜索表单调用“List”并使用搜索查询字符串设置参数。
  5. The actual searching is done within your Repository. That's the only part of the application which knows about things like SQL Server or Lucene. For trivial cases a controller could append a .Where to an IQueryable<T> returned by a Repository.
  6. 实际搜索在您的存储库中完成。这是应用程序中唯一知道SQL Server或Lucene等内容的部分。对于普通情况,控制器可以将一个。附加到存储库返回的IQueryable

#2


2  

I believe in one of his blog posts Jeff Atwood talks about how he used sitemaps in order to let google handle most of the searching capabilities on stack overflow. Why write your own searching algorithms when people are likely just going to use google anyway?

我相信他的一篇博客文章Jeff Atwood谈到他如何使用站点地图来让google处理堆栈溢出时的大部分搜索功能。当人们可能只是想使用谷歌时,为什么要编写自己的搜索算法呢?