public override void AddToIndex(Dictionary <Tuple <string, string>, Term> index) { var task = db.Table <CedictEntry>().ToListAsync(); var entries = task.Result; var indices = new List <Term>(); foreach (var entry in entries) { var key = Tuple.Create(entry.Traditional, entry.Pinyin); Term term; if (index.TryGetValue(key, out term)) { term.CedictEntryId = entry.Id; } else { term = new Term() { Traditional = entry.Traditional, Simplified = entry.Simplified, Pinyin = Pinyin.ConvertToAccents(entry.Pinyin), PinyinNumbered = entry.Pinyin, PinyinNoNumbers = Pinyin.RemoveNumbersAndUnderscore(entry.Pinyin), Length = entry.Traditional.Length, CedictEntryId = entry.Id }; index[key] = term; } } }
public override async Task <IEnumerable <SearchResult> > Search(CancellationToken ct, string query) { var results = new List <SearchResult>(); //try { //var entries = await db.Table<CedictEntry>().Where(p => p.Traditional.StartsWith(query)).ToListAsync(); var entries = await db.QueryAsync <CedictEntry>(ct, "SELECT * FROM CedictEntry WHERE Traditional LIKE ? ESCAPE '\\'", query + "%"); foreach (var q in Pinyin.ToQueryForms(query)) { var newEntries = await db.QueryAsync <CedictEntry>(ct, "SELECT * FROM (SELECT * FROM CedictEntry WHERE PinyinNoNumbers LIKE ? ESCAPE '\\') " + "WHERE Pinyin LIKE ? ESCAPE '\\'", Pinyin.RemoveNumbersAndUnderscore(q) + "%", q + "%"); entries.AddRange(newEntries); } foreach (var s in entries) { var definitions = await db.QueryAsync <CedictDefinition>(ct, "SELECT * FROM CedictDefinition WHERE EntryId = ?", s.Id); //var definitions = await db.Table<CedictDefinition>().Where(d => d.EntryId == s.Id).ToListAsync(); results.Add(new SearchResult() { Traditional = s.Traditional, Simplified = s.Simplified, Pinyin = Pinyin.ConvertToAccents(s.Pinyin), PinyinNumbered = s.Pinyin, Definitions = new List <List <string> >() { new List <string>(from d in definitions select d.Definition) } }); } } return(results); }