示例#1
0
        protected override void OnCatalogEntryIndex(ref SearchDocument document, CatalogEntryDto.CatalogEntryRow entry, string language)
        {
            if (entry.ClassTypeId != "Product")
            {
                return;
            }

            var result = GetDocument(language, entry.Code).Result;
            if (result == null)
            {
                throw new Exception(String.Format("could not connect to {0}, please make sure site is active",
                    _url + String.Format("referenceapi/searchdocuments/{0}/{1}", language, entry.Code)));
            }
                
            foreach (var field in result.Fields.Where(field => field.Values.Any()))
            {
                document.Add
                (
                    field.IsDecimal ?
                        new SearchField(field.Name, Decimal.Parse(field.Values.First(), CultureInfo.InvariantCulture), field.Attributes.ToArray()) :
                        new SearchField(field.Name, field.Values.First(), field.Attributes.ToArray())
                );
            }
        }
示例#2
0
        protected override void OnCatalogEntryIndex(ref SearchDocument document, CatalogEntryDto.CatalogEntryRow entry, string language)
        {
            if (entry.ClassTypeId == EntryType.Variation)
            {
                return;
            }

            var result = GetDocument(language, entry.Code).Result;

            if (result == null)
            {
                throw new Exception($"could not connect to {_url}referenceapi/searchdocuments/{language}/{entry.Code}, please make sure site is active");
            }

            foreach (var field in result.Fields.Where(field => field.Values.Any()))
            {
                document.Add
                (
                    field.IsDecimal ?
                    new SearchField(field.Name, Decimal.Parse(field.Values.First(), CultureInfo.InvariantCulture), field.Attributes.ToArray()) :
                    new SearchField(field.Name, field.Values.First(), field.Attributes.ToArray())
                );
            }
        }
示例#3
0
        public void UpdateSearchDocument(ref SearchDocument document, CatalogEntryDto.CatalogEntryRow entry, string language)
        {
            var sw = new Stopwatch();

            sw.Start();
            var contentLink    = _referenceConverter.GetContentLink(entry.Code);
            var productContent = _contentLoader.Get <FashionProduct>(contentLink);
            var variants       = _contentLoader.GetItems(productContent.GetVariants(_relationRepository), CultureInfo.GetCultureInfo(language)).OfType <FashionVariant>().ToList();

            AddPrices(document, variants);
            AddColors(document, variants);
            AddSizes(document, variants);
            AddCodes(document, variants);
            document.Add(new SearchField("code", productContent.Code, new[] { SearchField.Store.YES, SearchField.IncludeInDefaultSearch.YES }));
            document.Add(new SearchField("displayname", productContent.DisplayName));
            document.Add(new SearchField("image_url", _assetUrlResolver.GetAssetUrl <IContentImage>(productContent)));
            document.Add(new SearchField("content_link", productContent.ContentLink.ToString()));
            document.Add(new SearchField("created", productContent.Created.ToString("yyyyMMddhhmmss")));
            document.Add(new SearchField("brand", productContent.Brand));
            document.Add(new SearchField("top_category_name", GetTopCategory(productContent).DisplayName));

            sw.Stop();
            _log.Debug(string.Format("Indexing of {0} for {1} took {2}", productContent.Code, language, sw.Elapsed.Milliseconds));
        }
