Ejemplo n.º 1
0
        public PersistentIndex(PersistentIndexName name)
        {
            var folder = name.Folder;

            if (!PersistentIndexInfo.Exists(folder, FileNameInfo))
            {
                throw new InvalidOperationException("No index");
            }

            HeaderReader = new PersistentIndexInfo(folder, FileNameInfo);
            Header       = HeaderReader.Read();
            if (Header == null)
            {
                throw new InvalidOperationException("No index");
            }

            VerifyHeader(name);
            var indexType = Header.Type.Split(' ');

            Dictionary      = PersistentDictionaryFactory.Create(indexType[1], folder, FileNameDictionary, Header.MaxTokenSize, indexType[4]);
            PostingLists    = PostingListIOFactory.CreateReader(indexType[3], folder, FileNamePostingLists);
            PosIndex        = PersistentDictionaryFactory.Create(indexType[1], folder, FileNamePosIndex, PosIndexKeySize, indexType[4]);
            PositionsReader = new DeltaVarIntListReader(folder, FileNamePositions);
            Fields          = PersistentMetadataFactory.CreateStorage(indexType[2], folder, FileNameFields);
            this.name       = name;
        }
        protected override IFullTextIndexHeader GetIndexHeader()
        {
            var header = indexInfo.Read();

            var dictionaryType = PersistentDictionaryFactory.GetName(name.DictionaryType);
            var fieldsType     = PersistentMetadataFactory.GetName(name.FieldsType);
            var postingType    = PostingListIOFactory.GetName(name.PostingType);
            var textEncoding   = TextEncodingFactory.GetName(name.TextEncoding);

            if (header == null)
            {
                header = new IndexHeaderData
                {
                    Type           = $"{nameof(PersistentIndex)} {dictionaryType} {fieldsType} {postingType} {textEncoding}",
                    MaxTokenSize   = MaxTokenSize,
                    NextDocumentId = 0,
                    CreatedDate    = DateTime.UtcNow,
                    ModifiedDate   = DateTime.UtcNow,
                };
            }
            else
            {
                var types = header.Type.Split(' ');
                if (types[0] != nameof(PersistentIndex))
                {
                    throw new InvalidOperationException("Index type and name mismatch");
                }

                if (types[1] != dictionaryType)
                {
                    throw new InvalidOperationException("Field type and name mismatch");
                }

                if (types[2] != fieldsType)
                {
                    throw new InvalidOperationException("Field type and name mismatch");
                }

                if (types[3] != postingType)
                {
                    throw new InvalidOperationException("Posting type and name mismatch");
                }

                if (types[4] != textEncoding)
                {
                    throw new InvalidOperationException("Text encoding type and name mismatch");
                }
            }

            return(header);
        }
 protected override void DoStart()
 {
     base.DoStart();
     indexInfo        = new PersistentIndexInfo(Folder, PersistentIndex.FileNameInfo);
     fields           = PersistentMetadataFactory.CreateStorage(name.FieldsType, Folder, PersistentIndex.FileNameFields);
     occurrenceWriter = PostingListIOFactory.CreateWriter(name.PostingType, Folder, PersistentIndex.FileNamePostingLists);
     dictionaryWriter = PersistentDictionaryFactory.CreateWriter(name.DictionaryType, Folder, PersistentIndex.FileNameDictionary, MaxTokenSize, name.TextEncoding);
     dictionaryUpdate = dictionaryWriter.BeginUpdate();
     posIndexWriter   = PersistentDictionaryFactory.CreateWriter(name.DictionaryType, Folder, PersistentIndex.FileNamePosIndex, PersistentIndex.PosIndexKeySize, name.TextEncoding);
     posIndexUpdate   = posIndexWriter.BeginUpdate();
     positionsWriter  = new DeltaVarIntListWriter(Folder, PersistentIndex.FileNamePositions);
     dictUpdates      = 0;
     posUpdates       = 0;
 }