Esempio n. 1
0
        public void Events_Ignoring_Node()
        {
            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))
                        {
                            //change the parent id so that they are all ignored
                            var existingCriteria = indexer.IndexerData;
                            indexer.IndexerData = new IndexCriteria(existingCriteria.StandardFields, existingCriteria.UserFields, existingCriteria.IncludeNodeTypes, existingCriteria.ExcludeNodeTypes,
                                                                    999); //change to 999

                            var isIgnored = false;

                            EventHandler <IndexingNodeDataEventArgs> ignoringNode = (s, e) =>
                            {
                                isIgnored = true;
                            };

                            indexer.IgnoringNode += ignoringNode;

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

                            indexer.ReIndexNode(node, IndexTypes.Content);


                            Assert.IsTrue(isIgnored);
                        }
        }
Esempio n. 2
0
        public void Index_Protected_Content_Not_Indexed()
        {
            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))
                        {
                            indexer.RebuildIndex();

                            var protectedQuery = new BooleanQuery();
                            protectedQuery.Add(
                                new BooleanClause(
                                    new TermQuery(new Term(LuceneIndexer.IndexTypeFieldName, IndexTypes.Content)),
                                    BooleanClause.Occur.MUST));

                            protectedQuery.Add(
                                new BooleanClause(
                                    new TermQuery(new Term(LuceneIndexer.IndexNodeIdFieldName, TestContentService.ProtectedNode.ToString())),
                                    BooleanClause.Occur.MUST));

                            var collector = new AllHitsCollector(false, true);
                            var s         = searcher.GetSearcher();
                            s.Search(protectedQuery, collector);

                            Assert.AreEqual(0, collector.Count, "Protected node should not be indexed");
                        }
        }
Esempio n. 3
0
        public void TestSetup()
        {
            UmbracoExamineSearcher.DisableInitializationCheck = true;
            BaseUmbracoIndexer.DisableInitializationCheck     = true;
            //we'll copy over the pdf files first
            var svc  = new TestDataService();
            var path = svc.MapPath("/App_Data/Converting_file_to_PDF.pdf");
            var f    = new FileInfo(path);
            var dir  = f.Directory;

            //ensure the folder is there
            System.IO.Directory.CreateDirectory(dir.FullName);
            var pdfs  = new[] { TestFiles.Converting_file_to_PDF, TestFiles.PDFStandards, TestFiles.SurviorFlipCup, TestFiles.windows_vista };
            var names = new[] { "Converting_file_to_PDF.pdf", "PDFStandards.pdf", "SurviorFlipCup.pdf", "windows_vista.pdf" };

            for (int index = 0; index < pdfs.Length; index++)
            {
                var p = pdfs[index];
                using (var writer = File.Create(Path.Combine(dir.FullName, names[index])))
                {
                    writer.Write(p, 0, p.Length);
                }
            }

            _luceneDir = new RAMDirectory();
            _indexer   = IndexInitializer.GetPdfIndexer(_luceneDir);
            _indexer.RebuildIndex();
            _searcher = IndexInitializer.GetUmbracoSearcher(_luceneDir);
        }
Esempio n. 4
0
        public void Test_Sort_Order_Sorting()
        {
            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, null,
                                                                            new TestDataService()
                    {
                        ContentService = new TestContentService(TestFiles.umbraco_sort)
                    },
                                                                            supportUnpublishedContent: true))
                        using (var searcher = IndexInitializer.GetUmbracoSearcher(writer))
                        {
                            indexer.RebuildIndex();

                            var s = (LuceneSearcher)searcher;
                            var luceneSearcher = s.GetSearcher();
                            var i = (LuceneIndexer)indexer;

                            var numberSortedCriteria = searcher.CreateSearchCriteria()
                                                       .ParentId(1148).And()
                                                       .OrderBy(new SortableField("sortOrder", SortType.Int));
                            var numberSortedResult = searcher.Search(numberSortedCriteria.Compile());

                            var stringSortedCriteria = searcher.CreateSearchCriteria()
                                                       .ParentId(1148).And()
                                                       .OrderBy("sortOrder"); //will default to string
                            var stringSortedResult = searcher.Search(stringSortedCriteria.Compile());

                            Assert.AreEqual(12, numberSortedResult.TotalItemCount);
                            Assert.AreEqual(12, stringSortedResult.TotalItemCount);

                            Assert.IsTrue(IsSortedByNumber(numberSortedResult));
                            Assert.IsFalse(IsSortedByNumber(stringSortedResult));
                        }
        }
Esempio n. 5
0
 public override void TestSetup()
 {
     base.TestSetup();
     _luceneDir = new RAMDirectory();
     _indexer   = IndexInitializer.GetUmbracoIndexer(_luceneDir);
     _indexer.RebuildIndex();
     _searcher = IndexInitializer.GetUmbracoSearcher(_luceneDir);
 }
