Beispiel #1
0
        public void Index_Rebuild_Index()
        {
            using (var d = new RandomIdRAMDirectory())
                using (var indexer = IndexInitializer.GetUmbracoIndexer(d))
                {
                    indexer.RebuildIndex();
                    var searcher = IndexInitializer.GetUmbracoSearcher(d);

                    //get searcher and reader to get stats
                    var r = ((IndexSearcher)searcher.GetSearcher()).GetIndexReader();

                    //there's 16 fields in the index, but 3 sorted fields
                    var fields = r.GetFieldNames(IndexReader.FieldOption.ALL);

                    Assert.AreEqual(21, fields.Count());
                    //ensure there's 3 sorting fields
                    Assert.AreEqual(4, fields.Count(x => x.StartsWith(LuceneIndexer.SortedFieldNamePrefix)));
                    //there should be 11 documents (10 content, 1 media)
                    Assert.AreEqual(10, r.NumDocs());

                    //test for the special fields to ensure they are there:
                    Assert.AreEqual(1, fields.Where(x => x == LuceneIndexer.IndexNodeIdFieldName).Count());
                    Assert.AreEqual(1, fields.Where(x => x == LuceneIndexer.IndexTypeFieldName).Count());
                    Assert.AreEqual(1, fields.Where(x => x == UmbracoContentIndexer.IndexPathFieldName).Count());
                    Assert.AreEqual(1, fields.Where(x => x == UmbracoContentIndexer.NodeTypeAliasFieldName).Count());
                }
        }
Beispiel #2
0
        public void Initialize()
        {
            _cwsDir        = new RAMDirectory();
            _pdfDir        = new RAMDirectory();
            _simpleDir     = new RAMDirectory();
            _conventionDir = new RAMDirectory();

            //get all of the indexers and rebuild them all first
            var indexers = new IIndexer[]
            {
                IndexInitializer.GetUmbracoIndexer(_cwsDir),
                IndexInitializer.GetSimpleIndexer(_simpleDir),
                IndexInitializer.GetUmbracoIndexer(_conventionDir)
            };

            foreach (var i in indexers)
            {
                try
                {
                    i.RebuildIndex();
                }
                finally
                {
                    var d = i as IDisposable;
                    if (d != null)
                    {
                        d.Dispose();
                    }
                }
            }

            //now get the multi index searcher for all indexes
            _searcher = IndexInitializer.GetMultiSearcher(_pdfDir, _simpleDir, _conventionDir, _cwsDir);
        }
Beispiel #3
0
        public void Index_Ensure_No_Duplicates_In_Non_Async()
        {
            using (var d = new RandomIdRAMDirectory())
                using (var indexer = IndexInitializer.GetUmbracoIndexer(d))
                {
                    indexer.RebuildIndex();
                    var searcher = IndexInitializer.GetUmbracoSearcher(d);

                    //set to 5 so optmization occurs frequently
                    indexer.OptimizationCommitThreshold = 5;

                    //get a node from the data repo
                    var node = _contentService.GetPublishedContentByXPath("//*[string-length(@id)>0 and number(@id)>0]")
                               .Root
                               .Elements()
                               .First();

                    //get the id for th node we're re-indexing.
                    var id = (int)node.Attribute("id");

                    //reindex the same node a bunch of times
                    for (var i = 0; i < 29; i++)
                    {
                        indexer.ReIndexNode(node, IndexTypes.Content);
                    }

                    //ensure no duplicates
                    var results = searcher.Search(searcher.CreateSearchCriteria().Id(id).Compile());
                    Assert.AreEqual(1, results.Count());
                }
        }
Beispiel #4
0
        public void Index_Ensure_No_Duplicates_In_Async()
        {
            using (var d = new RAMDirectory())
            {
                var customIndexer = IndexInitializer.GetUmbracoIndexer(d);

                var isIndexing = false;

                EventHandler operationComplete = (sender, e) =>
                {
                    isIndexing = false;
                };

                //add the handler for optimized since we know it will be optimized last based on the commit count
                customIndexer.IndexOperationComplete += operationComplete;

                //remove the normal indexing error handler
                customIndexer.IndexingError -= IndexInitializer.IndexingError;

                //run in async mode
                customIndexer.RunAsync = true;

                //get a node from the data repo
                var node = _contentService.GetPublishedContentByXPath("//*[string-length(@id)>0 and number(@id)>0]")
                           .Root
                           .Elements()
                           .First();

                //get the id for th node we're re-indexing.
                var id = (int)node.Attribute("id");

                //set our internal monitoring flag
                isIndexing = true;

                //reindex the same node a bunch of times
                for (var i = 0; i < 29; i++)
                {
                    customIndexer.ReIndexNode(node, IndexTypes.Content);
                }

                //we need to check if the indexing is complete
                while (isIndexing)
                {
                    //wait until indexing is done
                    Thread.Sleep(1000);
                }

                //reset the async mode and remove event handler
                customIndexer.IndexOptimized -= operationComplete;
                customIndexer.IndexingError  += IndexInitializer.IndexingError;
                customIndexer.RunAsync        = false;


                //ensure no duplicates
                Thread.Sleep(10000);                 //seems to take a while to get its shit together... this i'm not sure why since the optimization should have def finished (and i've stepped through that code!)
                var customSearcher = IndexInitializer.GetLuceneSearcher(d);
                var results        = customSearcher.Search(customSearcher.CreateSearchCriteria().Id(id).Compile());
                Assert.AreEqual(1, results.Count());
            }
        }
