private IEnumerable <ScoredDocument> GetDocs(IList <DocumentScore> scores, IxInfo ix) { var docAddressFileName = Path.Combine(_directory, ix.VersionId + ".da"); IList <BlockInfo> docAdrs; using (var docAddressReader = new DocumentAddressReader( new FileStream(docAddressFileName, FileMode.Open, FileAccess.Read, FileShare.Read, 4096 * 1, FileOptions.SequentialScan))) { var adrs = scores .Select(s => new BlockInfo(s.DocumentId * _blockSize, _blockSize)) .OrderBy(b => b.Position) .ToList(); docAdrs = docAddressReader.Get(adrs).ToList(); } var docFileName = Path.Combine(_directory, ix.VersionId + ".rdoc"); using (var docReader = new DocumentReader( new FileStream(docFileName, FileMode.Open, FileAccess.Read, FileShare.Read, 4096 * 4, FileOptions.SequentialScan), (Compression)ix.Compression)) { var dic = scores.ToDictionary(x => x.DocumentId, y => y.Score); foreach (var doc in docReader.Get(docAdrs)) { var score = dic[doc.Id]; yield return(new ScoredDocument { Document = doc, Score = score }); } } }
public RDocStream(string fileName, string primaryKeyFieldName = null, int skip = 0, int take = int.MaxValue) : base(primaryKeyFieldName) { var versionId = Path.GetFileNameWithoutExtension(fileName); var directory = Path.GetDirectoryName(fileName); var docFileName = Path.Combine(directory, versionId + ".rdoc"); var docAddressFn = Path.Combine(directory, versionId + ".da"); var docHashesFileName = Path.Combine(directory, string.Format("{0}.{1}", versionId, "pk")); var keyIndexFileName = Path.Combine(directory, versionId + ".kix"); var keyIndex = Util.GetKeyIndex(keyIndexFileName); _ix = IxInfo.Load(Path.Combine(directory, versionId + ".ix")); _hashReader = new DocHashReader(docHashesFileName); _addressReader = new DocumentAddressReader(new FileStream(docAddressFn, FileMode.Open, FileAccess.Read)); _documentReader = new DocumentReader( new FileStream(docFileName, FileMode.Open, FileAccess.Read), _ix.Compression, keyIndex); _skip = skip; _take = take; _directory = directory; }