예제 #1
0
        public void Inclusion_Exclusion_Type_List()
        {
            var validator = new ContentValueSetValidator(
                false,
                true,
                Mock.Of <IPublicAccessService>(),
                Mock.Of <IScopeProvider>(),
                includeItemTypes: new List <string> {
                "include-content", "exclude-content"
            },
                excludeItemTypes: new List <string> {
                "exclude-content"
            });

            ValueSetValidationResult result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, "test-content", new { hello = "world", path = "-1,555" }));

            Assert.AreEqual(ValueSetValidationStatus.Failed, result.Status);

            result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,555" }));
            Assert.AreEqual(ValueSetValidationStatus.Failed, result.Status);

            result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, "exclude-content", new { hello = "world", path = "-1,555" }));
            Assert.AreEqual(ValueSetValidationStatus.Failed, result.Status);

            result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, "include-content", new { hello = "world", path = "-1,555" }));
            Assert.AreEqual(ValueSetValidationStatus.Valid, result.Status);
        }
예제 #2
0
        public void Published_Only()
        {
            var validator = new ContentValueSetValidator(
                true,
                true,
                Mock.Of <IPublicAccessService>(),
                Mock.Of <IScopeProvider>());

            ValueSetValidationResult result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,555" }));

            Assert.AreEqual(ValueSetValidationStatus.Failed, result.Status);

            result = validator.Validate(new ValueSet(
                                            "555",
                                            IndexTypes.Content,
                                            new Dictionary <string, object>
            {
                ["hello"] = "world",
                ["path"]  = "-1,555",
                [UmbracoExamineFieldNames.PublishedFieldName] = "n"
            }));
            Assert.AreEqual(ValueSetValidationStatus.Failed, result.Status);

            result = validator.Validate(new ValueSet(
                                            "555",
                                            IndexTypes.Content,
                                            new Dictionary <string, object>
            {
                ["hello"] = "world",
                ["path"]  = "-1,555",
                [UmbracoExamineFieldNames.PublishedFieldName] = "y"
            }));
            Assert.AreEqual(ValueSetValidationStatus.Valid, result.Status);
        }
예제 #3
0
        public void MultiIndex_Simple_Search()
        {
            var analyzer = new StandardAnalyzer(Version.LUCENE_30);

            using (var luceneDir1 = new RandomIdRAMDirectory())
                using (var luceneDir2 = new RandomIdRAMDirectory())
                    using (var luceneDir3 = new RandomIdRAMDirectory())
                        using (var luceneDir4 = new RandomIdRAMDirectory())
                            using (var indexer1 = new TestIndex(luceneDir1, analyzer))
                                using (var indexer2 = new TestIndex(luceneDir2, analyzer))
                                    using (var indexer3 = new TestIndex(luceneDir3, analyzer))
                                        using (var indexer4 = new TestIndex(luceneDir4, analyzer))

                                        {
                                            indexer1.IndexItem(ValueSet.FromObject(1.ToString(), "content", new { item1 = "value1", item2 = "The agitated zebras gallop back and forth in short, panicky dashes, then skitter off into the absolute darkness." }));
                                            indexer2.IndexItem(ValueSet.FromObject(1.ToString(), "content", new { item1 = "value2", item2 = "The festival lasts five days and celebrates the victory of good over evil, light over darkness, and knowledge over ignorance." }));
                                            indexer3.IndexItem(ValueSet.FromObject(1.ToString(), "content", new { item1 = "value3", item2 = "They are expected to confront the darkness and show evidence that they have done so in their papers" }));
                                            indexer4.IndexItem(ValueSet.FromObject(1.ToString(), "content", new { item1 = "value4", item2 = "Scientists believe the lake could be home to cold-loving microbial life adapted to living in total darkness." }));
                                            indexer3.IndexItem(ValueSet.FromObject(2.ToString(), "content", new { item1 = "value3", item2 = "Scotch scotch scotch, i love scotch" }));
                                            indexer4.IndexItem(ValueSet.FromObject(2.ToString(), "content", new { item1 = "value4", item2 = "60% of the time, it works everytime" }));

                                            using (var searcher = new MultiIndexSearcher("testSearcher",
                                                                                         new[] { indexer1, indexer2, indexer3, indexer4 },
                                                                                         analyzer))
                                            {
                                                var result = searcher.Search("darkness");

                                                Assert.AreEqual(4, result.TotalItemCount);
                                                foreach (var r in result)
                                                {
                                                    Console.WriteLine("Score = " + r.Score);
                                                }
                                            }
                                        }
        }
        public void Recycle_Bin_Content()
        {
            var validator = new ContentValueSetValidator(
                true,
                false,
                Mock.Of <IPublicAccessService>(),
                Mock.Of <IScopeProvider>());

            var result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,-20,555" }));

            Assert.AreEqual(ValueSetValidationResult.Failed, result);

            result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,-20,555,777" }));
            Assert.AreEqual(ValueSetValidationResult.Failed, result);

            result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,555" }));
            Assert.AreEqual(ValueSetValidationResult.Failed, result);

            result = validator.Validate(new ValueSet("555", IndexTypes.Content,
                                                     new Dictionary <string, object>
            {
                ["hello"] = "world",
                ["path"]  = "-1,555",
                [UmbracoExamineIndex.PublishedFieldName] = "y"
            }));
            Assert.AreEqual(ValueSetValidationResult.Valid, result);
        }
