public IndexHeaderData Read() { var buffer = new byte[1024]; int read = persistentStorage.Read(0, buffer, 0, buffer.Length); if (read == 0) { return(null); } using (var reader = new StringReader(System.Text.Encoding.UTF8.GetString(buffer, 0, read))) { var result = new IndexHeaderData { Type = reader.ReadLine(), MaxTokenSize = int.Parse(reader.ReadLine()), NextDocumentId = ulong.Parse(reader.ReadLine()), CreatedDate = DateTime.Parse(reader.ReadLine()), ModifiedDate = DateTime.Parse(reader.ReadLine()), }; while (true) { var line = reader.ReadLine(); if (line == null) { break; } result.Settings.Add(line); } return(result); } }
public InMemoryIndex() { Header = new IndexHeaderData { Type = nameof(InMemoryIndex), 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); }