コード例 #1
0
        public static UmbracoContentIndex GetUmbracoIndexer(
            IProfilingLogger profilingLogger,
            Directory luceneDir,
            Analyzer analyzer = null,
            ILocalizationService languageService = null,
            IContentValueSetValidator validator  = null)
        {
            if (languageService == null)
            {
                languageService = GetMockLocalizationService();
            }

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

            if (validator == null)
            {
                validator = new ContentValueSetValidator(true);
            }

            var i = new UmbracoContentIndex(
                "testIndexer",
                luceneDir,
                new UmbracoFieldDefinitionCollection(),
                analyzer,
                profilingLogger,
                languageService,
                validator);

            i.IndexingError += IndexingError;

            return(i);
        }
コード例 #2
0
        public override IEnumerable <IIndex> Create()
        {
            var index = new UmbracoContentIndex("ArticleIndex",
                                                CreateFileSystemLuceneDirectory("ArticleIndex"),
                                                new UmbracoFieldDefinitionCollection(),
                                                new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30),
                                                _profilingLogger,
                                                _localizationService,
                                                new ContentValueSetValidator(true, false, _publicAccessService, includeItemTypes: new string[] { "article" }));

            return(new[] { index });
        }
コード例 #3
0
        private IIndex CreateExternalIndex()
        {
            var index = new UmbracoContentIndex(
                Constants.UmbracoIndexes.ExternalIndexName,
                CreateFileSystemLuceneDirectory(Constants.UmbracoIndexes.ExternalIndexPath),
                new UmbracoFieldDefinitionCollection(),
                new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30),
                ProfilingLogger,
                LanguageService,
                GetPublishedContentValueSetValidator());

            return(index);
        }
コード例 #4
0
        private IIndex CreateInternalIndex()
        {
            var index = new UmbracoContentIndex(
                Constants.UmbracoIndexes.InternalIndexName,
                CreateFileSystemLuceneDirectory(Constants.UmbracoIndexes.InternalIndexPath),
                new UmbracoFieldDefinitionCollection(),
                new CultureInvariantWhitespaceAnalyzer(),
                ProfilingLogger,
                LanguageService,
                GetContentValueSetValidator());

            return(index);
        }
コード例 #5
0
        public override IEnumerable <IIndex> Create()
        {
            //define the new index
            var index = new UmbracoContentIndex("ProductIndex",
                                                CreateFileSystemLuceneDirectory("ProductIndex"),
                                                new UmbracoFieldDefinitionCollection(),
                                                new StandardAnalyzer(Version.LUCENE_30),
                                                _profilingLogger,
                                                _localizationService,
                                                // We can use the ContentValueSetValidator to set up rules for the content we
                                                // want to have indexed. In our case we want published, non-protected nodes of the type "product".
                                                new ContentValueSetValidator(true, false, _publicAccessService, includeItemTypes: new string[] { "product" }));

            return(new[] { index });
        }
コード例 #6
0
        public UmbracoContentIndex GetUmbracoIndexer(
            IHostingEnvironment hostingEnvironment,
            IRuntimeState runtimeState,
            Directory luceneDir,
            Analyzer analyzer = null,
            ILocalizationService languageService = null,
            IContentValueSetValidator validator  = null)
        {
            if (languageService == null)
            {
                languageService = GetMockLocalizationService();
            }

            if (analyzer == null)
            {
                analyzer = new StandardAnalyzer(LuceneInfo.CurrentVersion);
            }

            if (validator == null)
            {
                validator = new ContentValueSetValidator(true);
            }

            var options = GetOptions(
                "testIndexer",
                new LuceneDirectoryIndexOptions
            {
                Analyzer         = analyzer,
                Validator        = validator,
                DirectoryFactory = new GenericDirectoryFactory(s => luceneDir),
                FieldDefinitions = new UmbracoFieldDefinitionCollection()
            });

            var i = new UmbracoContentIndex(
                _loggerFactory,
                "testIndexer",
                options,
                hostingEnvironment,
                runtimeState,
                languageService);

            i.IndexingError          += IndexingError;
            i.IndexOperationComplete += I_IndexOperationComplete;

            return(i);
        }
