/// <summary> Index a Dictionary</summary> /// <param name="dict">the dictionary to index</param> /// <param name="mergeFactor">mergeFactor to use when indexing</param> /// <param name="ramMB">the max amount or memory in MB to use</param> /// <throws> IOException </throws> /// <throws>AlreadyClosedException if the Spellchecker is already closed</throws> public virtual void IndexDictionary(Dictionary dict, int mergeFactor, int ramMB) { lock (modifyCurrentIndexLock) { EnsureOpen(); Directory dir = this.spellindex; IndexWriter writer = new IndexWriter(spellindex, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED); writer.SetMergeFactor(mergeFactor); writer.SetMaxBufferedDocs(ramMB); 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(); // also re-open the spell index to see our own changes when the next suggestion // is fetched: SwapSearcher(dir); } }
/// <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; }
/// <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; }