public override Dictionary <Type, Func <SystemEntity, IEnumerable <LuceneAction> > > GetRelatedEntities()
 {
     return(new Dictionary <Type, Func <SystemEntity, IEnumerable <LuceneAction> > >
     {
         {
             typeof(Brand),
             entity =>
             {
                 if (entity is Brand)
                 {
                     var page = (entity as Brand);
                     var products =
                         _session.QueryOver <Product>()
                         .Where(product => product.BrandPage.Id == page.Id)
                         .Cacheable()
                         .List();
                     return products.Select(product =>
                                            new LuceneAction
                     {
                         Entity = product.Unproxy(),
                         Operation = LuceneOperation.Update,
                         IndexDefinition =
                             IndexingHelper.Get <ProductSearchIndex>()
                     }).ToList();
                 }
                 return new List <LuceneAction>();
             }
         }
     });
 }
示例#2
0
        private GenerationSummary?RunSingleGeneration(int generationNumber, Array <Individual> population, Array <Fitness> populationFitnesses)
        {
            var mutants = _populationMutator.TryMutate(population);

            if (mutants is null)
            {
                return(null);
            }

            var mutantsFitnesses           = _fitnessEvaluator.EvaluateAsMaximizationTask(mutants);
            var fittestCandidates          = population.Concatenate(mutants);
            var fittestCandidatesFitnesses = populationFitnesses.Concatenate(mutantsFitnesses);
            var fittestIndices             = _fittestIdentifier.FindIndicesOfFittestIndividuals(fittestCandidatesFitnesses);

            var fittestIndividuals = IndexingHelper.CopyIndexedItems(
                indices: fittestIndices,
                items: fittestCandidates);

            var fittestIndividualsFitnesses = IndexingHelper.CopyIndexedItems(
                indices: fittestIndices,
                items: fittestCandidatesFitnesses);

            return(new GenerationSummary(
                       generationNumber: generationNumber,
                       population: fittestIndividuals,
                       fitnesses: fittestIndividualsFitnesses));
        }
示例#3
0
        public Query GetQuery()
        {
            if (string.IsNullOrWhiteSpace(Term) && string.IsNullOrWhiteSpace(Type) && !CreatedOnTo.HasValue && !CreatedOnFrom.HasValue && Parent == null)
            {
                return(new MatchAllDocsQuery());
            }

            BooleanQuery booleanQuery = new BooleanQuery();

            if (!string.IsNullOrWhiteSpace(Term))
            {
                IndexDefinition indexDefinition       = IndexingHelper.Get <AdminWebpageIndexDefinition>();
                Lucene.Net.Analysis.Analyzer analyser = indexDefinition.GetAnalyser();
                MultiFieldQueryParser        parser   = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_30, indexDefinition.SearchableFieldNames, analyser);
                Query query = Term.SafeGetSearchQuery(parser, analyser);

                booleanQuery.Add(query, Occur.MUST);
            }
            if (CreatedOnFrom.HasValue || CreatedOnTo.HasValue)
            {
                booleanQuery.Add(GetDateQuery(), Occur.MUST);
            }
            if (!string.IsNullOrEmpty(Type))
            {
                booleanQuery.Add(new TermQuery(new Term(FieldDefinition.GetFieldName <TypeFieldDefinition>(), Type)),
                                 Occur.MUST);
            }
            if (Parent != null)
            {
                booleanQuery.Add(
                    new TermQuery(new Term(FieldDefinition.GetFieldName <ParentIdFieldDefinition>(), Parent.Id.ToString())), Occur.MUST);
            }

            return(booleanQuery);
        }
示例#4
0
 public override Dictionary <Type, Func <SystemEntity, IEnumerable <LuceneAction> > > GetRelatedEntities()
 {
     return(new Dictionary <Type, Func <SystemEntity, IEnumerable <LuceneAction> > >
     {
         {
             typeof(Category),
             entity =>
             {
                 if (entity is Category)
                 {
                     var category = (entity as Category);
                     Category categoryAlias = null;
                     IList <Product> products =
                         _session.QueryOver <Product>()
                         .JoinAlias(product => product.Categories, () => categoryAlias)
                         .Where(product => categoryAlias.Id == category.Id)
                         .Cacheable()
                         .List();
                     return products.Select(product =>
                                            new LuceneAction
                     {
                         Entity = product.Unproxy(),
                         Operation = LuceneOperation.Update,
                         IndexDefinition =
                             IndexingHelper.Get <ProductSearchIndex>()
                     }).ToList();
                 }
                 return new List <LuceneAction>();
             }
         }
     });
 }
示例#5
0
 public override Dictionary <Type, Func <SystemEntity, IEnumerable <LuceneAction> > > GetRelatedEntities()
 {
     return(new Dictionary <Type, Func <SystemEntity, IEnumerable <LuceneAction> > >
     {
         {
             typeof(UrlHistory),
             entity =>
             {
                 if (entity is UrlHistory)
                 {
                     return new List <LuceneAction>
                     {
                         new LuceneAction
                         {
                             Entity = (entity as UrlHistory).Webpage,
                             Operation = LuceneOperation.Update,
                             IndexDefinition = IndexingHelper.Get <AdminWebpageIndexDefinition>()
                         }
                     };
                 }
                 return new List <LuceneAction>();
             }
         }
     });
 }