예제 #5
0
        private void RunTest(SpatialContext ctx, SpatialStrategy strategy, Func <SpatialArgs, Query> createQuery)
        {
            var analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);

            using (var luceneDir = new RandomIdRAMDirectory())
            {
                string id1 = 1.ToString();
                string id2 = 2.ToString();
                string id3 = 3.ToString();
                string id4 = 4.ToString();

                using (var indexer = new TestIndex(luceneDir, analyzer))
                {
                    indexer.DocumentWriting += (sender, args) => Indexer_DocumentWriting(args, ctx, strategy);

                    indexer.IndexItems(new[] {
                        ValueSet.FromObject(id1, "content",
                                            new { nodeName = "location 1", bodyText = "Zanzibar is in Africa", lat = -6.1357, lng = 39.3621 }),
                        ValueSet.FromObject(id2, "content",
                                            new { nodeName = "location 2", bodyText = "In Canada there is a town called Sydney in Nova Scotia", lat = 46.1368, lng = -60.1942 }),
                        ValueSet.FromObject(id3, "content",
                                            new { nodeName = "location 3", bodyText = "Sydney is the capital of NSW in Australia", lat = -33.8688, lng = 151.2093 }),
                        ValueSet.FromObject(id4, "content",
                                            new { nodeName = "location 4", bodyText = "Somewhere unknown", lat = 50, lng = 50 })
                    });

                    DoSpatialSearch(ctx, strategy, indexer, SearchRadius, id3, createQuery, lat: -33, lng: 151);
                    DoSpatialSearch(ctx, strategy, indexer, SearchRadius, id2, createQuery, lat: 46, lng: -60);
                    DoSpatialSearch(ctx, strategy, indexer, SearchRadius, id1, createQuery, lat: -6, lng: 39);
                    DoSpatialSearch(ctx, strategy, indexer, SearchRadius, id4, createQuery, lat: 50, lng: 50);
                }
            }
        }
예제 #6
0
    public void Parent_Id()
    {
        var validator = new ContentValueSetValidator(
            false,
            true,
            Mock.Of <IPublicAccessService>(),
            Mock.Of <IScopeProvider>(),
            555);

        var result =
            validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,555" }));

        Assert.AreEqual(ValueSetValidationStatus.Filtered, result.Status);

        result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,444" }));
        Assert.AreEqual(ValueSetValidationStatus.Filtered, result.Status);

        result = validator.Validate(ValueSet.FromObject(
                                        "555",
                                        IndexTypes.Content,
                                        new { hello = "world", path = "-1,555,777" }));
        Assert.AreEqual(ValueSetValidationStatus.Valid, result.Status);

        result = validator.Validate(ValueSet.FromObject(
                                        "555",
                                        IndexTypes.Content,
                                        new { hello = "world", path = "-1,555,777,999" }));
        Assert.AreEqual(ValueSetValidationStatus.Valid, result.Status);
    }
예제 #7
0
    public void Non_Protected()
    {
        var publicAccessService = new Mock <IPublicAccessService>();

        publicAccessService.Setup(x => x.IsProtected("-1,555"))
        .Returns(Attempt.Succeed(new PublicAccessEntry(Guid.NewGuid(), 555, 444, 333, Enumerable.Empty <PublicAccessRule>())));
        publicAccessService.Setup(x => x.IsProtected("-1,777"))
        .Returns(Attempt.Fail <PublicAccessEntry>());
        var validator = new ContentValueSetValidator(
            false,
            false,
            publicAccessService.Object,
            Mock.Of <IScopeProvider>());

        var result =
            validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,555" }));

        Assert.AreEqual(ValueSetValidationStatus.Filtered, result.Status);

        result = validator.Validate(ValueSet.FromObject(
                                        "777",
                                        IndexTypes.Content,
                                        new { hello = "world", path = "-1,777" }));
        Assert.AreEqual(ValueSetValidationStatus.Valid, result.Status);
    }
