public List <int> SearchByToken(string token) { if (PostingsByToken.TryGetValue(token, out TokenPosting value)) { return(value.AllOccurrencesByDocumentId.Keys.ToList()); } else { return(new List <int>());//TokenPosting(token); } }
public OccurrencesPerDocument GetOccurrence(string token, int docId) { if (PostingsByToken.TryGetValue(token, out TokenPosting value)) { if (value.AllOccurrencesByDocumentId.TryGetValue(docId, out OccurrencesPerDocument occurrences)) { return(occurrences); } } return(new OccurrencesPerDocument(docId)); }
private TokenPosting GetOrCreateTokenPostings(string token) { if (PostingsByToken.TryGetValue(token, out TokenPosting tokenPostings)) { return(tokenPostings); } else { var result = new TokenPosting(token); PostingsByToken.Add(token, result); return(result); } }
public string GetWordInfo(string token) { var sb = new StringBuilder(); if (PostingsByToken.TryGetValue(token, out TokenPosting value)) { foreach (var doc in value.AllOccurrencesByDocumentId.Values) { sb.Append("DocId: " + doc.DocumentId); sb.Append(" Positions: " + string.Join(",", doc.Positions)); sb.Append(Environment.NewLine); } return(sb.ToString()); } else { return("This word does not exist"); } }