示例#6
0
 private static LuceneAction GetAction(Product product)
 {
     return(new LuceneAction
     {
         Entity = product.Unproxy(),
         Operation = LuceneOperation.Update,
         IndexDefinition = IndexingHelper.Get <ProductSearchIndex>()
     });
 }
        public void PopulateSearchDocument_WhenPopulatingDocument_ShouldAddDiscountGBPPrice()
        {
            var result   = _subject.PopulateSearchDocument("en", "Product");
            var document = result as OkNegotiatedContentResult <RestSearchDocument>;

            document.Content.Fields.First(x => x.Name.Equals(IndexingHelper.GetPriceField(MarketId.Default, Currency.GBP))).Values.First()
            .Should()
            .Equals((2000m).ToString(CultureInfo.InvariantCulture));
        }
        public void UpdateSearchDocument_WhenPopulatingDocument_ShouldAddOriginalUSDPrice()
        {
            var entry    = GetCatalogEntryRow("Product");
            var document = new SearchDocument();

            _subject.UpdateSearchDocument(ref document, entry, "en");
            document[IndexingHelper.GetOriginalPriceField(MarketId.Default, Currency.USD)].Value.ToString()
            .Should()
            .Equals((1000m).ToString(CultureInfo.InvariantCulture));
        }
示例#9
0
        private IEnumerable <ProductViewModel> CreateProductViewModels(ISearchResults searchResult)
        {
            var market   = _currentMarket.GetCurrentMarket();
            var currency = _currencyService.GetCurrentCurrency();

            return(searchResult.Documents.Select(document => new ProductViewModel
            {
                Brand = GetString(document, "brand"),
                Code = GetString(document, "code"),
                DisplayName = GetString(document, "displayname"),
                PlacedPrice = new Money(GetDecimal(document, IndexingHelper.GetOriginalPriceField(market.MarketId, currency)), currency),
                ExtendedPrice = new Money(GetDecimal(document, IndexingHelper.GetPriceField(market.MarketId, currency)), currency),
                ImageUrl = GetString(document, "image_url"),
                Url = _urlResolver.GetUrl(ContentReference.Parse(GetString(document, "content_link")))
            }));
        }
        private static IEnumerable <LuceneAction> GetActions(SystemEntity entity)
        {
            var line = entity as ProductOptionValue;

            if (line != null && line.ProductVariant != null && line.ProductVariant.Product != null)
            {
                yield return new LuceneAction
                       {
                           Entity          = line.ProductVariant.Product.Unproxy(),
                           Operation       = LuceneOperation.Update,
                           IndexDefinition =
                               IndexingHelper.Get <ProductSearchIndex>()
                       }
            }
            ;
        }
示例#11
0
        private IEnumerable <LuceneAction> GetValueActions(SystemEntity entity)
        {
            var line = entity as ProductSpecificationValue;

            if (line == null)
            {
                yield break;
            }

            yield return(new LuceneAction
            {
                Entity = line.Product.Unproxy(),
                Operation = LuceneOperation.Update,
                IndexDefinition = IndexingHelper.Get <ProductSearchIndex>()
            });
        }
示例#12
0
        public static void QueueTask(Type type, SiteEntity siteEntity, LuceneOperation operation)
        {
            if (IndexingHelper.AnyIndexes(siteEntity, operation))
            {
                var info = new QueuedTaskInfo
                {
                    Data   = siteEntity.Id.ToString(),
                    Type   = type.MakeGenericType(siteEntity.GetType()),
                    SiteId = siteEntity.Site.Id
                };

                if (!CurrentRequestData.OnEndRequest.OfType <AddLuceneTaskInfo>().Any(task => info.Equals(task.Data)))
                {
                    CurrentRequestData.OnEndRequest.Add(new AddLuceneTaskInfo(info));
                }
            }
        }
示例#13
0
        public IEnumerable <SortOrder> GetSortOrder()
        {
            var market   = _currentMarket.GetCurrentMarket();
            var currency = _currencyService.GetCurrentCurrency();

            return(new List <SortOrder>
            {
                new SortOrder {
                    Name = ProductSortOrder.PriceAsc, Key = IndexingHelper.GetPriceField(market.MarketId, currency), SortDirection = SortDirection.Ascending
                },
                new SortOrder {
                    Name = ProductSortOrder.Popularity, Key = "", SortDirection = SortDirection.Ascending
                },
                new SortOrder {
                    Name = ProductSortOrder.NewestFirst, Key = "created", SortDirection = SortDirection.Descending
                }
            });
        }
