Exemplo n.º 1
0
        public int CompareTo(object obj)
        {
            IndexTerm i = obj as IndexTerm;

            if (i == null)
            {
                return(-1);
            }

            // sort descending on frequency
            if (i.Frequency > this.frequency)
            {
                return(1);
            }

            return(-1);
        }
Exemplo n.º 2
0
        public static List<IndexTerm> GetIndexTerms(int siteId, int minFrequency, int maxFrequency)
        {
            List<IndexTerm> indexTerms = new List<IndexTerm>();

            using (Lucene.Net.Store.Directory searchDirectory = GetDirectory(siteId))
            {

                using (IndexReader reader = IndexReader.Open(searchDirectory, false))
                {

                    Term contentsField = new Term("contents");

                    TermEnum terms = reader.Terms(contentsField);
                    while (terms.Next())
                    {
                        Term term = terms.Term;
                        int frequency = reader.DocFreq(term);
                        if (frequency >= minFrequency)
                        {
                            if ((maxFrequency == -1) ||(frequency <= maxFrequency)) // -1 is no maximum
                            {
                                IndexTerm t = new IndexTerm();
                                t.Term = term.Text;
                                t.Frequency = frequency;
                                indexTerms.Add(t);
                            }
                        }
                    }

                }

            }

            indexTerms.Sort();

            return indexTerms;
        }