最佳ASP.NET MVC搜索解决方案

时间:2013-01-11 02:34:01

标签: c# asp.net asp.net-mvc search

https://addons.heroku.com/#search列出了一些非常酷的搜索插件。我正在为我的MVC项目寻找类似的东西。我希望它是:

  1. 相当容易实施
  2. 准确(好的结果)
  3. 很棒的API
  4. 不需要按标题搜索全文搜索(必须像S / O问题)
  5. 我也想知道我是否应该使用Google搜索API,因为它似乎非常准确。我很好奇什么搜索系统堆栈overflow.com使用?

    由于

1 个答案:

答案 0 :(得分:2)

你要求一个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上注册Application_Start ViewModel,例如Unity

实施SearchController并进行操作查询。

public ActionResult Query(SearchQueryModel model){
   model.Search();
   return View(model);
}

model.Search()中,搜索已实施ISearchable界面的已注册ViewModel,使用最适合您的最佳搜索API。或者不要使用API​​。

现实情况是,任何搜索都会为您提供服务,但是当它不再为您服务时,您可以在不中断实施的情况下进行切换。

我知道您要求“最佳ASP.NET MVC搜索解决方案”。我不能为您挑选任何特定产品,因为我不知道您的解决方案的内部运作,您的预算等。

但严格来说,从ASP.NET MVC的角度来看,可以插入上述场景的应该是一个好的。如果它符合您的账单等...

相关问题