예제 #1
0
        //-------------------------------------------------------------------------
        //  Assuming that caller has already set the necessay offset in the binary
        //  stream
        //-------------------------------------------------------------------------
        public void Save(BinaryWriter writer)
        {
            Debug.Assert(DocsNumber > 0);

            IndexConstructor.WriteCount(writer, HC);
            //---------------------------------------------------------------------
            for (int i = 0; i < DocsNumber; i++)
            {
                Entry e = GetEntryAt(i);
                IndexConstructor.WriteCount(writer, e.DocIndex);
                writer.Write(e.TfIdf);
                IndexConstructor.WriteCount(writer, e.Count - 1); // save count minus 1

                foreach (InstanceOffset insoff in e.Offsets)
                {
                    writer.Write(insoff.Offset);
                    writer.Write(insoff.CompoundInfo);
                }
            }
        }
예제 #2
0
        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);
        }