/// <summary> /// 创建hoot引擎 /// </summary> /// <param name="IndexPath">索引地址目录,全路径</param> /// <param name="FileName">文件名(最好无后缀)</param> /// <param name="DocMode">是否文档模式</param> public HootEngine(string IndexPath, string FileName, bool DocMode) { _Path = IndexPath; _FileName = FileName; _docMode = DocMode; if (_Path.EndsWith(Path.DirectorySeparatorChar.ToString()) == false) { _Path += Path.DirectorySeparatorChar; } if (Directory.Exists(IndexPath)) { Directory.CreateDirectory(IndexPath); } _log.Debug("hOOOOOOt Version:" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()); _log.Debug("Starting hOOOOOOt...."); _log.Debug("Storage Folder = " + _Path); if (DocMode) { _docs = new KeyStoreString(_Path, FileName, false); // read deleted _deleted = new BoolIndex(_Path, FileName); _lastDocNum = (int)_docs.Count();//得到文档数,用于编号 } _bitmaps = new BitmapIndex(_Path, _FileName); // read words LoadWords(); }
/// <summary> /// 关闭 /// </summary> public void Shutdown() { lock (_shutdownlock) { if (_index != null) { log.Debug("Shutting down"); } else { return; } _savetimer.Enabled = false; SaveIndex(); SaveLastRecord(); if (_deleted != null) { _deleted.Shutdown(); } if (_index != null) { _index.Shutdown(); } if (_archive != null) { _archive.Shutdown(); } _index = null; _archive = null; _deleted = null; //log.Debug("Shutting down log"); //LogManager.Shutdown(); } }
public void Shutdown() { lock (_lock) { InternalSave(); if (_deleted != null) { _deleted.SaveIndex(); _deleted.Shutdown(); _deleted = null; } if (_bitmaps != null) { _bitmaps.Commit(Global.FreeBitmapMemoryOnSave); _bitmaps.Shutdown(); _bitmaps = null; } if (_docMode) { _docs.Shutdown(); } } }
/// <summary> /// 初始化 /// </summary> /// <param name="filename"></param> /// <param name="maxkeysize"></param> /// <param name="AllowDuplicateKeys"></param> private void Initialize(string filename, byte maxkeysize, bool AllowDuplicateKeys) { _MaxKeySize = RDBDataType <T> .GetByteSize(maxkeysize); _T = RDBDataType <T> .ByteHandler(); _Path = Path.GetDirectoryName(filename); Directory.CreateDirectory(_Path); _FileName = Path.GetFileNameWithoutExtension(filename); string db = Path.Combine(_Path, _FileName + _datExtension); _index = new MGIndex <T>(_Path, _FileName + _idxExtension, _MaxKeySize, AllowDuplicateKeys); if (Global.SaveAsBinaryJSON) { _archive = new StorageFile <T>(db, SF_FORMAT.BSON, false); } else { _archive = new StorageFile <T>(db, SF_FORMAT.JSON, false); } _deleted = new BoolIndex(_Path, _FileName); log.Debug("Current Count = " + RecordCount().ToString("#,0")); CheckIndexState(); //保存服务 log.Debug("Starting save timer"); _savetimer = new System.Timers.Timer(); _savetimer.Elapsed += new System.Timers.ElapsedEventHandler(_savetimer_Elapsed); _savetimer.Interval = Global.SaveIndexToDiskTimerSeconds * 1000; _savetimer.AutoReset = true; _savetimer.Start(); }