public SearchResult PerformSearch(SearchFilter filter) { using (var service = new SearchService("site")) { var site = CmsService.Instance.SitePath.Split('/').Last(); var query = new QueryList(); query.SubQueries.Add(new TermQuery("site", site)); if (!string.IsNullOrEmpty(filter.TemplateName)) query.SubQueries.Add(new TermQuery("template", filter.TemplateName)); if (!string.IsNullOrEmpty(filter.Query)) { foreach (var term in filter.Query.ToLower().Split(' ')) query.SubQueries.Add(new WildCardQuery("text", term)); } if (filter.From.HasValue || filter.To.HasValue) query.SubQueries.Add(new DateRangeQuery("date", filter.From, filter.To)); if (filter.CategorizationIds != null && filter.CategorizationIds.Any()) { if (filter.CategorizationIds.Length == 1) query.SubQueries.Add(new WildCardQuery("categorizations", filter.CategorizationIds[0].ToString())); else { var categorizationFolder = CategorizationFolder.Get(); var types = categorizationFolder.GetTypes(filter.CategorizationIds); var typeQueries = new List<Query>(); foreach (var typeIds in types.Select(type => filter.CategorizationIds.Where(type.HasItem).ToArray())) { if (typeIds.Length == 1) typeQueries.Add(new WildCardQuery("categorizations", typeIds[0].ToString())); else typeQueries.Add(BooleanQuery.Or(typeIds.Select(id => new WildCardQuery("categorizations", id.ToString())).ToArray())); } query.SubQueries.Add(BooleanQuery.And(typeQueries.ToArray())); } } return service.Search(query, 0, int.MaxValue); } }
public SearchResult PerformSearch(SearchFilter filter) { using (var service = new SearchService("site")) { var query = new QueryList(); if (!string.IsNullOrEmpty(filter.TemplateName)) query.SubQueries.Add(new TermQuery("template", filter.TemplateName)); if (!string.IsNullOrEmpty(filter.Query)) { foreach (var term in filter.Query.ToLower().Split(' ')) query.SubQueries.Add(new WildCardQuery("text", term)); } if (filter.From.HasValue || filter.To.HasValue) query.SubQueries.Add(new DateRangeQuery("date", filter.From, filter.To)); if (filter.SubjectIds != null && filter.SubjectIds.Any()) { if (filter.SubjectIds.Length == 1) query.SubQueries.Add(new WildCardQuery("subjects", filter.SubjectIds[0].ToString())); else query.SubQueries.Add(BooleanQuery.Or(filter.SubjectIds.Select(id => new WildCardQuery("subjects", id.ToString())).ToArray())); } return service.Search(query, 0, int.MaxValue); } }