示例#14
0
        public Query Get(ProductSearchQuery searchQuery)
        {
            var booleanQuery = new BooleanQuery {
                ProductSearchPublishedDefinition.PublishedOnly
            };

            if (!searchQuery.Options.Any() && !searchQuery.Specifications.Any() && Math.Abs(searchQuery.PriceFrom - 0) < 0.01 && !searchQuery.PriceTo.HasValue &&
                !searchQuery.CategoryId.HasValue && string.IsNullOrWhiteSpace(searchQuery.SearchTerm) &&
                !searchQuery.BrandId.HasValue)
            {
                return(booleanQuery);
            }

            if (searchQuery.Options.Any())
            {
                booleanQuery.Add(GetOptionsQuery(searchQuery.Options), Occur.MUST);
            }
            if (searchQuery.Specifications.Any())
            {
                booleanQuery.Add(GetSpecificationsQuery(searchQuery.Specifications), Occur.MUST);
            }
            if (searchQuery.CategoryId.HasValue)
            {
                booleanQuery.Add(GetCategoriesQuery(searchQuery.CategoryId.Value), Occur.MUST);
            }
            if (searchQuery.PriceFrom > 0 || searchQuery.PriceTo.HasValue)
            {
                booleanQuery.Add(GetPriceRangeQuery(searchQuery), Occur.MUST);
            }
            if (!String.IsNullOrWhiteSpace(searchQuery.SearchTerm))
            {
                IndexDefinition indexDefinition = IndexingHelper.Get <ProductSearchIndex>();
                Analyzer        analyser        = indexDefinition.GetAnalyser();
                var             parser          = new MultiFieldQueryParser(Version.LUCENE_30, indexDefinition.SearchableFieldNames, analyser);
                Query           query           = searchQuery.SearchTerm.SafeGetSearchQuery(parser, analyser);

                booleanQuery.Add(query, Occur.MUST);
            }
            if (searchQuery.BrandId.HasValue)
            {
                booleanQuery.Add(GetBrandQuery(searchQuery.BrandId.Value), Occur.MUST);
            }
            return(booleanQuery);
        }
示例#15
0
        private static IEnumerable <LuceneAction> GetActions(SystemEntity entity)
        {
            var line = entity as ProductSpecificationAttributeOption;

            if (line == null)
            {
                yield break;
            }

            var productSpecificationValues = line.Values;

            foreach (var product in productSpecificationValues.Select(value => value.Product).Where(p => p != null))
            {
                yield return(new LuceneAction
                {
                    Entity = product.Unproxy(),
                    Operation = LuceneOperation.Update,
                    IndexDefinition =
                        IndexingHelper.Get <ProductSearchIndex>()
                });
            }
        }
示例#16
0
        public Query GetQuery()
        {
            var booleanQuery = new BooleanQuery
            {
                {
                    new TermRangeQuery(
                        FieldDefinition.GetFieldName <PublishedOnFieldDefinition>(), null,
                        DateTools.DateToString(CurrentRequestData.Now, DateTools.Resolution.SECOND), false, true),
                    Occur.MUST
                }
            };

            if (!String.IsNullOrWhiteSpace(Term))
            {
                var   indexDefinition = IndexingHelper.Get <WebpageSearchIndexDefinition>();
                var   analyser        = indexDefinition.GetAnalyser();
                var   parser          = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_30, indexDefinition.SearchableFieldNames, analyser);
                Query query           = Term.SafeGetSearchQuery(parser, analyser);

                booleanQuery.Add(query, Occur.MUST);
            }
            if (CreatedOnFrom.HasValue || CreatedOnTo.HasValue)
            {
                booleanQuery.Add(GetDateQuery(), Occur.MUST);
            }
            if (!string.IsNullOrEmpty(Type))
            {
                booleanQuery.Add(new TermQuery(new Term(FieldDefinition.GetFieldName <TypeFieldDefinition>(), Type)),
                                 Occur.MUST);
            }
            if (Parent != null)
            {
                booleanQuery.Add(
                    new TermQuery(new Term(FieldDefinition.GetFieldName <ParentIdFieldDefinition>(), Parent.Id.ToString())), Occur.MUST);
            }

            return(booleanQuery);
        }
示例#17
0
        private IEnumerable <ProductTileViewModel> CreateProductViewModels(ISearchResults searchResult)
        {
            var market   = _currentMarket.GetCurrentMarket();
            var currency = _currencyService.GetCurrentCurrency();

            return(searchResult.Documents.Select(document =>
            {
                var code = GetString(document, "code");
                var placedPrice = new Money(GetDecimal(document, IndexingHelper.GetOriginalPriceField(market.MarketId, currency)), currency);
                var discountedPrice = GetDiscountedPrice(code, placedPrice, market);
                return new ProductTileViewModel
                {
                    Brand = GetString(document, "brand"),
                    Code = GetString(document, "code"),
                    DisplayName = GetString(document, "displayname"),
                    PlacedPrice = placedPrice,
                    DiscountedPrice = discountedPrice,
                    ImageUrl = GetString(document, "image_url"),
                    Url = _urlResolver.GetUrl(ContentReference.Parse(GetString(document, "content_link"))),
                    IsAvailable = GetDecimal(document, IndexingHelper.GetOriginalPriceField(market.MarketId, currency)) > 0 || GetString(document, "_classtype") == "bundle"
                };
            }));
        }