private int GetRecordHandle(int termId) { recordKey.SetIntKey(termId); IEnumerator enumerator = TermId2RecordHandle.SearchForRange(recordKey, recordKey).GetEnumerator(); try { if (!enumerator.MoveNext()) { return(-1); } int offset = ((KeyPair)enumerator.Current)._offset; if (enumerator.MoveNext()) { throw new FormatException("TermIndexAccessor -- Amount of offsets can not exceed 1 in the B-Tree"); } return(offset); } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } }
public override void Close() { base.Close(); // check whether close was issued before the index was actually loaded if (TermId2RecordHandle != null) { TermId2RecordHandle.Close(); TermId2RecordHandle.Dispose(); TermId2RecordHandle = null; } }
protected void LoadOffsetsFromIndex() { foreach (int handle in _indexFile.GetAllFiles(false)) { if (Core.State == CoreState.ShuttingDown) { break; } if (handle != HandleOfHeaderFile) { TermIndexRecord record = GetRecordByHandle(handle); recordKey.SetIntKey(record.HC); TermId2RecordHandle.InsertKey(recordKey, handle); } } if (Core.State == CoreState.ShuttingDown) { TermId2RecordHandle.Clear(); } }
public int AddRecord(int docId, int termId, object instances, int maxTermInDoc) { #region Preconditions if (_indexFile == null) { throw new ApplicationException("Aplication has not initialized Accessor yet"); } #endregion Preconditions int recordHandle = GetRecordHandle(termId); BinaryWriter writer; if (recordHandle <= 0) { writer = _indexFile.AllocFile(out recordHandle); TermId2RecordHandle.InsertKey(recordKey, recordHandle); IndexConstructor.WriteCount(writer, termId); } else { int lastClusterHandle = GetRecordHandle(-termId); int saved = lastClusterHandle; writer = _indexFile.AppendFile(recordHandle, ref lastClusterHandle); if (saved != lastClusterHandle) { if (saved > 0) { TermId2RecordHandle.DeleteKey(recordKey, saved); } TermId2RecordHandle.InsertKey(recordKey, lastClusterHandle); } } ++_savedRecords; using ( writer ) { IndexConstructor.WriteEntry(writer, docId, termId, instances, maxTermInDoc); } return(termId); }