public override bool LessThan(object a, object b) { TermModel modle = (TermModel)a; TermModel modle2 = (TermModel)b; return(modle.Count < modle2.Count); }
/// <summary> /// 查找指定字段Term /// </summary> /// <param name="field"></param> /// <param name="text"></param> /// <param name="current"></param> /// <returns></returns> public TermModel FindTerm(string field, string text, bool current) { TermEnum enum2 = open.Reader.Terms(); if (enum2.SkipTo(new Term(field, text))) { TermModel modle2 = null; while ((!current && enum2.Next() && field.Equals(enum2.Term().Field())) || current) { modle2 = new TermModel(enum2.Term(), enum2.DocFreq()); break; } enum2.Close(); return modle2; } return null; }
/// <summary> /// 查找指定数目的Term /// </summary> /// <param name="num"></param> /// <returns></returns> public TermModel[] FindTerms(int num) { num++; TermInfoQueue queue = new TermInfoQueue(num); TermEnum enum2 = open.Reader.Terms(); int count = 0; while (enum2.Next()) { string str = enum2.Term().Field(); if ((currentField != null) && (!str.Equals(currentField))) { continue; } if (enum2.DocFreq() > count) { queue.Put(new TermModel(enum2.Term(), enum2.DocFreq())); if (queue.Size() < num) { continue; } queue.Pop(); count = ((TermModel)queue.Top()).Count; } } enum2.Close(); TermModel[] modleArray = new TermModel[queue.Size()]; for (int i = 0; i < modleArray.Length; i++) { modleArray[(modleArray.Length - i) - 1] = (TermModel)queue.Pop(); } return modleArray; }