bsharptree.example.simpleindex.SingleDocumentIndex.AddDocument C# (CSharp) Method

AddDocument() private method

private AddDocument ( Document document, IAnalyzer analyzer ) : void
document Document
analyzer IAnalyzer
return void
        private void AddDocument(Document document, IAnalyzer analyzer)
        {
            if (document.Key == Guid.Empty)
                document.Key = Guid.NewGuid();

            DocumentStorage.Add(document);

            System.Diagnostics.Debug.Assert(document.Value.CanSeek);
            document.Value.Seek(0, SeekOrigin.Begin);
            var termPositions = analyzer.GetTermPositions(document.Value);
            foreach(var termPositionsGroup in termPositions.GroupBy(a=>a.Term))
            {
                var term = new Term(
                    termPositionsGroup.Key,
                    termPositionsGroup.Select(a => new DocumentLocation { Document = document.Key, Span = a.Span }));

                TermStorage.Add(term);
            }
        }