コード例 #1
0
        /// <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);
        }
コード例 #2
0
        public IEnumerable <TermInfo> GetHighFrequencyTerms(int numTerms, string[] fields)
        {
            if (_reader == null || fields == null)
            {
                return(new TermInfo[0]);
            }

            var termInfoQueue = new TermInfoQueue(numTerms);

            var terms = _reader.Terms();

            while (terms.Next())
            {
                var term = terms.Term();
                if (termInfoQueue.Size() >= numTerms)
                {
                    break;
                }

                if (fields.Length > 0)
                {
                    // The lamda expresion is testing to see if the field that belongs to the term from lucene
                    // is in the list of fields we passed in
                    var skipField = fields.All(field => !term.Field().Equals(field));
                    if (skipField)
                    {
                        continue;
                    }

                    if (terms.DocFreq() > 0)
                    {
                        termInfoQueue.Add(new TermInfo(term, terms.DocFreq()));
                    }
                }
            }

            var res = BuildTermInfoList(termInfoQueue);

            return(res);
        }
コード例 #3
0
 /// <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;
 }