Пример #1
0
        public ViewResult Index(FindPage currentPage, string q)
        {
            var model = new FindSearchContentModel(currentPage)
            {
                PublicProxyPath = _findUIConfiguration.AbsolutePublicProxyPath()
            };

            if (!string.IsNullOrWhiteSpace(model.Query))
            {
                var query =
                    _searchClient.UnifiedSearchFor(model.Query, _searchClient.Settings.Languages.GetSupportedLanguage(ContentLanguage.PreferredCulture) ??
                                                   Language.None)
                    .UsingSynonyms()
                    //Include a facet whose value we can use to show the total number of hits
                    //regardless of section. The filter here is irrelevant but should match *everything*.
                    .TermsFacetFor(x => x.SearchSection)
                    .FilterFacet("AllSections", x => x.SearchSection.Exists())
                    //Fetch the specific paging page.
                    .Skip((model.PagingPage - 1) * model.CurrentPage.PageSize)
                    .Take(model.CurrentPage.PageSize)
                    //Range facet for date
                    //.RangeFacetFor(x => x.SearchUpdateDate, model.PublishedDateRange.ToArray())
                    //Allow editors (from the Find/Optimizations view) to push specific hits to the top
                    //for certain search phrases.
                    .ApplyBestBets();

                // obey DNT
                var doNotTrackHeader = System.Web.HttpContext.Current.Request.Headers.Get("DNT");
                // Should Not track when value equals 1
                if (doNotTrackHeader == null || doNotTrackHeader.Equals("0"))
                {
                    query = query.Track();
                }

                //If a section filter exists (in the query string) we apply
                //a filter to only show hits from a given section.
                if (!string.IsNullOrWhiteSpace(model.SectionFilter))
                {
                    query = query.FilterHits(x => x.SearchSection.Match(model.SectionFilter));
                }

                //We can (optionally) supply a hit specification as argument to the GetResult
                //method to control what each hit should contain. Here we create a
                //hit specification based on values entered by an editor on the search page.
                var hitSpec = new HitSpecification
                {
                    HighlightTitle   = model.CurrentPage.HighlightTitles,
                    HighlightExcerpt = model.CurrentPage.HighlightExcerpts
                };

                //Execute the query and populate the Result property which the markup (aspx)
                //will render.
                model.Hits = query.GetResult(hitSpec);
            }

            return(View(model));
        }
        public ViewResult Index(FindSearchPage currentPage, string q, string selectedAnalyzer)
        {
            var model = new FindSearchContentModel(currentPage)
            {
                PublicProxyPath = findUIConfiguration.AbsolutePublicProxyPath()
            };

            var parameters = Request.Url != null ? Request.Url.Query : string.Empty;

            model.OtherLanguageUrl = model.OtherLanguageUrl + parameters;

            //detect if serviceUrl and/or defaultIndex is configured.
            model.IsConfigured = SearchIndexIsConfigured(EPiServer.Find.Configuration.GetConfiguration());

            if (model.IsConfigured && !string.IsNullOrWhiteSpace(model.Query))
            {
                var query = BuildQuery(model, selectedAnalyzer);

                //Create a hit specification to determine display based on values entered by an editor on the search page.
                var hitSpec = new HitSpecification
                {
                    HighlightTitle   = model.CurrentPage.HighlightTitles,
                    HighlightExcerpt = model.CurrentPage.HighlightExcerpts,
                    // When HighlightExcerpt = true then minimum of ExcerptLength = 36
                    ExcerptLength = model.CurrentPage.HighlightExcerpts && model.ExcerptLength < 36 ? 36 : model.ExcerptLength
                };

                try
                {
                    model.Hits = query.GetResult(hitSpec);
                }
                catch (WebException wex)
                {
                    model.IsConfigured = wex.Status != WebExceptionStatus.NameResolutionFailure;
                }
            }

            model.Analyzers = CreateAnalyzers(selectedAnalyzer);

            RequireClientResources();

            return(View(model));
        }
Пример #3
0
        public ViewResult Index(FindSearchPage currentPage, string q)
        {
            var model = new FindSearchContentModel(currentPage)
            {
                PublicProxyPath = findUIConfiguration.AbsolutePublicProxyPath()
            };

            //detect if serviceUrl and/or defaultIndex is configured.

            var findConfiguration = EPiServer.Find.Configuration.GetConfiguration();

            model.IsConfigured = !findConfiguration.ServiceUrl.IsNullOrEmpty() &&
                                 !findConfiguration.DefaultIndex.IsNullOrEmpty();

            if (model.IsConfigured && !string.IsNullOrWhiteSpace(model.Query))
            {
                var query = BuildQuery(model);

                //Create a hit specification to determine display based on values entered by an editor on the search page.
                var hitSpec = new HitSpecification
                {
                    HighlightTitle   = model.CurrentPage.HighlightTitles,
                    HighlightExcerpt = model.CurrentPage.HighlightExcerpts,
                    ExcerptLength    = model.ExcerptLength
                };

                try
                {
                    model.Hits = query.GetResult(hitSpec);
                }
                catch (WebException wex)
                {
                    model.IsConfigured = wex.Status != WebExceptionStatus.NameResolutionFailure;
                }
            }

            RequireClientResources();

            return(View(model));
        }
        public ViewResult Index(EmployeeLocationPage currentPage, string q)
        {
            var model = new EmployeeSearchContentModel(currentPage)
            {
                PublicProxyPath = _findUIConfiguration.AbsolutePublicProxyPath()
            };

            var query = _searchClient.Search <EmployeePage>()
                        .Filter(x => x.EmployeeLocation.Match(currentPage.Name));

            if (this.ControllerContext.RequestContext.HttpContext.Request.QueryString["expertise"] != null)
            {
                string qs = this.ControllerContext.RequestContext.HttpContext.Request.QueryString["expertise"].ToString();
                query = query.Filter(x => x.EmployeeExpertiseList.Match(qs));
            }

            query = query.TermsFacetFor(x => x.EmployeeExpertiseList).OrderBy(x => x.LastName);

            model.FindResult = query.Take(100).GetPagesResult();

            return(View(model));
        }