Beispiel #5
0
        public void Ensure_Children_Are_Sorted()
        {
            using (var luceneDir = new RandomIdRAMDirectory())
                using (var writer = new IndexWriter(luceneDir, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29), IndexWriter.MaxFieldLength.LIMITED))
                    using (var indexer = IndexInitializer.GetUmbracoIndexer(writer))
                        using (var searcher = IndexInitializer.GetUmbracoSearcher(writer))
                        {
                            //var indexer = IndexInitializer.GetUmbracoIndexer(luceneDir);
                            indexer.RebuildIndex();

                            //var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
                            var result = searcher.Search(searcher.CreateSearchCriteria().Id(1111).Compile());
                            Assert.IsNotNull(result);
                            Assert.AreEqual(1, result.TotalItemCount);

                            var searchItem  = result.First();
                            var backedMedia = new ExamineBackedMedia(searchItem, indexer, searcher);
                            var children    = backedMedia.ChildrenAsList.Value;

                            var currSort = 0;
                            Assert.Greater(children.Count, 0);

                            for (var i = 0; i < children.Count; i++)
                            {
                                Assert.GreaterOrEqual(children[i].SortOrder, currSort);
                                currSort = children[i].SortOrder;
                            }
                        }
        }
Beispiel #6
0
        public void Ensure_Result_Has_All_Values()
        {
            var newIndexFolder = new DirectoryInfo(Path.Combine("App_Data\\CWSIndexSetTest", Guid.NewGuid().ToString()));
            var indexInit      = new IndexInitializer();
            var indexer        = indexInit.GetUmbracoIndexer(newIndexFolder);

            indexer.RebuildIndex();

            var searcher = indexInit.GetUmbracoSearcher(newIndexFolder);
            var result   = searcher.Search(searcher.CreateSearchCriteria().Id(1111).Compile());

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.TotalItemCount);

            var searchItem  = result.First();
            var backedMedia = new ExamineBackedMedia(searchItem, indexer, searcher);

            Assert.AreEqual(searchItem.Id, backedMedia.Id);
            Assert.AreEqual(searchItem.Fields["sortOrder"], backedMedia.SortOrder.ToString());
            Assert.AreEqual(searchItem.Fields["urlName"], backedMedia.UrlName);
            Assert.AreEqual(DateTools.StringToDate(searchItem.Fields["createDate"]), backedMedia.CreateDate);
            Assert.AreEqual(DateTools.StringToDate(searchItem.Fields["updateDate"]), backedMedia.UpdateDate);
            Assert.AreEqual(Guid.Parse(searchItem.Fields["version"]), backedMedia.Version);
            Assert.AreEqual(searchItem.Fields["level"], backedMedia.Level.ToString());
            Assert.AreEqual(searchItem.Fields["writerID"], backedMedia.WriterID.ToString());
            Assert.AreEqual(searchItem.Fields["writerID"], backedMedia.CreatorID.ToString()); //there's only writerId in the xml
            Assert.AreEqual(searchItem.Fields["writerName"], backedMedia.CreatorName);
            Assert.AreEqual(searchItem.Fields["writerName"], backedMedia.WriterName);         //tehre's only writer name in the xml
        }
Beispiel #7
0
        public void DescendantsOrSelf_With_Examine()
        {
            var rebuilder = IndexInitializer.GetMediaIndexRebuilder(Factory.GetInstance <PropertyEditorCollection>(), IndexInitializer.GetMockMediaService());

            using (var luceneDir = new RandomIdRamDirectory())
                using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir,
                                                                        validator: new ContentValueSetValidator(true)))
                    using (indexer.ProcessNonAsync())
                    {
                        rebuilder.RegisterIndex(indexer.Name);
                        rebuilder.Populate(indexer);

                        var searcher = indexer.GetSearcher();
                        var ctx      = GetUmbracoContext("/test");
                        var cache    = new PublishedMediaCache(ServiceContext.MediaService, ServiceContext.UserService, searcher, new DictionaryAppCache(), ContentTypesCache, Factory.GetInstance <IEntityXmlSerializer>(), Factory.GetInstance <IUmbracoContextAccessor>());

                        //we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
                        var publishedMedia  = cache.GetById(1111);
                        var rootDescendants = publishedMedia.DescendantsOrSelf();
                        Assert.IsTrue(rootDescendants.Select(x => x.Id).ContainsAll(new[] { 1111, 2112, 2222, 1113, 1114, 1115, 1116 }));

                        var publishedChild1 = cache.GetById(2222);
                        var subDescendants  = publishedChild1.DescendantsOrSelf();
                        Assert.IsTrue(subDescendants.Select(x => x.Id).ContainsAll(new[] { 2222, 2112, 3113 }));
                    }
        }