示例#4
0
        private ISearchResults Search <T>(ISearchCriteria criteria) where T : EntryContentBase
        {
            // set up filters

            // 1: phrase

            var filters = new List <Nest.QueryContainer>();

            if (criteria is CatalogEntrySearchCriteria)
            {
                var cesc = criteria as CatalogEntrySearchCriteria;

                if (!string.IsNullOrWhiteSpace(cesc.SearchPhrase))
                {
                    filters.Add(new Nest.QueryContainerDescriptor <T>().SimpleQueryString(
                                    sq => sq.Fields(f => f.Field("*.analyzed")).Query(cesc.SearchPhrase.Trim())));
                }
            }

            // 2: id ... NOTE: Vulcan supports 1 and only 1 filter field, code

            if (criteria.ActiveFilterFields != null && criteria.ActiveFilterFields.Count() == 1 && criteria.ActiveFilterFields[0].Equals("code", StringComparison.InvariantCultureIgnoreCase))
            {
                filters.Add(new Nest.QueryContainerDescriptor <T>().Term(
                                p => p.Field(f => f.Code).Value((criteria.ActiveFilterValues[0] as SimpleValue).value)));
            }

            // 3: inactive... TODO, not sure what this should check!

            /*
             * if(!criteria.IncludeInactive)
             * {
             *  filters.Add(new Nest.QueryContainerDescriptor<T>().Term(
             *      p => p.Field(f => f.)
             * }*/

            // get catalog filter, if needed

            var catalogReferences = new List <ContentReference>();

            if (criteria is CatalogEntrySearchCriteria)
            {
                var cesc = criteria as CatalogEntrySearchCriteria;

                if (cesc.CatalogNames != null)
                {
                    var catalogs = ContentLoader.Service.GetChildren <CatalogContent>(ReferenceConverter.Service.GetRootLink());

                    if (catalogs != null && catalogs.Any())
                    {
                        foreach (var catalogName in cesc.CatalogNames)
                        {
                            var catalog = catalogs.FirstOrDefault(c => c.Name.Equals(catalogName, StringComparison.InvariantCultureIgnoreCase));

                            if (catalog != null)
                            {
                                catalogReferences.Add(catalog.ContentLink);
                            }
                        }
                    }
                }
            }

            if (!catalogReferences.Any())
            {
                catalogReferences = null;
            }

            // do search

            var searchDescriptor = new Nest.SearchDescriptor <T>();

            searchDescriptor.Skip(criteria.StartingRecord);
            searchDescriptor.Take(criteria.RecordsToRetrieve);

            if (filters.Any())
            {
                searchDescriptor.Query(q => q.Bool(b => b.Must(filters.ToArray())));
            }

            var client = VulcanHandler.Service.GetClient(new CultureInfo(criteria.Locale));

            var results = client.SearchContent <T>(q => searchDescriptor, false, catalogReferences);

            //var id = ReferenceConverter.Service.GetObjectId();

            var searchDocuments = new SearchDocuments()
            {
                TotalCount = Convert.ToInt32(results.Total)
            };

            if (results.Hits != null && results.Hits.Any())
            {
                foreach (var hit in results.Hits)
                {
                    var doc = new SearchDocument();
                    doc.Add(new SearchField("_id", ReferenceConverter.Service.GetObjectId(hit.Source.ContentLink)));

                    searchDocuments.Add(doc);
                }
            }

            return(new SearchResults(searchDocuments, criteria));
        }
示例#5
0
        public void UpdateSearchDocument(ref SearchDocument document, CatalogEntryDto.CatalogEntryRow entry, string language)
        {
            var sw = new Stopwatch();
            sw.Start();
            var contentLink = _referenceConverter.GetContentLink(entry.Code);
            var productContent = _contentLoader.Get<FashionProduct>(contentLink);
            var variants = _contentLoader.GetItems(productContent.GetVariants(_relationRepository), CultureInfo.GetCultureInfo(language)).OfType<FashionVariant>().ToList();

            AddPrices(document, variants);
            AddColors(document, variants);
            AddSizes(document, variants);
            AddCodes(document, variants);
            document.Add(new SearchField("code", productContent.Code, new[] { SearchField.Store.YES, SearchField.IncludeInDefaultSearch.YES }));
            document.Add(new SearchField("displayname", productContent.DisplayName));
            document.Add(new SearchField("image_url", _assetUrlResolver.GetAssetUrl<IContentImage>(productContent)));
            document.Add(new SearchField("content_link", productContent.ContentLink.ToString()));
            document.Add(new SearchField("created", productContent.Created.ToString("yyyyMMddhhmmss")));
            document.Add(new SearchField("brand", productContent.Brand));
            document.Add(new SearchField("top_category_name", GetTopCategory(productContent).DisplayName));

            sw.Stop();
            _log.Debug(string.Format("Indexing of {0} for {1} took {2}", productContent.Code, language, sw.Elapsed.Milliseconds));
        }