Пример #1
0
        public IList <Document> ReadDocuments(IList <int> documentIds)
        {
            var addresses = new List <BlockInfo>(documentIds.Count);

            foreach (var id in documentIds)
            {
                addresses.Add(new BlockInfo(id * _blockSize, _blockSize));
            }

            var docAddresses = _addressReader.Read(addresses);
            var index        = 0;
            var documents    = new List <Document>(documentIds.Count);

            _stream.Seek(Version.KeyIndexOffset, SeekOrigin.Begin);
            var keyIndex = TableSerializer.ReadKeyIndex(_stream, Version.KeyIndexSize);

            using (var documentReader = new DocumentReader(
                       _stream, Version.Compression, keyIndex, leaveOpen: true))

                foreach (var document in documentReader.Read(docAddresses))
                {
                    document.Id = documentIds[index++];
                    documents.Add(document);
                }

            return(documents);
        }
Пример #2
0
        private IEnumerable <Document> StreamDocuments()
        {
            var skipped = 0;
            var took    = 0;

            for (int docId = 0; docId < _ix.DocumentCount; docId++)
            {
                var hash = _hashReader.Read(docId);

                var address = _addressReader.Read(new[]
                {
                    new BlockInfo(docId * BlockSerializer.SizeOfBlock(), BlockSerializer.SizeOfBlock())
                }).First();

                var document = _documentReader.Read(new List <BlockInfo> {
                    address
                }).First();

                if (!hash.IsObsolete)
                {
                    if (skipped == _skip && took < _take)
                    {
                        yield return(document);

                        took++;
                    }
                    else if (skipped < _skip)
                    {
                        skipped++;
                    }
                    else if (took == _take)
                    {
                        break;
                    }
                }
            }
        }