public IEnumerable <string> ReadAllDistinct(Func <TokenSource, bool> filter) { var results = new HashSet <CharArraySegmentKey>(); while (Next()) { if (filter(this)) { var term = new CharArraySegmentKey( Buffer, Size ); if (!results.Contains(term)) { var valueToReturn = ToString(); results.Add(new CharArraySegmentKey( valueToReturn )); yield return(valueToReturn); } } } }
public IEnumerable <Posting> GetPostingsFor(string term) { var key = new CharArraySegmentKey(term); return(!_data.ContainsKey(key) ? Enumerable.Empty <Posting>() : _data[key]); }
internal void Append(CharArraySegmentKey term, int documentId, long position) { if (_data.TryGetValue(term, out var postings)) { if (postings[documentId] == null) { postings[documentId] = new Posting(documentId); } postings[documentId].Positions.Add(position); } else { var posting = new Posting(documentId); posting.Positions.Add(position); postings = new Posting[_maxDocumentId + 1]; postings[documentId] = posting; _data.Add(term.Stabilize(), postings); } _indexedDocuments.Add(documentId); }