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;
        }
Beispiel #2
0
 protected override IFullTextIndexHeader GetIndexHeader()
 {
     return(indexInfo.Read() ?? new IndexHeaderData
     {
         Type = $"{nameof(PersistentIndex)} {name.FieldsType}",
         MaxTokenSize = MaxTokenSize,
         NextDocumentId = 0,
         CreatedDate = DateTime.UtcNow,
         ModifiedDate = DateTime.UtcNow
     });
 }
        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);
        }
Beispiel #4
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");
            }

            Dictionary   = new PersistentDictionary(folder, FileNameDictionary, FileNamePostingLists);
            PostingLists = new PostingListReader(folder, FileNamePostingLists);
            Fields       = PersistentMetadataFactory.CreateStorage(Header.Type.Split(' ')[1], folder, FileNameFields);
            this.name    = name;
        }