Beispiel #1
0
        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;
                }
            }
        }
Beispiel #2
0
        public override void AddToIndex(Dictionary <Tuple <string, string>, Term> index)
        {
            var entries = db.QueryAsync <MoedictHeteronymLookupForm>(
                "SELECT h.Id AS Id, Headword AS Traditional, Pinyin, PinyinNumbered "
                + "FROM MoedictHeteronym h LEFT JOIN MoedictEntry e ON h.EntryId = e.Id").Result;

            foreach (var entry in entries)
            {
                var  key = Tuple.Create(entry.Traditional, entry.PinyinNumbered);
                Term term;
                if (index.TryGetValue(key, out term))
                {
                    term.MoedictHeteronymId = entry.Id;
                }
                else
                {
                    term = new Term()
                    {
                        Traditional        = entry.Traditional,
                        Simplified         = TradToSimp.Convert(entry.Traditional).FirstOrDefault(),
                        Pinyin             = entry.Pinyin,
                        PinyinNumbered     = entry.PinyinNumbered,
                        PinyinNoNumbers    = Pinyin.RemoveNumbersAndUnderscore(entry.PinyinNumbered),
                        Length             = entry.Traditional.Length,
                        MoedictHeteronymId = entry.Id,
                    };
                    index[key] = term;
                }
            }
        }
Beispiel #3
0
        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);
        }