Beispiel #8
0
        public void Can_Overwrite_Index_During_Indexing_Operation()
        {
            using (var d = new RAMDirectory())
                using (var customIndexer = IndexInitializer.GetUmbracoIndexer(d))
                {
                    var isIndexing = false;

                    EventHandler operationComplete = (sender, e) =>
                    {
                        isIndexing = false;
                    };

                    //add the handler for optimized since we know it will be optimized last based on the commit count
                    customIndexer.IndexOperationComplete += operationComplete;

                    //remove the normal indexing error handler
                    customIndexer.IndexingError -= IndexInitializer.IndexingError;

                    //run in async mode
                    customIndexer.RunAsync = true;

                    //get a node from the data repo
                    var node = _contentService.GetPublishedContentByXPath("//*[string-length(@id)>0 and number(@id)>0]")
                               .Root
                               .Elements()
                               .First();

                    //get the id for th node we're re-indexing.
                    var id = (int)node.Attribute("id");

                    //set our internal monitoring flag
                    isIndexing = true;

                    //reindex the same node a bunch of times - then while this is running we'll overwrite below
                    for (var i = 0; i < 1000; i++)
                    {
                        customIndexer.ReIndexNode(node, IndexTypes.Content);
                    }

                    //overwrite!
                    customIndexer.EnsureIndex(true);

                    //we need to check if the indexing is complete
                    while (isIndexing)
                    {
                        //wait until indexing is done
                        Thread.Sleep(1000);
                    }

                    //reset the async mode and remove event handler
                    customIndexer.IndexOptimized -= operationComplete;
                    customIndexer.IndexingError  += IndexInitializer.IndexingError;
                    customIndexer.RunAsync        = false;

                    //ensure no data since it's a new index
                    var customSearcher = IndexInitializer.GetLuceneSearcher(d);
                    var results        = customSearcher.Search(customSearcher.CreateSearchCriteria().Id(id).Compile());
                    Assert.AreEqual(0, results.Count());
                }
        }
Beispiel #9
0
        public void Ensure_Children_Sorted_With_Examine()
        {
            var rebuilder = IndexInitializer.GetMediaIndexRebuilder(Factory.GetInstance <PropertyEditorCollection>(), IndexInitializer.GetMockMediaService());

            using (var luceneDir = new RandomIdRamDirectory())
                using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir,
                                                                        validator: new ContentValueSetValidator(true)))
                    using (indexer.ProcessNonAsync())
                    {
                        rebuilder.RegisterIndex(indexer.Name);
                        rebuilder.Populate(indexer);

                        var searcher = indexer.GetSearcher();
                        var ctx      = GetUmbracoContext("/test");
                        var cache    = new PublishedMediaCache(ServiceContext.MediaService, ServiceContext.UserService, searcher, new DictionaryAppCache(), ContentTypesCache, Factory.GetInstance <IEntityXmlSerializer>(), Factory.GetInstance <IUmbracoContextAccessor>());

                        //we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
                        var publishedMedia = cache.GetById(1111);
                        var rootChildren   = publishedMedia.Children().ToArray();
                        var currSort       = 0;
                        for (var i = 0; i < rootChildren.Count(); i++)
                        {
                            Assert.GreaterOrEqual(rootChildren[i].SortOrder, currSort);
                            currSort = rootChildren[i].SortOrder;
                        }
                    }
        }
Beispiel #10
0
        public void Ensure_Children_Are_Sorted()
        {
            var newIndexFolder = new DirectoryInfo(Path.Combine("App_Data\\CWSIndexSetTest", Guid.NewGuid().ToString()));
            var indexInit      = new IndexInitializer();
            var indexer        = indexInit.GetUmbracoIndexer(newIndexFolder);

            indexer.RebuildIndex();

            var searcher = indexInit.GetUmbracoSearcher(newIndexFolder);
            var result   = searcher.Search(searcher.CreateSearchCriteria().Id(1111).Compile());

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.TotalItemCount);

            var searchItem  = result.First();
            var backedMedia = new ExamineBackedMedia(searchItem, indexer, searcher);
            var children    = backedMedia.ChildrenAsList.Value;

            var currSort = 0;

            for (var i = 0; i < children.Count(); i++)
            {
                Assert.GreaterOrEqual(children[i].SortOrder, currSort);
                currSort = children[i].SortOrder;
            }
        }
Beispiel #11
0
        public void Ensure_Result_Has_All_Values()
        {
            using (var luceneDir = new RandomIdRAMDirectory())
                using (var writer = new IndexWriter(luceneDir, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29), IndexWriter.MaxFieldLength.LIMITED))
                    using (var indexer = IndexInitializer.GetUmbracoIndexer(writer))
                        using (var searcher = IndexInitializer.GetUmbracoSearcher(writer))
                        {
                            //var indexer = IndexInitializer.GetUmbracoIndexer(luceneDir);
                            indexer.RebuildIndex();

                            //var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
                            var result = searcher.Search(searcher.CreateSearchCriteria().Id(1111).Compile());
                            Assert.IsNotNull(result);
                            Assert.AreEqual(1, result.TotalItemCount);

                            var searchItem  = result.First();
                            var backedMedia = new ExamineBackedMedia(searchItem, indexer, searcher);

                            Assert.AreEqual(searchItem.Id, backedMedia.Id);
                            Assert.AreEqual(searchItem.Fields["sortOrder"], backedMedia.SortOrder.ToString());
                            Assert.AreEqual(searchItem.Fields["urlName"], backedMedia.UrlName);
                            Assert.AreEqual(DateTools.StringToDate(searchItem.Fields["createDate"]), backedMedia.CreateDate);
                            Assert.AreEqual(DateTools.StringToDate(searchItem.Fields["updateDate"]), backedMedia.UpdateDate);
                            Assert.AreEqual(Guid.Parse(searchItem.Fields["version"]), backedMedia.Version);
                            Assert.AreEqual(searchItem.Fields["level"], backedMedia.Level.ToString());
                            Assert.AreEqual(searchItem.Fields["writerID"], backedMedia.WriterID.ToString());
                            Assert.AreEqual(searchItem.Fields["writerID"], backedMedia.CreatorID.ToString()); //there's only writerId in the xml
                            Assert.AreEqual(searchItem.Fields["writerName"], backedMedia.CreatorName);
                            Assert.AreEqual(searchItem.Fields["writerName"], backedMedia.WriterName);         //tehre's only writer name in the xml
                        }
        }