예제 #8
0
    public void Recycle_Bin_Media()
    {
        var validator = new ContentValueSetValidator(
            true,
            false,
            Mock.Of <IPublicAccessService>(),
            Mock.Of <IScopeProvider>());

        var result =
            validator.Validate(ValueSet.FromObject(
                                   "555",
                                   IndexTypes.Media,
                                   new { hello = "world", path = "-1,-21,555" }));

        Assert.AreEqual(ValueSetValidationStatus.Filtered, result.Status);

        result = validator.Validate(ValueSet.FromObject(
                                        "555",
                                        IndexTypes.Media,
                                        new { hello = "world", path = "-1,-21,555,777" }));
        Assert.AreEqual(ValueSetValidationStatus.Filtered, result.Status);

        result = validator.Validate(
            ValueSet.FromObject("555", IndexTypes.Media, new { hello = "world", path = "-1,555" }));
        Assert.AreEqual(ValueSetValidationStatus.Valid, result.Status);
    }
        public IEnumerable <ValueSet> AllData()
        {
            var data = new List <ValueSet>();

            for (int i = 0; i < 100; i++)
            {
                data.Add(ValueSet.FromObject(i.ToString(), "category" + (i % 2), new { item1 = "value" + i, item2 = "value" + i }));
            }
            return(data);
        }
        public void Must_Have_Path()
        {
            var validator = new ContentValueSetValidator(false, true, Mock.Of <IPublicAccessService>());

            var result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world" }));

            Assert.AreEqual(ValueSetValidationResult.Failed, result);

            result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,555" }));
            Assert.AreEqual(ValueSetValidationResult.Valid, result);
        }
        public void Invalid_Category()
        {
            var validator = new ContentValueSetValidator(false, true, Mock.Of <IPublicAccessService>());

            var result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,555" }));

            Assert.AreEqual(ValueSetValidationResult.Valid, result);

            result = validator.Validate(ValueSet.FromObject("777", IndexTypes.Media, new { hello = "world", path = "-1,555" }));
            Assert.AreEqual(ValueSetValidationResult.Valid, result);

            result = validator.Validate(ValueSet.FromObject("555", "invalid-category", new { hello = "world", path = "-1,555" }));
            Assert.AreEqual(ValueSetValidationResult.Failed, result);
        }
        public void Inclusion_Exclusion_Field_List()
        {
            var validator = new ValueSetValidator(null, null,
                                                  new[] { "hello", "world" },
                                                  new[] { "world" });

            var valueSet = ValueSet.FromObject("555", IndexTypes.Content, "test-content", new { hello = "world", path = "-1,555", world = "your oyster" });
            var result   = validator.Validate(valueSet);

            Assert.AreEqual(ValueSetValidationResult.Filtered, result);

            Assert.IsFalse(valueSet.Values.ContainsKey("path"));
            Assert.IsTrue(valueSet.Values.ContainsKey("hello"));
            Assert.IsFalse(valueSet.Values.ContainsKey("world"));
        }
