Beispiel #1
0
        /// <summary>
        /// Returns a collection of entities for media based on search results
        /// </summary>
        /// <param name="results"></param>
        /// <returns></returns>
        private IEnumerable <EntityBasic> MemberFromSearchResults(ISearchResults results)
        {
            var mapped = Mapper.Map <IEnumerable <EntityBasic> >(results).ToArray();

            //add additional data
            foreach (var m in mapped)
            {
                //if no icon could be mapped, it will be set to document, so change it to picture
                if (m.Icon == "icon-document")
                {
                    m.Icon = "icon-user";
                }

                var searchResult = results.First(x => x.Id.ToInvariantString() == m.Id.ToString());
                if (searchResult.Fields.ContainsKey("email") && searchResult.Fields["email"] != null)
                {
                    m.AdditionalData["Email"] = results.First(x => x.Id.ToInvariantString() == m.Id.ToString()).Fields["email"];
                }
                if (searchResult.Fields.ContainsKey("__key") && searchResult.Fields["__key"] != null)
                {
                    Guid key;
                    if (Guid.TryParse(searchResult.Fields["__key"], out key))
                    {
                        m.Key = key;
                    }
                }
            }
            return(mapped);
        }
Beispiel #2
0
        /// <summary>
        ///  Get the Forum Info - using examine, because that can be faster when
        ///  there are lots and lots of posts - although i've yet to see it
        ///  really get faster than the traverse method (yet)
        /// </summary>
        /// <param name="item"></param>
        /// <param name="useExamine">true to use examine</param>
        public static ForumCacheItem GetForumInfo(this IPublishedContent item, bool useExamine)
        {
            if (!useExamine)
            {
                return(GetForumInfo(item));
            }

            ExamineManager.Instance.TryGetSearcher("InternalSearcher", out _);

            var cacheName = $"forum_{item.Id}";
            var cache     = Current.AppCaches.RuntimeCache;
            var forumInfo = cache.GetCacheItem <ForumCacheItem>(cacheName);

            if (forumInfo != null)
            {
                return(forumInfo);
            }

            //Stopwatch sw = new Stopwatch();
            //sw.Start();

            forumInfo = new ForumCacheItem();

            ISearchResults searchResults = queryLastPostIndex(item, item.Name);
            ISearchResults updateResults = queryLastEditIndex(item, item.Name);

            forumInfo.Count      = searchResults.ToList().Count - 1;
            forumInfo.latestPost = DateTime.MinValue;

            if (searchResults.Any())
            {
                var lastpostdate = new DateTime(Convert.ToInt64(searchResults.First().Values["createDate"]));
                if (lastpostdate > DateTime.MinValue)
                {
                    forumInfo.latestPost = lastpostdate;
                }
                forumInfo.lastpostAuthor = searchResults.First().Values["postCreator"];
            }
            if (updateResults.Any())
            {
                var latestedit = new DateTime(Convert.ToInt64(searchResults.First().Values["editDate"]));
                if (latestedit > DateTime.MinValue)
                {
                    forumInfo.latestEdit = latestedit;
                }
            }

            cache.InsertCacheItem <ForumCacheItem>(cacheName, () => forumInfo);

            return(forumInfo);
        }