Beispiel #12
0
        public void Can_Add_Multiple_Values_To_Single_Index_Field()
        {
            using (var d = new RAMDirectory())
                using (var customIndexer = IndexInitializer.GetUmbracoIndexer(d))
                {
                    EventHandler <DocumentWritingEventArgs> handler = (sender, args) =>
                    {
                        args.Document.Add(new Field("headerText", "another value", Field.Store.YES, Field.Index.ANALYZED));
                    };

                    customIndexer.DocumentWriting += handler;

                    customIndexer.RebuildIndex();

                    customIndexer.DocumentWriting += handler;

                    var customSearcher = IndexInitializer.GetLuceneSearcher(d);
                    var results        = customSearcher.Search(customSearcher.CreateSearchCriteria().NodeName("home").Compile());
                    Assert.Greater(results.TotalItemCount, 0);
                    foreach (var result in results)
                    {
                        var vals = result.GetValues("headerText");
                        Assert.AreEqual(2, vals.Count());
                        Assert.AreEqual("another value", vals.ElementAt(1));
                    }
                }
        }
Beispiel #13
0
        public void MultiIndex_Field_Count()
        {
            using (var cwsDir = new RandomIdRAMDirectory())
                using (var pdfDir = new RandomIdRAMDirectory())
                    using (var simpleDir = new RandomIdRAMDirectory())
                        using (var conventionDir = new RandomIdRAMDirectory())
                        {
                            //get all of the indexers and rebuild them all first
                            var indexers = new IIndexer[]
                            {
                                IndexInitializer.GetUmbracoIndexer(cwsDir),
                                IndexInitializer.GetSimpleIndexer(simpleDir),
                                IndexInitializer.GetUmbracoIndexer(conventionDir)
                            };
                            foreach (var i in indexers)
                            {
                                i.RebuildIndex();
                            }

                            //now get the multi index searcher for all indexes
                            using (var searcher = IndexInitializer.GetMultiSearcher(pdfDir, simpleDir, conventionDir, cwsDir))
                            {
                                var result = searcher.GetSearchFields();
                                Assert.AreEqual(26, result.Count(), "The total number for fields between all of the indexes should be ");
                            }
                        }
        }
Beispiel #14
0
 public override void TestSetup()
 {
     _luceneDir = new RAMDirectory();
     _indexer   = IndexInitializer.GetUmbracoIndexer(_luceneDir);
     _indexer.RebuildIndex();
     _searcher = IndexInitializer.GetUmbracoSearcher(_luceneDir);
 }
Beispiel #15
0
        public void AncestorsOrSelf_With_Examine()
        {
            var newIndexFolder = new DirectoryInfo(Path.Combine("App_Data\\CWSIndexSetTest", Guid.NewGuid().ToString()));
            var indexInit      = new IndexInitializer();
            var indexer        = indexInit.GetUmbracoIndexer(newIndexFolder);

            indexer.RebuildIndex();

            var store = new DefaultPublishedMediaStore(
                indexInit.GetUmbracoSearcher(newIndexFolder),
                indexInit.GetUmbracoIndexer(newIndexFolder));

            //we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
            var publishedMedia = store.GetDocumentById(GetUmbracoContext("/test", 1234), 3113);
            var ancestors      = publishedMedia.AncestorsOrSelf();

            Assert.IsTrue(ancestors.Select(x => x.Id).ContainsAll(new[] { 3113, 2112, 2222, 1111 }));
        }
Beispiel #16
0
        public void TestSetup()
        {
            _luceneDir = new RandomIdRAMDirectory();

            //_luceneDir = new SimpleFSDirectory(new DirectoryInfo(Path.Combine(TestHelper.AssemblyDirectory, Guid.NewGuid().ToString())));

            _indexer = IndexInitializer.GetUmbracoIndexer(_luceneDir);
            _indexer.RebuildIndex();
            _searcher = IndexInitializer.GetUmbracoSearcher(_luceneDir);
        }
