コード例 #1
0
 protected override void RenderPart(LinqIt.Utils.Web.HtmlWriter writer)
 {
     using (var service = new SearchService("site"))
     {
         var q = BooleanQuery.Or(Request.QueryString["query"].ToLower().Split(' ').Where(s => !string.IsNullOrEmpty(s)).Select(s => new WildCardQuery("text", "*" + s + "*")).ToArray());
         var result = service.Search(q, 0, int.MaxValue);
         foreach (var record in result.Records)
         {
             writer.RenderBeginTag(HtmlTextWriterTag.Div, "search-result");
             writer.RenderBeginTag(HtmlTextWriterTag.H3);
             writer.RenderLinkTag(record.GetString("url"), record.GetString("title"));
             writer.RenderEndTag();
             writer.RenderFullTag(HtmlTextWriterTag.Div, record.GetString("text"));
             writer.RenderEndTag();
         }
     }
 }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
ファイル: DataService.cs プロジェクト: Psolow/Umbraco-Public
        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);
            }
        }