using System.Collections.Generic;
public string description;
public class InvertedIndex
public string[] StopWords = {"the", "a", "is"};
public Dictionary<string, HashSet<Card>> index = new Dictionary<string, HashSet<Card>>();
public List<Card> lookup(string term)
HashSet<Card> lookupValue;
if (index.TryGetValue(term, out lookupValue))
return new List<Card>(lookupValue);
public void addToIndex(Card card)
List<string> tokens = new List<string>();
tokens.AddRange(tokenize(card.title));
tokens.AddRange(tokenize(card.description));
foreach(string token in tokens)
if(index.ContainsKey(token))
HashSet<Card> newSet = new HashSet<Card>();
index.Add(token, newSet);
private List<string> tokenize(string str)
return new List<string>(str.Split(' '));
public static void Main()
""description"": ""this is a description both""
""description"": ""inverted index me both zaddy""
InvertedIndex index = new InvertedIndex();
List<Card> cards = JsonConvert.DeserializeObject<List<Card>>(data);
foreach (Card card in cards) {
List<Card> cardsContainingBoth = index.lookup("both");
foreach(Card match in cardsContainingBoth)
Console.WriteLine($@"Match: {match.title}/{match.description}");