예제 #1
0
        public override Lucene.Net.Store.Directory CreateDirectory(DirectoryInfo luceneIndexFolder)
        {
            var indexFolder = luceneIndexFolder;
            var tempFolder  = GetLocalStorageDirectory(indexFolder);

            var simpleFsDirectory = new SimpleFSDirectory(tempFolder);

            simpleFsDirectory.SetLockFactory(DefaultLockFactory(tempFolder));
            return(simpleFsDirectory);
        }
예제 #2
0
        public virtual Lucene.Net.Store.Directory CreateDirectory(LuceneIndexer indexer, string luceneIndexFolder)
        {
            var indexFolder = new DirectoryInfo(luceneIndexFolder);
            var tempFolder  = GetLocalStorageDirectory(indexFolder);

            var simpleFsDirectory = new SimpleFSDirectory(tempFolder);

            simpleFsDirectory.SetLockFactory(DirectoryTracker.DefaultLockFactory(tempFolder));
            return(simpleFsDirectory);
        }
예제 #3
0
        public override Lucene.Net.Store.Directory CreateDirectory(DirectoryInfo luceneIndexFolder)
        {
            var master    = luceneIndexFolder;
            var codeGen   = GetLocalStorageDirectory(master);
            var masterDir = new SimpleFSDirectory(master);
            var cacheDir  = new SimpleFSDirectory(codeGen);

            masterDir.SetLockFactory(DefaultLockFactory(master));
            cacheDir.SetLockFactory(DefaultLockFactory(codeGen));
            return(new SyncDirectory(masterDir, cacheDir));
        }
        public Lucene.Net.Store.Directory CreateDirectory(LuceneIndexer indexer, string luceneIndexFolder)
        {
            var indexFolder = new DirectoryInfo(luceneIndexFolder);
            var codeGen     = GetLocalStorageDirectory(indexFolder);
            var master      = new DirectoryInfo(luceneIndexFolder);
            var masterDir   = new SimpleFSDirectory(master);
            var cacheDir    = new SimpleFSDirectory(codeGen);

            masterDir.SetLockFactory(DirectoryTracker.DefaultLockFactory(master));
            cacheDir.SetLockFactory(DirectoryTracker.DefaultLockFactory(codeGen));
            return(new SyncDirectory(masterDir, cacheDir));
        }
예제 #5
0
        public Directory GetDirectory(DirectoryInfo dir, bool throwIfEmpty)
        {
            if (throwIfEmpty)
            {
                Directory d;
                if (!_directories.TryGetValue(dir.FullName, out d))
                {
                    throw new NullReferenceException("No directory was added with path " + dir.FullName + ", maybe an indexer hasn't been initialized?");
                }
                return(d);
            }
            var resolved = _directories.GetOrAdd(dir.FullName, s =>
            {
                var simpleFsDirectory = new SimpleFSDirectory(dir);
                simpleFsDirectory.SetLockFactory(DirectoryTracker.DefaultLockFactory(dir));
                return(simpleFsDirectory);
            });

            return(resolved);
        }
예제 #6
0
        public virtual Directory CreateFileSystemLuceneDirectory(string folderName)
        {
            var combinedPath  = Path.Combine("App_Data/TEMP", "ExamineIndexes", folderName);
            var baseDirectory = AppContext.BaseDirectory;
            var currentPath   = Path.Combine(AppContext.BaseDirectory, combinedPath);

            var dirInfo = new DirectoryInfo(currentPath);

            if (!dirInfo.Exists)
            {
                System.IO.Directory.CreateDirectory(dirInfo.FullName);
            }

            string configuredDirectoryFactory =
                _configuration["Novicell.Examine.LuceneDirectoryFactory"];

            if (!string.IsNullOrWhiteSpace(configuredDirectoryFactory))
            {
                /*  TODO: Check with Mikkel if is better way for TypeFinder */
                var factoryType = ExamineTypeFinder.GetTypeByName(configuredDirectoryFactory);
                if (factoryType == null)
                {
                    throw new NullReferenceException("No directory type found for value: " +
                                                     configuredDirectoryFactory);
                }
                var directoryFactory = (IDirectoryFactory)this.Resolve <IDirectoryFactory>(factoryType);
                return(directoryFactory.CreateDirectory(dirInfo, true));
            }

            //no dir factory, just create a normal fs directory
            var luceneDir = new SimpleFSDirectory(dirInfo);

            //we want to tell examine to use a different fs lock instead of the default NativeFSFileLock which could cause problems if the appdomain
            //terminates and in some rare cases would only allow unlocking of the file if IIS is forcefully terminated. Instead we'll rely on the simplefslock
            //which simply checks the existence of the lock file
            // The full syntax of this is: new NoPrefixSimpleFsLockFactory(dirInfo)
            // however, we are setting the DefaultLockFactory in startup so we'll use that instead since it can be managed globally.
            luceneDir.SetLockFactory(DirectoryFactory.DefaultLockFactory(dirInfo));
            return(luceneDir);
        }
        /// <summary>
        /// Creates a file system based Lucene <see cref="Lucene.Net.Store.Directory"/> with the correct locking guidelines for Umbraco
        /// </summary>
        /// <param name="folderName">
        /// The folder name to store the index (single word, not a fully qualified folder) (i.e. Internal)
        /// </param>
        /// <returns></returns>
        public virtual Lucene.Net.Store.Directory CreateFileSystemLuceneDirectory(string folderName)
        {
            var dirInfo = new DirectoryInfo(Path.Combine(IOHelper.MapPath(SystemDirectories.Data), "TEMP", "ExamineIndexes", folderName));

            if (!dirInfo.Exists)
            {
                System.IO.Directory.CreateDirectory(dirInfo.FullName);
            }

            //check if there's a configured directory factory, if so create it and use that to create the lucene dir
            var configuredDirectoryFactory = ConfigurationManager.AppSettings["Umbraco.Examine.LuceneDirectoryFactory"];

            if (!configuredDirectoryFactory.IsNullOrWhiteSpace())
            {
                //this should be a fully qualified type
                var factoryType = TypeFinder.GetTypeByName(configuredDirectoryFactory);
                if (factoryType == null)
                {
                    throw new NullReferenceException("No directory type found for value: " + configuredDirectoryFactory);
                }
                var directoryFactory = (IDirectoryFactory)Activator.CreateInstance(factoryType);
                return(directoryFactory.CreateDirectory(dirInfo));
            }

            //no dir factory, just create a normal fs directory

            var luceneDir = new SimpleFSDirectory(dirInfo);

            //we want to tell examine to use a different fs lock instead of the default NativeFSFileLock which could cause problems if the appdomain
            //terminates and in some rare cases would only allow unlocking of the file if IIS is forcefully terminated. Instead we'll rely on the simplefslock
            //which simply checks the existence of the lock file
            // The full syntax of this is: new NoPrefixSimpleFsLockFactory(dirInfo)
            // however, we are setting the DefaultLockFactory in startup so we'll use that instead since it can be managed globally.
            luceneDir.SetLockFactory(DirectoryFactory.DefaultLockFactory(dirInfo));
            return(luceneDir);
        }