コード例 #7
0
        private IIndex CreateWebsiteResourceIndex(WebsiteNode site)
        {
            var fields = new FieldDefinitionCollection();

            fields.AddOrUpdate(new FieldDefinition("lat", FieldDefinitionTypes.Double));
            fields.AddOrUpdate(new FieldDefinition("lon", FieldDefinitionTypes.Double));

            var index = new UmbracoContentIndex(
                Constants.Examine.ResourceIndexName + "-" + site.WebsiteName,
                this.CreateFileSystemLuceneDirectory(Constants.Examine.ResourceDirectory + "-" + site.WebsiteName),
                fields,
                new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30),
                this.ProfilingLogger,
                this.LanguageService,
                this.GetPublishedContentValueSetValidator(site.WebsiteId));



            return(index);
        }
コード例 #8
0
        /// <summary>
        /// Used to create and manage a testable index
        /// </summary>
        /// <param name="publishedValuesOnly"></param>
        /// <param name="index"></param>
        /// <param name="contentRebuilder"></param>
        /// <param name="contentValueSetBuilder"></param>
        /// <param name="parentId"></param>
        /// <returns></returns>
        protected IDisposable GetSynchronousContentIndex(
            bool publishedValuesOnly,
            out UmbracoContentIndex index,
            out ContentIndexPopulator contentRebuilder,
            out ContentValueSetBuilder contentValueSetBuilder,
            int?parentId = null,
            IContentService contentService = null)
        {
            contentValueSetBuilder = IndexInitializer.GetContentValueSetBuilder(publishedValuesOnly);

            ISqlContext             sqlContext = Mock.Of <ISqlContext>(x => x.Query <IContent>() == Mock.Of <IQuery <IContent> >());
            IUmbracoDatabaseFactory dbFactory  = Mock.Of <IUmbracoDatabaseFactory>(x => x.SqlContext == sqlContext);

            if (contentService == null)
            {
                contentService = IndexInitializer.GetMockContentService();
            }

            contentRebuilder = IndexInitializer.GetContentIndexRebuilder(contentService, publishedValuesOnly, dbFactory);

            var luceneDir = new RandomIdRAMDirectory();

            ContentValueSetValidator validator;

            // if only published values then we'll change the validator for tests to
            // ensure we don't support protected nodes and that we
            // mock the public access service for the special protected node.
            if (publishedValuesOnly)
            {
                var publicAccessServiceMock = new Mock <IPublicAccessService>();
                publicAccessServiceMock.Setup(x => x.IsProtected(It.IsAny <string>()))
                .Returns((string path) =>
                {
                    if (path.EndsWith("," + ExamineDemoDataContentService.ProtectedNode))
                    {
                        return(Attempt <PublicAccessEntry> .Succeed());
                    }
                    return(Attempt <PublicAccessEntry> .Fail());
                });

                var scopeProviderMock = new Mock <IScopeProvider>();
                scopeProviderMock.Setup(x => x.CreateScope(
                                            It.IsAny <IsolationLevel>(),
                                            It.IsAny <RepositoryCacheMode>(),
                                            It.IsAny <IEventDispatcher>(),
                                            It.IsAny <IScopedNotificationPublisher>(),
                                            It.IsAny <bool?>(),
                                            It.IsAny <bool>(),
                                            It.IsAny <bool>()))
                .Returns(Mock.Of <IScope>);

                validator = new ContentValueSetValidator(
                    publishedValuesOnly,
                    false,
                    publicAccessServiceMock.Object,
                    scopeProviderMock.Object,
                    parentId);
            }
            else
            {
                validator = new ContentValueSetValidator(publishedValuesOnly, parentId);
            }

            index = IndexInitializer.GetUmbracoIndexer(
                HostingEnvironment,
                RunningRuntimeState,
                luceneDir,
                validator: validator);

            IDisposable syncMode = index.WithThreadingMode(IndexThreadingMode.Synchronous);

            return(new DisposableWrapper(syncMode, index, luceneDir));
        }