Esempio n. 1
0
        public static UmbracoContentIndexer GetUmbracoIndexer(
            Lucene.Net.Store.Directory luceneDir,
            Analyzer analyzer        = null,
            IDataService dataService = null)
        {
            if (dataService == null)
            {
                dataService = new TestDataService();
            }

            if (analyzer == null)
            {
                analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29);
            }

            var indexSet      = new IndexSet();
            var indexCriteria = indexSet.ToIndexCriteria(dataService, UmbracoContentIndexer.IndexFieldPolicies);

            var i = new UmbracoContentIndexer(indexCriteria,
                                              luceneDir,         //custom lucene directory
                                              dataService,
                                              analyzer,
                                              false);

            //i.IndexSecondsInterval = 1;

            i.IndexingError += IndexingError;

            return(i);
        }
 /// <summary>
 /// Creates an IIndexCriteria object based on the indexSet passed in and our DataService
 /// </summary>
 /// <param name="indexSet"></param>
 /// <returns></returns>
 /// <remarks>
 /// If we cannot initialize we will pass back empty indexer data since we cannot read from the database
 /// </remarks>
 protected override IIndexCriteria GetIndexerData(IndexSet indexSet)
 {
     if (CanInitialize())
     {
         return(indexSet.ToIndexCriteria(DataService, IndexFieldPolicies));
     }
     else
     {
         return(base.GetIndexerData(indexSet));
     }
 }
        /// <summary>
        /// Ensures that the'_searchEmail' is added to the user fields so that it is indexed - without having to modify the config
        /// </summary>
        /// <param name="indexSet"></param>
        /// <returns></returns>
        protected override IIndexCriteria GetIndexerData(IndexSet indexSet)
        {
            if (CanInitialize())
            {
                //Add a custom _searchEmail to the index criteria no matter what is in config
                var field = new IndexField {
                    Name = "_searchEmail"
                };
                StaticField policy;
                if (IndexFieldPolicies.TryGetValue("_searchEmail", out policy))
                {
                    field.Type          = policy.Type;
                    field.EnableSorting = policy.EnableSorting;
                }

                return(indexSet.ToIndexCriteria(DataService, IndexFieldPolicies,
                                                //add additional explicit fields
                                                new [] { field }));
            }
            else
            {
                return(base.GetIndexerData(indexSet));
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Creates an IIndexCriteria object based on the indexSet passed in and our DataService
 /// </summary>
 /// <param name="indexSet">
 /// The index Set.
 /// </param>
 /// <remarks>
 /// If we cannot initialize we will pass back empty indexer data since we cannot read from the database
 /// </remarks>
 /// <returns>
 /// The <see cref="IIndexCriteria"/>.
 /// </returns>
 protected override IIndexCriteria GetIndexerData(IndexSet indexSet)
 {
     return(indexSet.ToIndexCriteria(DataService.OrderDataService.GetIndexFieldNames(), IndexFieldPolicies));
 }
Esempio n. 5
0
 /// <summary>
 /// Creates an IIndexCriteria object based on the indexSet passed in and our DataService
 /// </summary>
 /// <param name="indexSet">
 /// The index Set.
 /// </param>
 /// <remarks>
 /// If we cannot initialize we will pass back empty indexer data since we cannot read from the database
 /// </remarks>
 /// <returns>
 /// The <see cref="IIndexCriteria"/>.
 /// </returns>
 protected override IIndexCriteria GetIndexerData(IndexSet indexSet)
 {
     return indexSet.ToIndexCriteria(DataService.InvoiceDataService.GetIndexFieldNames(), IndexFieldPolicies);
 }
        public static UmbracoContentIndexer GetUmbracoIndexer(
            Directory luceneDir,
            Analyzer analyzer                = null,
            IDataService dataService         = null,
            IContentService contentService   = null,
            IMediaService mediaService       = null,
            IDataTypeService dataTypeService = null,
            IMemberService memberService     = null,
            IUserService userService         = null)
        {
            if (dataService == null)
            {
                dataService = new TestDataService();
            }
            if (contentService == null)
            {
                contentService = Mock.Of <IContentService>();
            }
            if (userService == null)
            {
                userService = Mock.Of <IUserService>(x => x.GetProfileById(It.IsAny <int>()) == Mock.Of <IProfile>(p => p.Id == (object)0 && p.Name == "admin"));
            }
            if (mediaService == null)
            {
                long totalRecs;

                var allRecs = dataService.MediaService.GetLatestMediaByXpath("//node")
                              .Root
                              .Elements()
                              .Select(x => Mock.Of <IMedia>(
                                          m =>
                                          m.Id == (int)x.Attribute("id") &&
                                          m.ParentId == (int)x.Attribute("parentID") &&
                                          m.Level == (int)x.Attribute("level") &&
                                          m.CreatorId == 0 &&
                                          m.SortOrder == (int)x.Attribute("sortOrder") &&
                                          m.CreateDate == (DateTime)x.Attribute("createDate") &&
                                          m.UpdateDate == (DateTime)x.Attribute("updateDate") &&
                                          m.Name == (string)x.Attribute("nodeName") &&
                                          m.Path == (string)x.Attribute("path") &&
                                          m.Properties == new PropertyCollection() &&
                                          m.ContentType == Mock.Of <IMediaType>(mt =>
                                                                                mt.Alias == (string)x.Attribute("nodeTypeAlias") &&
                                                                                mt.Id == (int)x.Attribute("nodeType"))))
                              .ToArray();


                mediaService = Mock.Of <IMediaService>(
                    x => x.GetPagedDescendants(
                        It.IsAny <int>(), It.IsAny <long>(), It.IsAny <int>(), out totalRecs, It.IsAny <string>(), It.IsAny <Direction>(), It.IsAny <string>())
                    ==
                    allRecs);
            }
            if (dataTypeService == null)
            {
                dataTypeService = Mock.Of <IDataTypeService>();
            }

            if (memberService == null)
            {
                memberService = Mock.Of <IMemberService>();
            }

            if (analyzer == null)
            {
                analyzer = new StandardAnalyzer(Version.LUCENE_29);
            }

            var indexSet      = new IndexSet();
            var indexCriteria = indexSet.ToIndexCriteria(dataService, UmbracoContentIndexer.IndexFieldPolicies);

            var i = new UmbracoContentIndexer(indexCriteria,
                                              luceneDir,         //custom lucene directory
                                              dataService,
                                              contentService,
                                              mediaService,
                                              dataTypeService,
                                              userService,
                                              analyzer,
                                              false);

            //i.IndexSecondsInterval = 1;

            i.IndexingError += IndexingError;

            return(i);
        }
Esempio n. 7
0
        public static UmbracoContentIndexer GetUmbracoIndexer(
            IndexWriter writer,
            Analyzer analyzer                      = null,
            IDataService dataService               = null,
            IContentService contentService         = null,
            IMediaService mediaService             = null,
            IDataTypeService dataTypeService       = null,
            IMemberService memberService           = null,
            IUserService userService               = null,
            IContentTypeService contentTypeService = null,
            bool supportUnpublishedContent         = false)
        {
            if (dataService == null)
            {
                dataService = new TestDataService();
            }
            if (contentService == null)
            {
                long longTotalRecs;
                int  intTotalRecs;

                var allRecs = dataService.ContentService.GetLatestContentByXPath("//*[@isDoc]")
                              .Root
                              .Elements()
                              .Select(x => Mock.Of <IContent>(
                                          m =>
                                          m.Id == (int)x.Attribute("id") &&
                                          m.ParentId == (int)x.Attribute("parentID") &&
                                          m.Level == (int)x.Attribute("level") &&
                                          m.CreatorId == 0 &&
                                          m.SortOrder == (int)x.Attribute("sortOrder") &&
                                          m.CreateDate == (DateTime)x.Attribute("createDate") &&
                                          m.UpdateDate == (DateTime)x.Attribute("updateDate") &&
                                          m.Name == (string)x.Attribute("nodeName") &&
                                          m.Path == (string)x.Attribute("path") &&
                                          m.Properties == new PropertyCollection() &&
                                          m.ContentType == Mock.Of <IContentType>(mt =>
                                                                                  mt.Alias == x.Name.LocalName &&
                                                                                  mt.Id == (int)x.Attribute("nodeType") &&
                                                                                  mt.Icon == "test")))
                              .ToArray();


                contentService = Mock.Of <IContentService>(
                    x => x.GetPagedDescendants(
                        It.IsAny <int>(), It.IsAny <long>(), It.IsAny <int>(), out longTotalRecs, It.IsAny <string>(), It.IsAny <Direction>(), It.IsAny <bool>(), It.IsAny <string>())
                    ==
                    allRecs &&
                    x.GetPagedDescendants(
                        It.IsAny <int>(), It.IsAny <long>(), It.IsAny <int>(), out longTotalRecs, It.IsAny <string>(), It.IsAny <Direction>(), It.IsAny <string>())
                    ==
                    allRecs &&
                    x.GetPagedDescendants(
                        It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), out intTotalRecs, It.IsAny <string>(), It.IsAny <Direction>(), It.IsAny <string>())
                    ==
                    allRecs &&
                    x.GetPagedDescendants(
                        It.IsAny <int>(), It.IsAny <long>(), It.IsAny <int>(), out longTotalRecs, It.IsAny <string>(), It.IsAny <Direction>(), It.IsAny <bool>(), It.IsAny <IQuery <IContent> >())
                    ==
                    allRecs);
            }
            if (userService == null)
            {
                userService = Mock.Of <IUserService>(x => x.GetProfileById(It.IsAny <int>()) == Mock.Of <IProfile>(p => p.Id == 0 && p.Name == "admin"));
            }
            if (mediaService == null)
            {
                long longTotalRecs;
                int  intTotalRecs;

                var mediaXml = dataService.MediaService.GetLatestMediaByXpath("//node");
                var allRecs  = mediaXml
                               .Root
                               .Elements()
                               .Select(x => Mock.Of <IMedia>(
                                           m =>
                                           m.Id == (int)x.Attribute("id") &&
                                           m.ParentId == (int)x.Attribute("parentID") &&
                                           m.Level == (int)x.Attribute("level") &&
                                           m.CreatorId == 0 &&
                                           m.SortOrder == (int)x.Attribute("sortOrder") &&
                                           m.CreateDate == (DateTime)x.Attribute("createDate") &&
                                           m.UpdateDate == (DateTime)x.Attribute("updateDate") &&
                                           m.Name == (string)x.Attribute("nodeName") &&
                                           m.Path == (string)x.Attribute("path") &&
                                           m.Properties == new PropertyCollection() &&
                                           m.ContentType == Mock.Of <IMediaType>(mt =>
                                                                                 mt.Alias == (string)x.Attribute("nodeTypeAlias") &&
                                                                                 mt.Id == (int)x.Attribute("nodeType"))))
                               .ToArray();

                // MOCK!
                var mediaServiceMock = new Mock <IMediaService>();

                mediaServiceMock
                .Setup(x => x.GetPagedDescendants(
                           It.IsAny <int>(), It.IsAny <long>(), It.IsAny <int>(), out longTotalRecs, It.IsAny <string>(), It.IsAny <Direction>(), It.IsAny <bool>(), It.IsAny <string>())
                       ).Returns(() => allRecs);

                mediaServiceMock
                .Setup(x => x.GetPagedDescendants(
                           It.IsAny <int>(), It.IsAny <long>(), It.IsAny <int>(), out longTotalRecs, It.IsAny <string>(), It.IsAny <Direction>(), It.IsAny <string>())
                       ).Returns(() => allRecs);

                mediaServiceMock
                .Setup(x => x.GetPagedDescendants(
                           It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), out intTotalRecs, It.IsAny <string>(), It.IsAny <Direction>(), It.IsAny <string>())
                       ).Returns(() => allRecs);

                mediaServiceMock.Setup(service => service.GetPagedXmlEntries(It.IsAny <string>(), It.IsAny <long>(), It.IsAny <int>(), out longTotalRecs))
                .Returns(() => allRecs.Select(x => x.ToXml()));

                mediaService = mediaServiceMock.Object;
            }
            if (dataTypeService == null)
            {
                dataTypeService = Mock.Of <IDataTypeService>();
            }

            if (memberService == null)
            {
                memberService = Mock.Of <IMemberService>();
            }

            if (contentTypeService == null)
            {
                var contentTypeServiceMock = new Mock <IContentTypeService>();
                contentTypeServiceMock.Setup(x => x.GetAllMediaTypes())
                .Returns(new List <IMediaType>()
                {
                    new MediaType(-1)
                    {
                        Alias = "Folder", Name = "Folder", Id = 1031, Icon = "icon-folder"
                    },
                    new MediaType(-1)
                    {
                        Alias = "Image", Name = "Image", Id = 1032, Icon = "icon-picture"
                    }
                });
                contentTypeService = contentTypeServiceMock.Object;
            }

            if (analyzer == null)
            {
                analyzer = new StandardAnalyzer(Version.LUCENE_29);
            }

            var indexSet      = new IndexSet();
            var indexCriteria = indexSet.ToIndexCriteria(dataService, UmbracoContentIndexer.IndexFieldPolicies);

            var i = new UmbracoContentIndexer(indexCriteria,
                                              writer,
                                              dataService,
                                              contentService,
                                              mediaService,
                                              dataTypeService,
                                              userService,
                                              contentTypeService,
                                              false)
            {
                SupportUnpublishedContent = supportUnpublishedContent
            };

            //i.IndexSecondsInterval = 1;

            i.IndexingError += IndexingError;

            return(i);
        }
 /// <summary>
 /// Convert the indexset to indexerdata.
 /// This detects if there are no user/system fields specified and if not, uses the data service to look them
 /// up and update the in memory IndexSet.
 /// </summary>
 /// <param name="set"></param>
 /// <param name="svc"></param>
 /// <returns></returns>
 public static IIndexCriteria ToIndexCriteria(this IndexSet set, IDataService svc)
 {
     return(set.ToIndexCriteria(svc, Enumerable.Empty <StaticField>()));
 }
 /// <summary>
 /// Creates an IIndexCriteria object based on the indexSet passed in and our DataService
 /// </summary>
 /// <param name="indexSet"></param>
 /// <returns></returns>
 protected override IIndexCriteria GetIndexerData(IndexSet indexSet)
 {
     return(indexSet.ToIndexCriteria(DataService));
 }
 /// <summary>
 /// Convert the indexset to indexerdata.
 /// This detects if there are no user/system fields specified and if not, uses the data service to look them
 /// up and update the in memory IndexSet.
 /// </summary>
 /// <param name="set"></param>
 /// <param name="svc"></param>
 /// <returns></returns>
 public static IIndexCriteria ToIndexCriteria(this IndexSet set, IDataService svc)
 {
     return(set.ToIndexCriteria(svc, new StaticFieldCollection()));
 }