Beispiel #17
0
        public void Ensure_Children_Sorted_With_Examine()
        {
            var newIndexFolder = new DirectoryInfo(Path.Combine("App_Data\\CWSIndexSetTest", Guid.NewGuid().ToString()));
            var indexInit      = new IndexInitializer();
            var indexer        = indexInit.GetUmbracoIndexer(newIndexFolder);

            indexer.RebuildIndex();

            var store = new DefaultPublishedMediaStore(
                indexInit.GetUmbracoSearcher(newIndexFolder),
                indexInit.GetUmbracoIndexer(newIndexFolder));

            //we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
            var publishedMedia = store.GetDocumentById(GetUmbracoContext("/test", 1234), 1111);
            var rootChildren   = publishedMedia.Children().ToArray();
            var currSort       = 0;

            for (var i = 0; i < rootChildren.Count(); i++)
            {
                Assert.GreaterOrEqual(rootChildren[i].SortOrder, currSort);
                currSort = rootChildren[i].SortOrder;
            }
        }
Beispiel #18
0
        public void MultiIndex_Simple_Search()
        {
            var cwsIndexer = IndexInitializer.GetUmbracoIndexer(_cwsDir);

            cwsIndexer.RebuildIndex();
            var cwsSearcher = IndexInitializer.GetUmbracoSearcher(_cwsDir);

            var cwsResult = cwsSearcher.Search("sam", false);
            var result    = _searcher.Search("sam", false);

            //ensure there's more results than just the one index
            Assert.IsTrue(cwsResult.Count() < result.Count());
            //there should be 8
            Assert.AreEqual(8, result.Count(), "Results returned for 'sam' should be equal to 5 with the StandardAnalyzer");
        }
Beispiel #19
0
        public void AncestorsOrSelf_With_Examine()
        {
            using (var luceneDir = new RAMDirectory())
            {
                var indexer = IndexInitializer.GetUmbracoIndexer(luceneDir);
                indexer.RebuildIndex();
                var ctx      = GetUmbracoContext("/test", 1234);
                var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
                var cache    = new ContextualPublishedMediaCache(new PublishedMediaCache(searcher, indexer), ctx);

                //we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
                var publishedMedia = cache.GetById(3113);
                var ancestors      = publishedMedia.AncestorsOrSelf();
                Assert.IsTrue(ancestors.Select(x => x.Id).ContainsAll(new[] { 3113, 2112, 2222, 1111 }));
            }
        }
Beispiel #20
0
        public void Do_Not_Find_In_Recycle_Bin()
        {
            var rebuilder = IndexInitializer.GetMediaIndexRebuilder(Factory.GetInstance <PropertyEditorCollection>(), IndexInitializer.GetMockMediaService());

            using (var luceneDir = new RandomIdRamDirectory())
                using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir,
                                                                        //include unpublished content since this uses the 'internal' indexer, it's up to the media cache to filter
                                                                        validator: new ContentValueSetValidator(false)))
                    using (indexer.ProcessNonAsync())
                    {
                        rebuilder.RegisterIndex(indexer.Name);
                        rebuilder.Populate(indexer);

                        var searcher = indexer.GetSearcher();
                        var ctx      = GetUmbracoContext("/test");
                        var cache    = new PublishedMediaCache(ServiceContext.MediaService, ServiceContext.UserService, searcher, new DictionaryAppCache(), ContentTypesCache, Factory.GetInstance <IEntityXmlSerializer>(), Factory.GetInstance <IUmbracoContextAccessor>());

                        //ensure it is found
                        var publishedMedia = cache.GetById(3113);
                        Assert.IsNotNull(publishedMedia);

                        //move item to recycle bin
                        var newXml = XElement.Parse(@"<node id='3113' key='5b3e46ab-3e37-4cfa-ab70-014234b5bd33' parentID='-21' level='1' writerID='0' nodeType='1032' template='0' sortOrder='2' createDate='2010-05-19T17:32:46' updateDate='2010-05-19T17:32:46' nodeName='Another Umbraco Image' urlName='acnestressscrub' writerName='Administrator' nodeTypeAlias='Image' path='-1,-21,3113'>
                    <data alias='umbracoFile'><![CDATA[/media/1234/blah.pdf]]></data>
                    <data alias='umbracoWidth'>115</data>
                    <data alias='umbracoHeight'>268</data>
                    <data alias='umbracoBytes'>10726</data>
                    <data alias='umbracoExtension'>jpg</data>
                </node>");
                        indexer.IndexItems(new[] { newXml.ConvertToValueSet("media") });


                        //ensure it still exists in the index (raw examine search)
                        var criteria = searcher.CreateQuery();
                        var filter   = criteria.Id(3113);
                        var found    = filter.Execute();
                        Assert.IsNotNull(found);
                        Assert.AreEqual(1, found.TotalItemCount);

                        //ensure it does not show up in the published media store
                        var recycledMedia = cache.GetById(3113);
                        Assert.IsNull(recycledMedia);
                    }
        }
        public void AncestorsOrSelf_With_Examine()
        {
            using (var luceneDir = new RandomIdRAMDirectory())
                using (var writer = new IndexWriter(luceneDir, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29), IndexWriter.MaxFieldLength.LIMITED))
                    using (var indexer = IndexInitializer.GetUmbracoIndexer(writer))
                        using (var searcher = IndexInitializer.GetUmbracoSearcher(writer))
                        {
                            //var indexer = IndexInitializer.GetUmbracoIndexer(luceneDir);
                            indexer.RebuildIndex();
                            var ctx = GetUmbracoContext("/test", 1234);
                            //var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
                            var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(ctx.Application, searcher, indexer), ctx);

                            //we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
                            var publishedMedia = cache.GetById(3113);
                            var ancestors      = publishedMedia.AncestorsOrSelf();
                            Assert.IsTrue(ancestors.Select(x => x.Id).ContainsAll(new[] { 3113, 2112, 2222, 1111 }));
                        }
        }
