// 1) Load Table // 2) Add items to index // 3) Save Index public void CreateIndex(string Name, string Directory, IDataReader reader, CultureInfo culture, string keyField, string textField) { int row = 0; TextIndex index = new TextIndex(Name, culture); index.IndexFolder = Directory; index.Initialize(); while (reader.Read()) { int key = (int)reader[keyField]; string text = (string)reader[textField]; index.AddPhrase(key, text); row++; if (OnRowInserted != null) OnRowInserted(row); } index.SaveIndex(); }
/// <remarks>This method assumes a reader lock has already been acquired before calling this method</remarks> private static TextIndex GetTextIndex(string catalog, CultureInfo culture) { string indexKey = catalog + culture.ToString(); if (Indexes.Keys.Contains(indexKey)) return Indexes[indexKey]; else { // Load the index! TextIndex index = new TextIndex(catalog, culture); index.IndexFolder = DatabasePath; index.Initialize(); index.LoadIndex(); LockCookie lc = readerLock.UpgradeToWriterLock(1000 * 60); // 60 seconds! Indexes.Add(indexKey, index); readerLock.DowngradeFromWriterLock(ref lc); return index; } }