나는 웹 사이트에서 어떻게 고급 검색 기능을 만들 수 있는지 알아 내려고하고있다. 지금 사용하고있는 코드는 효율적이지 않고 매우 비싼 쿼리를 만듭니다.고급 검색 창 만들기
이내 검색 컨트롤러 : 당신은 텍스트 검색을 많이 할하려는 경우
public ActionResult Index(string q = null, string authors = null, string category = null, decimal rating = 0, string published = null, int completed = 0, int page = 0)
{
List<string> categories = new List<string>();
List<string> authorss = new List<string>();
DateTime DateBy = new DateTime();
DateTime.TryParse(published, out DateBy);
if(!string.IsNullOrEmpty(authors))
authorss = authors.Split(',').ToList();
if (!string.IsNullOrEmpty(category))
categories = category.Split(',').ToList();
IEnumerable<Comic> Comics = db.Comics.Where(i => i.Title.Contains(q)).Include(i => i.ComicRatings).Include(i => i.ComicAuthors).Include("ComicAuthors.User");
if(authorss.Count() >= 1)
{
Comics = Comics.Where(i => i.ComicAuthors.Where(j => authorss.Contains(j.User.UserName)).GroupBy(j => j.Comic_Id).Where(j => j.Count() >= authorss.Count()).Any());
}
if (categories.Count() >= 1)
{
Comics = Comics.Where(i => i.ComicCategories.Where(j => categories.Contains(j.Category.Name)).GroupBy(j => j.Comic_Id).Where(j => j.Count() >= categories.Count()).Any());
}
if (rating != 0)
{
Comics = Comics.Where(i => i.ComicRatings.Where(j => j.Rating >= rating).Any());
}
if (completed == 1)
{
Comics = Comics.Where(i => i.Completed == false);
}
else if (completed == 2)
{
Comics = Comics.Where(i => i.Completed == true);
}
if (!string.IsNullOrEmpty(published))
{
Comics = Comics.Where(i => i.DatePublished >= DateBy);
}
if(page <= (Comics.Count()/20))
page = 0;
Comics = Comics.Skip(page * 20).Take(20);
IEnumerable<LocalComicCategoriesModel> testing = helper.getCategories();
ViewSearchModel post = new ViewSearchModel
{
Comic = Comics.ToList(),
Categories = testing
};
return View(post);
}
나는이 대답을 반향 것입니다 ... 당신이 구축을 위해 노력하지 않더라도 " avanced 검색 ", 나는 Lucene을 사용합니다. –
Lucene을 Entity와 함께 사용하는 좋은 지침서는 어디 있습니까? –
Entity와 데이터베이스를 통합하는 방법을 모르겠습니다. –