Beispiel #22
0
        public void DescendantsOrSelf_With_Examine()
        {
            using (var luceneDir = new RAMDirectory())
            {
                var indexer = IndexInitializer.GetUmbracoIndexer(luceneDir);
                indexer.RebuildIndex();
                var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
                var ctx      = GetUmbracoContext("/test", 1234);
                var cache    = new ContextualPublishedMediaCache(new PublishedMediaCache(searcher, indexer), ctx);

                //we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
                var publishedMedia  = cache.GetById(1111);
                var rootDescendants = publishedMedia.DescendantsOrSelf();
                Assert.IsTrue(rootDescendants.Select(x => x.Id).ContainsAll(new[] { 1111, 2112, 2222, 1113, 1114, 1115, 1116 }));

                var publishedChild1 = cache.GetById(2222);
                var subDescendants  = publishedChild1.DescendantsOrSelf();
                Assert.IsTrue(subDescendants.Select(x => x.Id).ContainsAll(new[] { 2222, 2112, 3113 }));
            }
        }
Beispiel #23
0
        public void Ensure_Children_Sorted_With_Examine()
        {
            using (var luceneDir = new RAMDirectory())
            {
                var indexer = IndexInitializer.GetUmbracoIndexer(luceneDir);
                indexer.RebuildIndex();
                var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
                var ctx      = GetUmbracoContext("/test", 1234);
                var cache    = new ContextualPublishedMediaCache(new PublishedMediaCache(searcher, indexer), ctx);

                //we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
                var publishedMedia = cache.GetById(1111);
                var rootChildren   = publishedMedia.Children().ToArray();
                var currSort       = 0;
                for (var i = 0; i < rootChildren.Count(); i++)
                {
                    Assert.GreaterOrEqual(rootChildren[i].SortOrder, currSort);
                    currSort = rootChildren[i].SortOrder;
                }
            }
        }
Beispiel #24
0
        public void Do_Not_Find_In_Recycle_Bin()
        {
            var newIndexFolder = new DirectoryInfo(Path.Combine("App_Data\\CWSIndexSetTest", Guid.NewGuid().ToString()));
            var indexInit      = new IndexInitializer();
            var indexer        = indexInit.GetUmbracoIndexer(newIndexFolder);

            indexer.RebuildIndex();
            var searcher = indexInit.GetUmbracoSearcher(newIndexFolder);
            var store    = new DefaultPublishedMediaStore(searcher, indexer);
            var ctx      = GetUmbracoContext("/test", 1234);

            //ensure it is found
            var publishedMedia = store.GetDocumentById(ctx, 3113);

            Assert.IsNotNull(publishedMedia);

            //move item to recycle bin
            var newXml = XElement.Parse(@"<node id='3113' version='5b3e46ab-3e37-4cfa-ab70-014234b5bd33' parentID='-21' level='1' writerID='0' nodeType='1032' template='0' sortOrder='2' createDate='2010-05-19T17:32:46' updateDate='2010-05-19T17:32:46' nodeName='Another Umbraco Image' urlName='acnestressscrub' writerName='Administrator' nodeTypeAlias='Image' path='-1,-21,3113'>
					<data alias='umbracoFile'><![CDATA[/media/1234/blah.pdf]]></data>
					<data alias='umbracoWidth'>115</data>
					<data alias='umbracoHeight'>268</data>
					<data alias='umbracoBytes'>10726</data>
					<data alias='umbracoExtension'>jpg</data>
				</node>"                );

            indexer.ReIndexNode(newXml, "media");

            //ensure it still exists in the index (raw examine search)
            var criteria = searcher.CreateSearchCriteria();
            var filter   = criteria.Id(3113);
            var found    = searcher.Search(filter.Compile());

            Assert.IsNotNull(found);
            Assert.AreEqual(1, found.TotalItemCount);

            //ensure it does not show up in the published media store
            var recycledMedia = store.GetDocumentById(ctx, 3113);

            Assert.IsNull(recycledMedia);
        }
        public void Do_Not_Find_In_Recycle_Bin()
        {
            using (var luceneDir = new RandomIdRAMDirectory())
                using (var writer = new IndexWriter(luceneDir, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29), IndexWriter.MaxFieldLength.LIMITED))
                    using (var indexer = IndexInitializer.GetUmbracoIndexer(writer))
                        using (var searcher = IndexInitializer.GetUmbracoSearcher(writer))
                        {
                            //var indexer = IndexInitializer.GetUmbracoIndexer(luceneDir);
                            indexer.RebuildIndex();
                            //var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
                            var ctx   = GetUmbracoContext("/test", 1234);
                            var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(ctx.Application, searcher, indexer), ctx);

                            //ensure it is found
                            var publishedMedia = cache.GetById(3113);
                            Assert.IsNotNull(publishedMedia);

                            //move item to recycle bin
                            var newXml = XElement.Parse(@"<node id='3113' version='5b3e46ab-3e37-4cfa-ab70-014234b5bd33' parentID='-21' level='1' writerID='0' nodeType='1032' template='0' sortOrder='2' createDate='2010-05-19T17:32:46' updateDate='2010-05-19T17:32:46' nodeName='Another Umbraco Image' urlName='acnestressscrub' writerName='Administrator' nodeTypeAlias='Image' path='-1,-21,3113'>
					<data alias='umbracoFile'><![CDATA[/media/1234/blah.pdf]]></data>
					<data alias='umbracoWidth'>115</data>
					<data alias='umbracoHeight'>268</data>
					<data alias='umbracoBytes'>10726</data>
					<data alias='umbracoExtension'>jpg</data>
				</node>"                );
                            indexer.ReIndexNode(newXml, "media");

                            //ensure it still exists in the index (raw examine search)
                            var criteria = searcher.CreateSearchCriteria();
                            var filter   = criteria.Id(3113);
                            var found    = searcher.Search(filter.Compile());
                            Assert.IsNotNull(found);
                            Assert.AreEqual(1, found.TotalItemCount);

                            //ensure it does not show up in the published media store
                            var recycledMedia = cache.GetById(3113);
                            Assert.IsNull(recycledMedia);
                        }
        }
