public ActionResult Index() { if (MXFlagSettingHelper.Get <bool>("bUseElasticSearchEngine")) { ViewBag.IsUsingElasticSearch = true; } else { ViewBag.IsUsingElasticSearch = false; } //This is being used for checking if sample data is there. No need to do this in real scenarios. if (!_bookRepository.IsAnyBookFound) { ViewBag.ShowDummyButton = true; } return(View()); }
//just mapping to the same SearchDoc objects so that the same view could be reused. public IList <BookSearchDocument> Search(string term) { var results = new List <BookSearchDocument>(); if (MXFlagSettingHelper.Get <bool>("bUseElasticSearchEngine")) { results = _bookSearchRepository.Search <BookSearchDocument>(term, take: 30).ToList(); } else { IList <Book> books; if (term == string.Empty) { books = _productCatalogMongoRepository.GetMany <Book>(take: 20); } else { books = _productCatalogMongoRepository.GetManyByTextSearch <Book>(term, 20); } foreach (var book in books) { results.Add(new BookSearchDocument { Id = book.Id, Title = book.Name, Author = new MXSearchDenormalizedRefrence { DenormalizedId = book.Author.DenormalizedId, DenormalizedName = book.Author.DenormalizedName }, Category = new MXSearchDenormalizedRefrence { DenormalizedId = book.Category.DenormalizedId, DenormalizedName = book.Category.DenormalizedName }, AvaliableCopies = book.AvaliableCopies, }); } } return(results); }