Beispiel #3
0
        public void GivenIndexingDocument_WhenRichTextPropertyData_CanStoreImmenseFields()
        {
            using (GetSynchronousContentIndex(false, out UmbracoContentIndex index, out _, out ContentValueSetBuilder contentValueSetBuilder, null))
            {
                index.CreateIndex();

                ContentType contentType = ContentTypeBuilder.CreateBasicContentType();
                contentType.AddPropertyType(new PropertyType(TestHelper.ShortStringHelper, "test", ValueStorageType.Ntext)
                {
                    Alias = "rte",
                    Name  = "RichText",
                    PropertyEditorAlias = Cms.Core.Constants.PropertyEditors.Aliases.TinyMce
                });

                Content content = ContentBuilder.CreateBasicContent(contentType);
                content.Id   = 555;
                content.Path = "-1,555";

                var luceneStringFieldMaxLength = ByteBlockPool.BYTE_BLOCK_SIZE - 2;
                var faker       = new Faker();
                var immenseText = faker.Random.String(length: luceneStringFieldMaxLength + 10);

                content.Properties["rte"].SetValue(immenseText);

                IEnumerable <ValueSet> valueSet = contentValueSetBuilder.GetValueSets(content);
                index.IndexItems(valueSet);

                ISearchResults results = index.Searcher.CreateQuery().Id(555).Execute();
                ISearchResult  result  = results.First();

                var key = $"{UmbracoExamineFieldNames.RawFieldPrefix}rte";
                Assert.IsTrue(result.Values.ContainsKey(key));
                Assert.Greater(result.Values[key].Length, luceneStringFieldMaxLength);
            }
        }
        public void Can_Add_A_New_Product_To_The_Index()
        {
            PreTestDataWorker.DeleteAllProducts();

            //// Arrange
            var provider = (ProductIndexer)ExamineManager.Instance.IndexProviderCollection["MerchelloProductIndexer"];

            provider.RebuildIndex();

            var searcher = ExamineManager.Instance.SearchProviderCollection["MerchelloProductSearcher"];

            var productVariantService = PreTestDataWorker.ProductVariantService;

            //// Act
            var product = MockProductDataMaker.MockProductCollectionForInserting(1).First();

            product.ProductOptions.Add(new ProductOption("Color"));
            product.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Blue", "Blue"));
            product.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Red", "Red"));
            product.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Green", "Green"));
            product.ProductOptions.Add(new ProductOption("Size"));
            product.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("Small", "Sm"));
            product.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("Medium", "Med"));
            product.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("Large", "Lg"));
            product.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("X-Large", "XL"));
            product.Height      = 11M;
            product.Width       = 11M;
            product.Length      = 11M;
            product.CostOfGoods = 15M;
            product.OnSale      = true;
            product.SalePrice   = 18M;
            _productService.Save(product);


            var attributes = new ProductAttributeCollection()
            {
                product.ProductOptions.First(x => x.Name == "Color").Choices.First(x => x.Sku == "Blue"),
                product.ProductOptions.First(x => x.Name == "Size").Choices.First(x => x.Sku == "XL")
            };

            productVariantService.CreateProductVariantWithKey(product, attributes);

            provider.AddProductToIndex(product);

            //// Assert
            var criteria = searcher.CreateSearchCriteria("productvariant", BooleanOperation.And);

            criteria.Field("productKey", product.Key.ToString()).And().Field("master", "true");

            ISearchResults results = searcher.Search(criteria);

            Assert.IsTrue(results.Count() == 1);
            var result = results.First();

            Assert.NotNull(result.Fields["productOptions"]);

            provider.RebuildIndex();
        }
Beispiel #5
0
        public void GivenIndexingDocument_WhenGridPropertyData_ThenDataIndexedInSegregatedFields()
        {
            using (GetSynchronousContentIndex(false, out UmbracoContentIndex index, out _, out ContentValueSetBuilder contentValueSetBuilder, null))
            {
                index.CreateIndex();

                ContentType contentType = ContentTypeBuilder.CreateBasicContentType();
                contentType.AddPropertyType(new PropertyType(TestHelper.ShortStringHelper, "test", ValueStorageType.Ntext)
                {
                    Alias = "grid",
                    Name  = "Grid",
                    PropertyEditorAlias = Cms.Core.Constants.PropertyEditors.Aliases.Grid
                });
                Content content = ContentBuilder.CreateBasicContent(contentType);
                content.Id   = 555;
                content.Path = "-1,555";
                var gridVal = new GridValue
                {
                    Name     = "n1",
                    Sections = new List <GridValue.GridSection>
                    {
                        new GridValue.GridSection
                        {
                            Grid = "g1",
                            Rows = new List <GridValue.GridRow>
                            {
                                new GridValue.GridRow
                                {
                                    Id    = Guid.NewGuid(),
                                    Name  = "row1",
                                    Areas = new List <GridValue.GridArea>
                                    {
                                        new GridValue.GridArea
                                        {
                                            Grid     = "g2",
                                            Controls = new List <GridValue.GridControl>
                                            {
                                                new GridValue.GridControl
                                                {
                                                    Editor = new GridValue.GridEditor
                                                    {
                                                        Alias = "editor1",
                                                        View  = "view1"
                                                    },
                                                    Value = "value1"
                                                },
                                                new GridValue.GridControl
                                                {
                                                    Editor = new GridValue.GridEditor
                                                    {
                                                        Alias = "editor1",
                                                        View  = "view1"
                                                    },
                                                    Value = "value2"
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                };

                var json = JsonConvert.SerializeObject(gridVal);
                content.Properties["grid"].SetValue(json);

                IEnumerable <ValueSet> valueSet = contentValueSetBuilder.GetValueSets(content);
                index.IndexItems(valueSet);

                ISearchResults results = index.Searcher.CreateQuery().Id(555).Execute();
                Assert.AreEqual(1, results.TotalItemCount);

                ISearchResult result = results.First();
                Assert.IsTrue(result.Values.ContainsKey("grid.row1"));
                Assert.AreEqual("value1", result.AllValues["grid.row1"][0]);
                Assert.AreEqual("value2", result.AllValues["grid.row1"][1]);
                Assert.IsTrue(result.Values.ContainsKey("grid"));
                Assert.AreEqual("value1 value2 ", result["grid"]);
                Assert.IsTrue(result.Values.ContainsKey($"{UmbracoExamineFieldNames.RawFieldPrefix}grid"));
                Assert.AreEqual(json, result[$"{UmbracoExamineFieldNames.RawFieldPrefix}grid"]);
            }
        }