Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
499 views
in Technique[技术] by (71.8m points)

design patterns - How to implement search features in ASP.NET MVC applications

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 stackoverflow). Some technologies that I have in mind are:

  • SQL Server full-text search
  • External search engine (like Search Server 2008)
  • Lucene.NET

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

Ideas?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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. 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.
  3. 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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...