Пример #1
0
        public bool TryLoad(string path, IndexLoadOptions options)
        {
            try
            {
                _directory = FSDirectory.Open(path);
                _reader = IndexReader.Open(_directory, options.ReadOnly);

                if (options.ForceUnlock && _directory.FileExists(IndexWriter.WRITE_LOCK_NAME))
                {
                    _directory.ClearLock(IndexWriter.WRITE_LOCK_NAME);
                }

                var fields = _reader.GetFieldNames(IndexReader.FieldOption.ALL);
                _numFields = fields.Count;

                CountTerms();

                foreach (var file in _directory.ListAll())
                {
                    try
                    {
                        string fpath = Path.Combine(_directory.Directory.ToString(), file);

                        if (_lastModified == null)
                            _lastModified = File.GetLastWriteTimeUtc(fpath);
                        else
                        {
                            var mod = File.GetLastWriteTimeUtc(fpath);
                            if (mod > _lastModified.Value)
                                _lastModified = mod;
                        }
                    }
                    catch
                    {
                        // ignore
                    }
                }

                _loaded = true;
                return true;
            }
            catch
            {
                _directory = null;
                _reader = null;
                _numFields = 0;
                _numTerms = 0;
                _loaded = false;
                _lastModified = null;
                return false;
            }
        }