private static void InsertBestBets(ElasticEpiSearchParams searchParams, ElasticEpiSearchResults results, ICollection <string> contentGuids)
        {
            var bestBets = ServiceLocator.Current.GetInstance <IDynamicDataRepository <BestBet> >().ReadAll()
                           .Where(bb => string.Equals(bb.Keyword, searchParams.Query, StringComparison.CurrentCultureIgnoreCase) &&
                                  string.Equals(bb.Language, searchParams.LanguageName,
                                                StringComparison.CurrentCultureIgnoreCase));

            var bestBetValidator = searchParams.BestBetOptions.Validator;

            foreach (var bestBet in bestBets)
            {
                var contents = bestBet.Contents.OrderByDescending(c => c.Order).Skip(searchParams.Skip)
                               .Take(searchParams.Take).ToList();

                foreach (var content in contents)
                {
                    var page = PageResolver.ResolvePage(content.ContentGuid, searchParams.LanguageName);

                    if (bestBetValidator != null && !bestBetValidator.ShouldIncludeAsBestBet(page, searchParams.BestBetOptions))
                    {
                        continue;
                    }

                    var document = ServiceLocator.Current.GetInstance <IEpiPageParser>().Parse(page);

                    if (document != null)
                    {
                        contentGuids.Add(document.ContentGuid);

                        results.Items.Add(new ElasticEpiSearchResultItem
                        {
                            Document = document,
                            Score    = double.MaxValue
                        });

                        results.Count++;

                        if (searchParams.Take > 0)
                        {
                            searchParams.Take--;
                        }
                    }
                }

                if (searchParams.Skip > 0)
                {
                    searchParams.Skip -= contents.Count;
                }

                if (searchParams.Skip < 0)
                {
                    searchParams.Skip = 0;
                }
            }
        }
示例#2
0
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            var resolver = new PageResolver();

            resolver.AddResolver(Navigation.MessageAlias, () => new MessagePage());
            resolver.AddResolver(Navigation.SendAlias, () => new SendPage());
            resolver.AddResolver(Navigation.SendConfirmationAlias, () => new SendConfirmationPage());
            resolver.AddResolver(Navigation.ConversionConfirmationAlias, () => new ConversionConfirmationPage());
            resolver.AddResolver(Navigation.SendingAlias, () => new SendingPage());

            Navigation.UseResolver(resolver);
            Navigation.Service = Frame.NavigationService;
        }