public void Initialize(String directoryProviderName, IDictionary <string, string> properties, ISearchFactoryImplementor searchFactory)
        {
            this.properties            = properties;
            this.directoryProviderName = directoryProviderName;

            // source guessing
            source = DirectoryProviderHelper.GetSourceDirectory(Environment.SourceBase, Environment.Source, directoryProviderName, (IDictionary)properties);
            if (source == null)
            {
                throw new ArgumentException("FSSlaveDirectoryProvider requires a viable source directory");
            }

            if (!File.Exists(Path.Combine(source, "current1")) && !File.Exists(Path.Combine(source, "current2")))
            {
                log.Warn("No current marker in source directory: " + source);
            }

            log.Debug("Source directory: " + source);
            indexDir = DirectoryProviderHelper.DetermineIndexDir(directoryProviderName, (IDictionary)properties);
            log.Debug("Index directory: " + indexDir.FullName);
            try
            {
                bool create = !indexDir.Exists;
                if (create)
                {
                    log.DebugFormat("Index directory not found, creating '{0}'", indexDir.FullName);
                    indexDir.Create();
                }
                indexName = indexDir.FullName;
            }
            catch (IOException e)
            {
                throw new HibernateException("Unable to initialize index: " + directoryProviderName, e);
            }
        }
        public void Initialize(String directoryProviderName, IDictionary <string, string> properties, ISearchFactoryImplementor searchFactory)
        {
            DirectoryInfo indexDir = DirectoryProviderHelper.DetermineIndexDir(directoryProviderName, (IDictionary)properties);

            try
            {
                bool create = !IndexReader.IndexExists(indexDir.FullName);
                indexName = indexDir.FullName;
                directory = FSDirectory.GetDirectory(indexName, create);

                if (create)
                {
                    IndexWriter iw = new IndexWriter(directory,
                                                     new StandardAnalyzer(),
                                                     create,
                                                     new KeepOnlyLastCommitDeletionPolicy(),
                                                     IndexWriter.MaxFieldLength.UNLIMITED);
                    iw.Close();
                }

                //searchFactory.RegisterDirectoryProviderForLocks(this);
            }
            catch (IOException e)
            {
                throw new HibernateException("Unable to initialize index: " + directoryProviderName, e);
            }
        }
        public override void Initialize(String directoryProviderName, IDictionary <string, string> properties, ISearchFactoryImplementor searchFactory)
        {
            DirectoryInfo indexDir = DirectoryProviderHelper.DetermineIndexDir(directoryProviderName, (IDictionary)properties);

            indexName = indexDir.FullName;

            var directory = InitializeIndex(indexDir, directoryProviderName);

            this.directory = directory;
        }
        public void CreateViaRoot()
        {
            var properties = new Dictionary <string, string>();

            properties["sourceBase"] = root;

            DirectoryProviderHelper.GetSourceDirectory("sourceBase", "relativeBase", "Test", properties);

            DirectoryInfo info = new DirectoryInfo(root + "/Test");

            Assert.IsTrue(info.Exists);
        }
        public void CreateViaParent()
        {
            var properties = new Dictionary <string, string>();

            properties["indexBase"] = "../Wilma";
            properties["indexName"] = "fakeIndex";

            DirectoryInfo info = DirectoryProviderHelper.DetermineIndexDir(null, properties);

            // get process execution path
            DirectoryInfo targetParentDir = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);

            // check if a directory info object was returned and "Wilma" folder was created into parent folder of execution process
            Assert.IsTrue(targetParentDir.Parent.GetDirectories().Any(d => d.Name.Equals(info.Parent.Name)));
        }
        public void Initialize(string directoryProviderName, IDictionary <string, string> properties, ISearchFactoryImplementor searchFactory)
        {
            this.properties            = properties;
            this.directoryProviderName = directoryProviderName;

            // source guessing
            source = DirectoryProviderHelper.GetSourceDirectory(Environment.SourceBase, Environment.Source, directoryProviderName, (IDictionary)properties);
            if (source == null)
            {
                throw new ArgumentException("FSMasterDirectoryProvider requires a viable source directory");
            }

            log.Debug("Source directory: " + source);
            indexDir = DirectoryProviderHelper.DetermineIndexDir(directoryProviderName, (IDictionary)properties);
            log.Debug("Index directory: " + indexDir);
            try
            {
                // NB Do we need to do this since we are passing the create flag to Lucene?
                bool create = !IndexReader.IndexExists(indexDir.FullName);
                if (create)
                {
                    log.DebugFormat("Index directory not found, creating '{0}'", indexDir.FullName);
                    indexDir.Create();
                }

                indexName = indexDir.FullName;
                directory = FSDirectory.GetDirectory(indexName, create);

                if (create)
                {
                    indexName = indexDir.FullName;
                    IndexWriter iw = new IndexWriter(directory, new StandardAnalyzer(), create);
                    iw.Close();
                }
            }
            catch (IOException e)
            {
                throw new HibernateException("Unable to initialize index: " + directoryProviderName, e);
            }

            this.searchFactory = searchFactory;
        }
예제 #7
0
        public override void Initialize(string directoryProviderName, IDictionary <string, string> properties, ISearchFactoryImplementor searchFactory)
        {
            this.properties            = properties;
            this.directoryProviderName = directoryProviderName;

            // source guessing
            source = DirectoryProviderHelper.GetSourceDirectory(Environment.SourceBase, Environment.Source, directoryProviderName, (IDictionary)properties);
            if (source == null)
            {
                throw new ArgumentException("FSMasterDirectoryProvider requires a viable source directory");
            }

            log.Debug("Source directory: " + source);
            indexDir = DirectoryProviderHelper.DetermineIndexDir(directoryProviderName, (IDictionary)properties);
            log.Debug("Index directory: " + indexDir);

            this.indexName = directoryProviderName;

            this.directory = InitializeIndex(indexDir, indexDir.FullName);

            this.searchFactory = searchFactory;
        }
예제 #8
0
        public void Initialize(String directoryProviderName, IDictionary <string, string> properties, ISearchFactoryImplementor searchFactory)
        {
            DirectoryInfo indexDir = DirectoryProviderHelper.DetermineIndexDir(directoryProviderName, (IDictionary)properties);

            try
            {
                indexName = indexDir.FullName;
                directory = FSDirectory.Open(indexDir.FullName);

                if (DirectoryReader.IndexExists(directory))
                {
                    return;
                }

                var config = new IndexWriterConfig(LuceneVersion.LUCENE_48, new StandardAnalyzer(LuceneVersion.LUCENE_48));
                var writer = new IndexWriter(directory, config);
                writer.Dispose();
            }
            catch (IOException e)
            {
                throw new HibernateException("Unable to initialize index: " + directoryProviderName, e);
            }
        }