Beispiel #26
0
        public void AncestorsOrSelf_With_Examine()
        {
            var rebuilder = IndexInitializer.GetMediaIndexRebuilder(Factory.GetInstance <PropertyEditorCollection>(), IndexInitializer.GetMockMediaService());

            using (var luceneDir = new RandomIdRamDirectory())
                using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir,
                                                                        validator: new ContentValueSetValidator(true)))
                    using (indexer.ProcessNonAsync())
                    {
                        rebuilder.RegisterIndex(indexer.Name);
                        rebuilder.Populate(indexer);


                        var ctx      = GetUmbracoContext("/test");
                        var searcher = indexer.GetSearcher();
                        var cache    = new PublishedMediaCache(ServiceContext.MediaService, ServiceContext.UserService, searcher, indexer, new StaticCacheProvider(), ContentTypesCache);

                        //we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
                        var publishedMedia = cache.GetById(3113);
                        var ancestors      = publishedMedia.AncestorsOrSelf();
                        Assert.IsTrue(ancestors.Select(x => x.Id).ContainsAll(new[] { 3113, 2112, 2222, 1111 }));
                    }
        }
Beispiel #27
0
        public void MultiIndex_Simple_Search()
        {
            using (var cwsDir = new RandomIdRAMDirectory())
                using (var pdfDir = new RandomIdRAMDirectory())
                    using (var simpleDir = new RandomIdRAMDirectory())
                        using (var conventionDir = new RandomIdRAMDirectory())
                        {
                            //get all of the indexers and rebuild them all first
                            var indexers = new IIndexer[]
                            {
                                IndexInitializer.GetUmbracoIndexer(cwsDir),
                                IndexInitializer.GetSimpleIndexer(simpleDir),
                                IndexInitializer.GetUmbracoIndexer(conventionDir)
                            };
                            foreach (var i in indexers)
                            {
                                i.RebuildIndex();
                            }

                            using (var cwsIndexer = IndexInitializer.GetUmbracoIndexer(cwsDir))
                            {
                                cwsIndexer.RebuildIndex();
                                //now get the multi index searcher for all indexes
                                using (var searcher = IndexInitializer.GetMultiSearcher(pdfDir, simpleDir, conventionDir, cwsDir))
                                    using (var cwsSearcher = IndexInitializer.GetUmbracoSearcher(cwsDir))
                                    {
                                        var cwsResult = cwsSearcher.Search("sam", false);
                                        var result    = searcher.Search("sam", false);

                                        //ensure there's more results than just the one index
                                        Assert.IsTrue(cwsResult.Count() < result.Count());
                                        //there should be 8
                                        Assert.AreEqual(8, result.Count(), "Results returned for 'sam' should be equal to 5 with the StandardAnalyzer");
                                    }
                            };
                        }
        }
Beispiel #28
0
        public void Ensure_Children_Are_Sorted()
        {
            using (var luceneDir = new RAMDirectory())
            {
                var indexer = IndexInitializer.GetUmbracoIndexer(luceneDir);
                indexer.RebuildIndex();

                var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
                var result   = searcher.Search(searcher.CreateSearchCriteria().Id(1111).Compile());
                Assert.IsNotNull(result);
                Assert.AreEqual(1, result.TotalItemCount);

                var searchItem  = result.First();
                var backedMedia = new ExamineBackedMedia(searchItem, indexer, searcher);
                var children    = backedMedia.ChildrenAsList.Value;

                var currSort = 0;
                for (var i = 0; i < children.Count(); i++)
                {
                    Assert.GreaterOrEqual(children[i].SortOrder, currSort);
                    currSort = children[i].SortOrder;
                }
            }
        }
        public void Ensure_Children_Sorted_With_Examine()
        {
            using (var luceneDir = new RandomIdRAMDirectory())
                using (var writer = new IndexWriter(luceneDir, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29), IndexWriter.MaxFieldLength.LIMITED))
                    using (var indexer = IndexInitializer.GetUmbracoIndexer(writer))
                        using (var searcher = IndexInitializer.GetUmbracoSearcher(writer))
                        {
                            //var indexer = IndexInitializer.GetUmbracoIndexer(luceneDir);
                            indexer.RebuildIndex();
                            //var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
                            var ctx   = GetUmbracoContext("/test", 1234);
                            var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(ctx.Application, searcher, indexer), ctx);

                            //we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
                            var publishedMedia = cache.GetById(1111);
                            var rootChildren   = publishedMedia.Children().ToArray();
                            var currSort       = 0;
                            for (var i = 0; i < rootChildren.Count(); i++)
                            {
                                Assert.GreaterOrEqual(rootChildren[i].SortOrder, currSort);
                                currSort = rootChildren[i].SortOrder;
                            }
                        }
        }
