public async Task <IActionResult> Search(string query, string myOnly) { if (query?.Length > MaxQueryLength) { return(BadRequest("Query is too long")); } var user = await FindUserAsync(User?.Identity?.Name); var to = DateTime.UtcNow; var from = to.AddMinutes(-LastMinutesToSearch); var gen = Request.Cookies[IndexGenerationCookieName].TryParseOrDefault(); return(Ok(LuceneIndex.Search(query, user, myOnly == "on", from, to, 1000, gen))); }
public virtual async Task <ActionResult> AutoCompleteSearch(string term) { if (string.IsNullOrWhiteSpace(term)) { return(Content(string.Empty)); } var categories = await _categoryService.SearchCategory(term, 5); var items = LuceneIndex.Search(term, "Title", "Description").Take(10).ToList(); var luceneList = items.Where(x => x.Category == "کالاها").Select(item => new AutoCompleteSearchViewModel { Label = item.Title, Url = Url.Action(MVC.Product.Home.ActionNames.Index, MVC.Product.Home.Name, new { area = MVC.Product.Name, id = item.ProductId, slugUrl = item.SlugUrl }), Category = item.Category, Image = item.Image, }).ToList(); luceneList.AddRange(items.Where(x => x.Category != "کالاها").Select(item => new AutoCompleteSearchViewModel { Label = item.Title, Url = Url.Action(MVC.Post.Home.ActionNames.Index, MVC.Post.Home.Name, new { area = MVC.Post.Name, id = item.PostId, slugUrl = item.SlugUrl }), Category = item.Category, Image = item.Image })); var data = categories.Select(x => new AutoCompleteSearchViewModel { Label = x.Name, Url = $"{Url.Action(MVC.Product.SearchProduct.ActionNames.Index, MVC.Product.SearchProduct.Name, new { area = MVC.Product.Name })}#/page/{x.Id}", Category = "گروهها" }).Concat(luceneList); return(Json(data, JsonRequestBehavior.AllowGet)); }