示例#1
0
 void DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
 {
     IndexGenerate.CreateIndex(backgroundWorker1);
 }
示例#2
0
        public ArrayList GetMetaphoneList(string word)
        {
            int    upper = (int)(m_metaphoneFile.Length / 4) - 1;           // 和数组一样 最后一个元素下标是总数减一
            int    lower = 0;
            int    pos   = 0;
            int    ret;
            string tmp;
            var    list = new ArrayList();

            string search = IndexGenerate.GetMetaphone(word);

            if (search == null)
            {
                return(list);
            }

            do               // TODO 可以提取到一个函数中
            {
                pos = (upper + lower) / 2;
                tmp = IndexGenerate.GetMetaphone(GetWordByMetaIndex(pos));                 //TODO 这里错了 不能用普通的查找表来找MP
                ret = String.Compare(search, tmp, StringComparison.OrdinalIgnoreCase);

                if (ret == 0)
                {
                    break;
                }
                else if (ret < 0)
                {
                    upper = pos - 1;
                    pos   = (upper + lower) / 2;
                }
                else
                {
                    lower = pos + 1;
                    pos   = (upper + lower) / 2;
                }
            } while (upper >= lower);

            if (ret == 0)
            {
                // 向前找第一个
                for (int i = 1; i < 100; i++)
                {
                    string meta = IndexGenerate.GetMetaphone(GetWordByMetaIndex(pos - i));
                    if (meta != search)
                    {
                        pos = pos - i + 1;
                        break;
                    }
                }
                // 按顺序插入输出
                for (int i = 0; i < 100; i++)
                {
                    string out_word = GetWordByMetaIndex(pos + i);
                    string meta     = IndexGenerate.GetMetaphone(out_word);

                    if (meta != search)
                    {
                        break;
                    }
                    list.Add(out_word);
                }
            }
            list.Sort();
            return(list);
        }