Beispiel #30
0
        public void Index_Read_And_Write_Ensure_No_Errors_In_Async()
        {
            using (var d = new RAMDirectory())
            {
                using (var writer = new IndexWriter(d, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29), IndexWriter.MaxFieldLength.LIMITED))
                    using (var customIndexer = IndexInitializer.GetUmbracoIndexer(writer))
                        using (var customSearcher = IndexInitializer.GetUmbracoSearcher(writer))
                        {
                            var isIndexing = false;

                            EventHandler operationComplete = (sender, e) =>
                            {
                                isIndexing = false;
                            };

                            //add the handler for optimized since we know it will be optimized last based on the commit count
                            customIndexer.IndexOperationComplete += operationComplete;

                            //remove the normal indexing error handler
                            customIndexer.IndexingError -= IndexInitializer.IndexingError;

                            //run in async mode
                            customIndexer.RunAsync = true;

                            //get a node from the data repo
                            var node = _contentService.GetPublishedContentByXPath("//*[string-length(@id)>0 and number(@id)>0]")
                                       .Root
                                       .Elements()
                                       .First();

                            //set our internal monitoring flag
                            isIndexing = true;

                            var docId                = 1234;
                            var searchThreadCount    = 500;
                            var indexThreadCount     = 1;
                            var searchCount          = 10700;
                            var indexCount           = 20;
                            var searchCountPerThread = Convert.ToInt32(searchCount / searchThreadCount);
                            var indexCountPerThread  = Convert.ToInt32(indexCount / indexThreadCount);

                            //spawn a bunch of threads to perform some reading
                            var tasks = new List <Task>();

                            Action <UmbracoExamineSearcher> doSearch = (s) =>
                            {
                                try
                                {
                                    for (var counter = 0; counter < searchCountPerThread; counter++)
                                    {
                                        var r = s.Search(s.CreateSearchCriteria().Id(docId).Compile());
                                        //Debug.WriteLine("searching tId: {0}, tName: {1}, found: {2}", Thread.CurrentThread.ManagedThreadId, Thread.CurrentThread.Name, r.Count());
                                        Thread.Sleep(50);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Debug.WriteLine("ERROR!! {0}", ex);
                                    throw;
                                }
                            };

                            Action <UmbracoContentIndexer> doIndex = (ind) =>
                            {
                                try
                                {
                                    //reindex the same node a bunch of times
                                    for (var i = 0; i < indexCountPerThread; i++)
                                    {
                                        var cloned = new XElement(node);
                                        cloned.Attribute("id").Value = docId.ToString(CultureInfo.InvariantCulture);
                                        //Debug.WriteLine("Indexing {0}", i);
                                        ind.ReIndexNode(cloned, IndexTypes.Content);
                                        Thread.Sleep(100);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Debug.WriteLine("ERROR!! {0}", ex);
                                    throw;
                                }
                            };

                            //searching threads
                            for (var i = 0; i < searchThreadCount; i++)
                            {
                                tasks.Add(Task.Factory.StartNew(() => doSearch(customSearcher), TaskCreationOptions.LongRunning));
                            }
                            //indexing threads
                            for (var i = 0; i < indexThreadCount; i++)
                            {
                                tasks.Add(Task.Factory.StartNew(() => doIndex(customIndexer), TaskCreationOptions.LongRunning));
                            }

                            try
                            {
                                Task.WaitAll(tasks.ToArray());
                            }
                            catch (AggregateException e)
                            {
                                var sb = new StringBuilder();
                                sb.Append(e.Message + ": ");
                                foreach (var v in e.InnerExceptions)
                                {
                                    sb.Append(v.Message + "; ");
                                }
                                Assert.Fail(sb.ToString());
                            }

                            //we need to check if the indexing is complete
                            while (isIndexing)
                            {
                                //wait until indexing is done
                                Thread.Sleep(1000);
                            }

                            //reset the async mode and remove event handler
                            customIndexer.IndexOptimized -= operationComplete;
                            customIndexer.IndexingError  += IndexInitializer.IndexingError;
                            customIndexer.RunAsync        = false;

                            //ensure no duplicates
                            Thread.Sleep(10000); //seems to take a while to get its shit together... this i'm not sure why since the optimization should have def finished (and i've stepped through that code!)

                            //var results = customSearcher.Search(customSearcher.CreateSearchCriteria().Id(id).Compile());
                            //Assert.AreEqual(1, results.Count());
                        }
            }
        }