예제 #13
0
        public void MultiIndex_Field_Count()
        {
            var analyzer = new StandardAnalyzer(Version.LUCENE_30);

            using (var luceneDir1 = new RandomIdRAMDirectory())
                using (var luceneDir2 = new RandomIdRAMDirectory())
                    using (var luceneDir3 = new RandomIdRAMDirectory())
                        using (var luceneDir4 = new RandomIdRAMDirectory())
                            using (var indexer1 = new TestIndex(luceneDir1, analyzer)
                            {
                                RunAsync = false
                            })
                                using (var indexer2 = new TestIndex(luceneDir2, analyzer)
                                {
                                    RunAsync = false
                                })
                                    using (var indexer3 = new TestIndex(luceneDir3, analyzer)
                                    {
                                        RunAsync = false
                                    })
                                        using (var indexer4 = new TestIndex(luceneDir4, analyzer)
                                        {
                                            RunAsync = false
                                        })
                                        {
                                            indexer1.IndexItem(ValueSet.FromObject(1.ToString(), "content", new { item1 = "hello", item2 = "The agitated zebras gallop back and forth in short, panicky dashes, then skitter off into the absolute darkness." }));
                                            indexer2.IndexItem(ValueSet.FromObject(1.ToString(), "content", new { item1 = "world", item2 = "The festival lasts five days and celebrates the victory of good over evil, light over darkness, and knowledge over ignorance." }));
                                            indexer3.IndexItem(ValueSet.FromObject(1.ToString(), "content", new { item1 = "here", item2 = "They are expected to confront the darkness and show evidence that they have done so in their papers" }));
                                            indexer4.IndexItem(ValueSet.FromObject(1.ToString(), "content", new { item1 = "are", item2 = "Scientists believe the lake could be home to cold-loving microbial life adapted to living in total darkness." }));
                                            indexer3.IndexItem(ValueSet.FromObject(2.ToString(), "content", new { item3 = "some", item2 = "Scotch scotch scotch, i love scotch" }));
                                            indexer4.IndexItem(ValueSet.FromObject(2.ToString(), "content", new { item4 = "values", item2 = "60% of the time, it works everytime" }));

                                            using (var searcher = new MultiIndexSearcher("testSearcher",
                                                                                         new[] { indexer1, indexer2, indexer3, indexer4 },
                                                                                         analyzer))
                                            {
                                                var result = searcher.GetAllIndexedFields();
                                                //will be item1 , item2, item3, and item4
                                                Assert.AreEqual(4, result.Count());
                                                foreach (var s in new[] { "item1", "item2", "item3", "item4" })
                                                {
                                                    Assert.IsTrue(result.Contains(s));
                                                }
                                            }
                                        }
        }
예제 #14
0
        public void Can_Add_Doc_With_Easy_Fields()
        {
            using (var luceneDir = new RandomIdRAMDirectory())
                using (var indexer = new TestIndex(luceneDir, new StandardAnalyzer(Version.LUCENE_30)))
                {
                    indexer.IndexItem(ValueSet.FromObject(1.ToString(), "content",
                                                          new { item1 = "value1", item2 = "value2" }));

                    using (var s = (LuceneSearcher)indexer.GetSearcher())
                    {
                        var luceneSearcher = s.GetLuceneSearcher();
                        var fields         = luceneSearcher.Doc(0).GetFields().ToArray();
                        Assert.IsNotNull(fields.SingleOrDefault(x => x.Name == "item1"));
                        Assert.IsNotNull(fields.SingleOrDefault(x => x.Name == "item2"));
                        Assert.AreEqual("value1", fields.Single(x => x.Name == "item1").StringValue);
                        Assert.AreEqual("value2", fields.Single(x => x.Name == "item2").StringValue);
                    }
                }
        }
        public void Track_Readers()
        {
            var analyzer = new StandardAnalyzer(Version.LUCENE_30);

            using (var luceneDir = new RandomIdRAMDirectory())
                using (var indexer = new TestIndex(luceneDir, analyzer))
                {
                    indexer.IndexItems(new[] {
                        ValueSet.FromObject(1.ToString(), "content",
                                            new { nodeName = "umbraco", headerText = "world", writerName = "administrator" }),
                        ValueSet.FromObject(2.ToString(), "content",
                                            new { nodeName = "umbraco", headerText = "umbraco", writerName = "administrator" }),
                        ValueSet.FromObject(3.ToString(), "content",
                                            new { nodeName = "umbraco", headerText = "umbraco", writerName = "administrator" }),
                        ValueSet.FromObject(4.ToString(), "content",
                                            new { nodeName = "hello", headerText = "world", writerName = "blah" })
                    });

                    LuceneSearcher searcher       = (LuceneSearcher)indexer.GetSearcher();
                    IndexSearcher  luceneSearcher = (IndexSearcher)searcher.GetLuceneSearcher();

                    //Arrange
                    var sc = searcher.CreateQuery("content").Field("writerName", "administrator");

                    //Act
                    var results = sc.Execute();

                    using (var e1 = results.GetEnumerator())
                    {
                        Assert.AreEqual(2, luceneSearcher.IndexReader.RefCount);
                        using (var e2 = results.Skip(2).GetEnumerator())
                        {
                            Assert.AreEqual(3, luceneSearcher.IndexReader.RefCount);
                        }
                        Assert.AreEqual(2, luceneSearcher.IndexReader.RefCount);
                    }
                    Assert.AreEqual(1, luceneSearcher.IndexReader.RefCount);
                }
        }