Exemplo n.º 1
0
        public virtual void  ClearIndex()
        {
            IndexReader.Unlock(spellindex);
            IndexWriter writer = new IndexWriter(spellindex, null, true);

            writer.Close();
        }
Exemplo n.º 2
0
        /// <summary> Index a Dictionary</summary>
        /// <param name="dict">the dictionary to index
        /// </param>
        /// <throws>  IOException </throws>
        public virtual void  IndexDictionary(Dictionary dict)
        {
            IndexReader.Unlock(spellindex);
            IndexWriter writer = new IndexWriter(spellindex, new WhitespaceAnalyzer(), !IndexReader.IndexExists(spellindex));

            writer.SetMergeFactor(300);
            writer.SetMaxBufferedDocs(150);

            System.Collections.IEnumerator iter = dict.GetWordsIterator();
            while (iter.MoveNext())
            {
                System.String word = (System.String)iter.Current;

                int len = word.Length;
                if (len < 3)
                {
                    continue; // too short we bail but "too long" is fine...
                }

                if (this.Exist(word))
                {
                    // if the word already exist in the gramindex
                    continue;
                }

                // ok index the word
                Document doc = CreateDocument(word, GetMin(len), GetMax(len));
                writer.AddDocument(doc);
            }
            // close writer
            writer.Optimize();
            writer.Close();

            // close reader
            reader.Close();
            reader = null;
        }