Wednesday 15 August 2012

c# - Need advice for building a search in an ASP.NET MVC application -


I've been googling, but there is no good info on creating a good search function in an asp.net mvc project.

Above my head, a search feature will look like this to find authors and books:

  char [] delimiterChars = {'', '', ' }; String [] searchers = searchbox. Split (limiter chairs); IQueryable & LT; SearchResult & gt; SR = _db.Books.Where (e => (e.Title.Contains (Search [0]) || e.uthor.names.Contains (SearchTerm [0])) & amp; amp; amp; amp; amp; Tight. (Search [1]) || e.uthor.name.Contains (Searchroom [1]) For the number of terms entered in the search box, for // & amp; Amp; & Amp; Amp; Repeat. Select (E = & gt; New Search Result {title = e.Title, type = "book", link = "book" "+ e.BookID});  

Question < / H3>
  1. Is there a better way to do this?
  2. If not, how can I dynamically create my SQL query as the form of many search terms Look for entry?
  3. Can I add search results to the SR variable from another search?

Other ideas

In the above search I I'm looking for results that match the author. Maybe I want to do a search to search for a match in the author table, and then those results will be returned from the first query to SR Add to variable results. I do not know that this is the most practical approach, but can it be done?

My first inclination would be to sell some things like Lucinate. Mr. Lack, you can do this:

  char [] delimiterChars = { '', ','}; String [] searchers = searchbox. Split (limiter chairs); Var temp = _db.Books.AsQueryable (); Foreach (string term in search) {temp = temp.Where (e => (e.Title.Contains (term)} e.uthor.Name.Contains (term)}} IQueryable & lt; SearchResult & gt; ; Select result = temp (E = & gt; New search result {title = e.Title, Type = "Book", Link = "Book /" + e.BookID});  

Note that Dynamically creates a query.


No comments:

Post a Comment