Ejemplo n.º 1
0
 public static TimeSpan WriteIndexWithEvent(Analyzer analyzer, IndexerSet indexer, Source source, bool create,
                                         IndexCompletedEventHandler OnIndexCompleted,
                                         IndexProgressChangedEventHandler OnProgressChanged)
 {
     try
     {
         //ChineseSegAnalysis csa = new ChineseSegAnalysis(index.BasePath, index.NamePath, index.NumberPath, index.CustomPaths);
         //csa.FilterFilePath = index.FilterPath;
         //Analyzer analyzer = csa.GetAnalyzer();
         string connect = source.GetConnString();
         DateTime start;
         if (create)
         {
             DBRamCreateIndexer dbcIndexer = new DBRamCreateIndexer(analyzer, source.DBType, connect, index.Path,index.Caption);
             dbcIndexer.OnIndexCompleted += OnIndexCompleted;
             dbcIndexer.OnProgressChanged += OnProgressChanged;
             start = DateTime.Now;
             dbcIndexer.WriteResultsWithEvent(source.Query, indexer.MaxFieldLength, indexer.RamBufferSize, indexer.MergeFactor, indexer.MaxBufferedDocs);
             return DateTime.Now - start;
         }
         else
         {
             DBRamIncremIndexer dbiIndexer = new DBRamIncremIndexer(analyzer, source.DBType, connect, index.Path,index.Caption);
             dbiIndexer.OnIndexCompleted += OnIndexCompleted;
             dbiIndexer.OnProgressChanged += OnProgressChanged;
             start = DateTime.Now;
             dbiIndexer.WriteResultsWithEvent(source.Query, indexer.MaxFieldLength, indexer.RamBufferSize, indexer.MergeFactor, indexer.MaxBufferedDocs);
             return DateTime.Now - start;
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Ejemplo n.º 2
0
 internal static void IndexDir(IndexWriter writer, string dir, IndexProgressChangedEventHandler OnProgressChanged)
 {
     List<string> fileList = SupportClass.FileUtil.GetDirFiles(dir, string.Empty);
     foreach (string file in fileList)
     {
         try
         {
             IndexFile(writer, file);
             OnProgressChanged("FileIndexer", new IndexProgressChangedEventArgs(1000, 1));
         }
         catch (Exception)
         {
             continue;
         }
     }
 }
Ejemplo n.º 3
0
 public static bool IndexFile(bool create, IndexCompletedEventHandler OnIndexCompleted, IndexProgressChangedEventHandler OnProgressChanged)
 {
     try
     {
         if (create)
         {
             SupportClass.FileUtil.DeleteFolder(fileSet.Path);
         }
         IndexWriter writer = new IndexWriter(fileSet.Path, analyzer, create);
         writer.SetMaxFieldLength(indexerSet.MaxFieldLength);
         writer.SetRAMBufferSizeMB(indexerSet.RamBufferSize);
         writer.SetMergeFactor(indexerSet.MergeFactor);
         writer.SetMaxBufferedDocs(indexerSet.MaxBufferedDocs);
         int i=0;
         foreach (string dir in fileSet.BaseDirs)
         {
             i++;
             FileIndexer.IndexDir(writer, dir,OnProgressChanged);
             OnProgressChanged("IndexUtil", new IndexProgressChangedEventArgs(fileSet.BaseDirs.Count, i));
         }
         writer.Optimize();
         writer.Close();
         OnIndexCompleted("IndexUtil", new IndexCompletedEventArgs("File"));
         return true;
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Ejemplo n.º 4
0
 public static void IndexWithEventEx(bool isIncreament, IndexCompletedEventHandler OnIndexCompleted, IndexProgressChangedEventHandler OnProgressChanged)
 {
     if (!initSettings)
         throw new ApplicationException("Index Settings not init!");
     if (indexDict.Count > 0)
     {
         foreach (IndexSet indexSet in indexDict.Keys)
         {
             if (indexSet.Type == type)
             {
                 RamIWriter.WriteIndexWithEvent(analyzer, indexerSet, indexSet, indexDict[indexSet], type == IndexTypeEnum.Ordinary, OnIndexCompleted, OnProgressChanged);
             }
         }
     }
 }
Ejemplo n.º 5
0
 public static void BoostIndexWithEvent(bool isIncreament, IndexCompletedEventHandler OnIndexCompleted, IndexProgressChangedEventHandler OnProgressChanged)
 {
     if (!initSettings)
         throw new ApplicationException("Index Settings not init!");
     if (indexDict.Count > 0)
     {
         foreach (IndexSet indexSet in indexDict.Keys)
         {
             if (indexSet.Type == IndexTypeEnum.Ordinary)
             {
                 SupportClass.FileUtil.DeleteFolder(indexSet.Path);
             }
             if (indexSet.Type == type)
             {
                 IWriter.WriteBoostIndexWithEvent(analyzer, indexerSet, indexSet, indexDict[indexSet], type == IndexTypeEnum.Ordinary, OnIndexCompleted, OnProgressChanged);
             }
         }
     }
 }
Ejemplo n.º 6
0
 public static void BoostIndexWithEvent(Source source, bool isIncreament, IndexCompletedEventHandler OnIndexCompleted, IndexProgressChangedEventHandler OnProgressChanged)
 {
     if (!initSettings)
         throw new ApplicationException("Index Settings not init!");
     if (indexDict.Count > 0 && indexDict.ContainsKey(indexSet))
     {
         //DataBaseLibrary.SearchUpdateManage dblSum = new DataBaseLibrary.SearchUpdateManage();
         SupportClass.FileUtil.DeleteFolder(indexSet.Path);
         IWriter.WriteBoostIndexWithEvent(analyzer, indexerSet, indexSet, indexDict[indexSet], type == IndexTypeEnum.Ordinary, OnIndexCompleted, OnProgressChanged);
     }
 }