/// <summary> /// Builds an index of the documents given by this object's state. /// </summary> private void CreateIndex() { if (SelectedDocFiles == null || !SelectedDocFiles.Any()) return; try { if (_ngramLucene != null) _ngramLucene.Dispose(); var indexPath = CommonFiles.IndexBasePath(LanguageId); var docsPath = CommonFiles.DocsPath(LanguageId); using (var lucene = new NGramLucene(indexPath, true, IgnoreCase)) { foreach (string fileName in SelectedDocFiles) { string path = Path.Combine(docsPath, fileName); string text = File.ReadAllText(path); lucene.CreateAndAddDocument(text, fileName); } lucene.FinishAdding(); } _ngramLucene = new NGramLucene(indexPath, false, IgnoreCase); } catch (Exception ex) { Debug.WriteLine(ex.Message + ex.StackTrace); } }
public void Initialize() { string lang = LanguageId; if (_ngramLucene != null) _ngramLucene.Dispose(); try { _ngramLucene = new NGramLucene(CommonFiles.IndexBasePath(lang), false, IgnoreCase); } catch (Exception ex) { Debug.WriteLine(ex.Message + ex.StackTrace); } _ngramIndexer = new NGramIndexer(CommonFiles.Words(lang), CommonFiles.WordCounts(lang), CommonFiles.NGrams(lang), CommonFiles.NGramCounts(lang), CommonFiles.NGramsByWord(lang), CommonFiles.WordsByNGram(lang)); }