ASP.NET Search Box

1

I'm having trouble creating an item search box. I'm already a beginner.

I want the user to type a name in the search box to display the items that contain the name that the user entered or a part of it, for example: the user entered materials or mat should then appear:

  • file materials
  • automotive materials
  • etc ...

My biggest question is how to implement this using DDD. I saw this example , and I found it relatively simple, but I can not imagine a way to implement it. I saw that it implements PagedList.Mvc and found it simple, but how to leave decoupled (Using DDD)?

An example of what was implemented there

public ViewResult Index(string sortOrder, string currentFilter, string searchString, int? page)
{
   ViewBag.CurrentSort = sortOrder;
   ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
   ViewBag.DateSortParm = sortOrder == "Date" ? "date_desc" : "Date";

   if (searchString != null)
   {
      page = 1;
   }
   else
   {
      searchString = currentFilter;
   }

   ViewBag.CurrentFilter = searchString;

   var students = from s in db.Students
                  select s;
   if (!String.IsNullOrEmpty(searchString))
   {
      students = students.Where(s => s.LastName.Contains(searchString)
                             || s.FirstMidName.Contains(searchString));
   }
   switch (sortOrder)
   {
      case "name_desc":
         students = students.OrderByDescending(s => s.LastName);
         break;
      case "Date":
         students = students.OrderBy(s => s.EnrollmentDate);
         break;
      case "date_desc":
         students = students.OrderByDescending(s => s.EnrollmentDate);
         break;
      default:  // Name ascending 
         students = students.OrderBy(s => s.LastName);
         break;
   }

   int pageSize = 3;
   int pageNumber = (page ?? 1);
   return View(students.ToPagedList(pageNumber, pageSize));
}

In my understanding, there is another way to do this to leave it unbound.

    
asked by anonymous 24.05.2016 / 22:05

1 answer

0

There are two things to implement to achieve this kind of rich search experience.

  • Typeahead.js

    With this component you will be able to create this autocomplete or sugestions experience while searching your application.

  • Search Engine

    You can develop a backend to perform the searches, or use some service to do this in a more performative, relevant and scalable way. I highly recommend using Azure Search as a search platform. It is affordable and also very easy to implement. It not only has search service, but also has suggestions service to do exactly what you need.

  • On my blog I posted a course, free, with a Azure Search Overview . In it I explain all the main features of this Platform as a Service and how it consumes.

    There is also a source code for demonstrating how to use each feature. From how to load data to the service, to how to use the suggestion service with fuzzy searches - eg: you search for "floers" and it suggests "flowers".

        
    25.05.2016 / 09:34