Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
501 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 Answer

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...