예제 #1
0
 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);
     }
 }
예제 #2
0
        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));
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
        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");
            }
        }