Esempio n. 6
0
        public void Index_Move_Media_From_Non_Indexable_To_Indexable_ParentID()
        {
            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))
                        {
                            indexer.RebuildIndex();

                            var mediaService = new TestMediaService();

                            //change parent id to 1116
                            var existingCriteria = indexer.IndexerData;
                            indexer.IndexerData = new IndexCriteria(existingCriteria.StandardFields, existingCriteria.UserFields, existingCriteria.IncludeNodeTypes, existingCriteria.ExcludeNodeTypes,
                                                                    1116);

                            //rebuild so it excludes children unless they are under 1116
                            indexer.RebuildIndex();

                            //ensure that node 2112 doesn't exist
                            var results = searcher.Search(searcher.CreateSearchCriteria().Id(2112).Compile());
                            Assert.AreEqual(0, results.TotalItemCount);

                            //get a node from the data repo (this one exists underneath 2222)
                            var node = mediaService.GetLatestMediaByXpath("//*[string-length(@id)>0 and number(@id)>0]")
                                       .Root
                                       .Elements()
                                       .First(x => (int)x.Attribute("id") == 2112);

                            var currPath = (string)node.Attribute("path"); //should be : -1,1111,2222,2112
                            Assert.AreEqual("-1,1111,2222,2112", currPath);

                            //now mimic moving 2112 to 1116
                            //node.SetAttributeValue("path", currPath.Replace("2222", "1116"));
                            node.SetAttributeValue("path", "-1,1116,2112");
                            node.SetAttributeValue("parentID", "1116");

                            //now reindex the node, this should first delete it and then WILL add it because of the parent id constraint
                            indexer.ReIndexNode(node, IndexTypes.Media);

                            //RESET the parent id
                            existingCriteria    = ((IndexCriteria)indexer.IndexerData);
                            indexer.IndexerData = new IndexCriteria(existingCriteria.StandardFields, existingCriteria.UserFields, existingCriteria.IncludeNodeTypes, existingCriteria.ExcludeNodeTypes,
                                                                    null);

                            //now ensure it's deleted
                            var newResults = searcher.Search(searcher.CreateSearchCriteria().Id(2112).Compile());
                            Assert.AreEqual(1, newResults.TotalItemCount);
                        }
        }
Esempio n. 7
0
        public void Index_Delete_Index_Item_Ensure_Heirarchy_Removed()
        {
            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))
                        {
                            indexer.RebuildIndex();

                            //now delete a node that has children

                            indexer.DeleteFromIndex(1140.ToString());
                            //this node had children: 1141 & 1142, let's ensure they are also removed

                            var results = searcher.Search(searcher.CreateSearchCriteria().Id(1141).Compile());
                            Assert.AreEqual(0, results.TotalItemCount);

                            results = searcher.Search(searcher.CreateSearchCriteria().Id(1142).Compile());
                            Assert.AreEqual(0, results.TotalItemCount);
                        }
        }
Esempio n. 8
0
        public void Index_Reindex_Content()
        {
            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, supportUnpublishedContent: true))
                        using (var searcher = IndexInitializer.GetUmbracoSearcher(writer))
                        {
                            indexer.RebuildIndex();

                            var s = (IndexSearcher)searcher.GetSearcher();

                            //first delete all 'Content' (not media). This is done by directly manipulating the index with the Lucene API, not examine!

                            var contentTerm = new Term(LuceneIndexer.IndexTypeFieldName, IndexTypes.Content);
                            writer.DeleteDocuments(contentTerm);
                            writer.Commit();

                            //make sure the content is gone. This is done with lucene APIs, not examine!
                            var collector = new AllHitsCollector(false, true);
                            var query     = new TermQuery(contentTerm);
                            s = (IndexSearcher)searcher.GetSearcher(); //make sure the searcher is up do date.
                            s.Search(query, collector);
                            Assert.AreEqual(0, collector.Count);

                            //call our indexing methods
                            indexer.IndexAll(IndexTypes.Content);

                            collector = new AllHitsCollector(false, true);
                            s         = (IndexSearcher)searcher.GetSearcher(); //make sure the searcher is up do date.
                            s.Search(query, collector);
                            //var ids = new List<string>();
                            //for (var i = 0; i < collector.Count;i++)
                            //{
                            //    ids.Add(s.Doc(collector.GetDocId(i)).GetValues("__NodeId")[0]);
                            //}
                            Assert.AreEqual(21, collector.Count);
                        }
        }
Esempio n. 9
0
        public void Test_Sort_Order_Sorting()
        {
            //var newIndexFolder = new DirectoryInfo(Path.Combine("App_Data\\SearchTests", Guid.NewGuid().ToString()));
            //System.IO.Directory.CreateDirectory(newIndexFolder.FullName);

            using (var luceneDir = new RAMDirectory())
            //using (var luceneDir = new SimpleFSDirectory(newIndexFolder))
            {
                var indexer = IndexInitializer.GetUmbracoIndexer(luceneDir, null,
                                                                 new TestDataService()
                {
                    ContentService = new TestContentService(TestFiles.umbraco_sort)
                });
                indexer.RebuildIndex();
                var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);

                var s = (LuceneSearcher)searcher;
                var luceneSearcher = s.GetSearcher();
                var i = (LuceneIndexer)indexer;

                var numberSortedCriteria = searcher.CreateSearchCriteria()
                                           .ParentId(1148).And()
                                           .OrderBy(new SortableField("sortOrder", SortType.Int));
                var numberSortedResult = searcher.Search(numberSortedCriteria.Compile());

                var stringSortedCriteria = searcher.CreateSearchCriteria()
                                           .ParentId(1148).And()
                                           .OrderBy("sortOrder"); //will default to string
                var stringSortedResult = searcher.Search(stringSortedCriteria.Compile());

                Assert.AreEqual(12, numberSortedResult.TotalItemCount);
                Assert.AreEqual(12, stringSortedResult.TotalItemCount);

                Assert.IsTrue(IsSortedByNumber(numberSortedResult));
                Assert.IsFalse(IsSortedByNumber(stringSortedResult));
            }
        }