internal static void UseLuceneSearch(this IApplicationBuilder app, IHostEnvironment env, IHangfireBackJob hangfire, LuceneIndexerOptions luceneIndexerOptions)
        {
            var are = new AutoResetEvent(false);

            Task.Run(() =>
            {
                Console.WriteLine("正在导入自定义词库...");
                double time = HiPerfTimer.Execute(() =>
                {
                    var db        = app.ApplicationServices.GetRequiredService <DataContext>();
                    using var set = db.Post.Select(p => $"{p.Title},{p.Label},{p.Keyword}").AsParallel().SelectMany(s => Regex.Split(s, @"\p{P}(?<!\.|#)|\p{Z}|\p{S}")).Where(s => s.Length > 1).ToPooledSet();
                    var lines     = File.ReadAllLines(Path.Combine(env.ContentRootPath, "App_Data", "CustomKeywords.txt")).Union(set);
                    KeywordsManager.AddWords(lines);
                    KeywordsManager.AddSynonyms(File.ReadAllLines(Path.Combine(env.ContentRootPath, "App_Data", "CustomSynonym.txt")).Where(s => s.Contains(" ")).Select(s =>
                    {
                        var arr = Regex.Split(s, "\\s");
                        return(arr[0], arr[1]);
                    }));
                });
                Console.WriteLine($"导入自定义词库完成,耗时{time}s");
                Windows.ClearMemorySilent();
                are.Set();
            });

            string lucenePath = Path.Combine(env.ContentRootPath, luceneIndexerOptions.Path);

            if (!Directory.Exists(lucenePath) || Directory.GetFiles(lucenePath).Length < 1)
            {
                are.WaitOne();
                Console.WriteLine("索引库不存在,开始自动创建Lucene索引库...");
                hangfire.CreateLuceneIndex();
                Console.WriteLine("索引库创建完成!");
            }
        }
Beispiel #2
0
 /// <summary>
 /// Instancia clase
 /// </summary>
 /// <param name="settings">Objeto con la configuracion de mapeo</param>
 public OwlHandler(OwlSettings settings)
 {
     ETexts.LoadTexts();
     Settings        = settings;
     XOMLValidator   = new XOMLValidator();
     KeywordsManager = new KeywordsManager();
     _OwlVars        = new Dictionary <string, string>();
 }