https://addons.heroku.com/#search列出了一些非常酷的搜索插件。我正在为我的 MVC 项目寻找类似的东西。我希望它是:
- 相当容易实施
- 准确(好结果)
- 很棒的 API
- 不需要全文搜索,只需按标题搜索(必须像 S/O 问题)
我也想知道我是否应该只使用 Google 搜索 API,因为它似乎非常准确。我很好奇 overflow.com 使用什么搜索系统堆栈?
谢谢
https://addons.heroku.com/#search列出了一些非常酷的搜索插件。我正在为我的 MVC 项目寻找类似的东西。我希望它是:
我也想知道我是否应该只使用 Google 搜索 API,因为它似乎非常准确。我很好奇 overflow.com 使用什么搜索系统堆栈?
谢谢
你要求一个 MVC 解决方案,我会给你一个。
实现接口 ISearchable
interface ISearchable{
SearchResult Search(string query);
}
实现类 SearchResult
public class SearchResult{
SearchResult(string title, string url, string description, int rank){
this.Title = title;
this.Url = url;
this.Description = description;
this.Rank = rank;
}
public string Title { get; set; }
public string Url { get; set; }
public string Description { get; set; }
public int Rank { get; set; }
}
让您的 ViewModel 实现 ISearchable 接口。
public class MyViewModel : ISearchable{
public List<Article> Articles { get; set; }
#region ISearchable
public SearchResult Search(string query){
string title = "";
string url = "";
string description = "";
int rank = 0;
// Custom logic to search for an article
...
return new SearchResult(title, url, description, rank);
}
#endregion
}
在 上注册ISearchable
ViewModel Application_Start
,例如在Unity
.
实施SearchController
并拥有行动查询。
public ActionResult Query(SearchQueryModel model){
model.Search();
return View(model);
}
在model.Search()
中,通过已注册的实现ISearchable
接口的 ViewModel 进行搜索,使用最适合您的任何搜索 API。或者不要使用 API。
现实情况是,任何搜索都会为您服务一时,但当它不再为您服务时,您可以切换而不会破坏您的实施。
我知道您要求“最佳 ASP.NET MVC 搜索解决方案”。我无法为您挑选任何特定的产品,因为我不知道您的解决方案的内部运作方式、您的预算等。
但严格从 ASP.NET MVC 的角度来看,可以插入到上述场景中的那个应该是一个不错的。如果它符合您的账单等...