コード例 #1
0
        public virtual ContentIndexResult IndexContent(IContent content, bool includeChild = false)
        {
            SlimContentReader slimContentReader = new SlimContentReader(this._contentRepository, content.ContentLink, (c =>
            {
                return(includeChild);
            }));
            var listDocument = new List <SearchDocument>();

            while (slimContentReader.Next())
            {
                if (!slimContentReader.Current.ContentLink.CompareToIgnoreWorkID(ContentReference.RootPage))
                {
                    IVersionable current = slimContentReader.Current as IVersionable;
                    if (current == null || current.Status == VersionStatus.Published)
                    {
                        if (LuceneConfiguration.CanIndexContent(slimContentReader.Current))
                        {
                            var document = GetDocFromContent(slimContentReader.Current);
                            if (document != null)
                            {
                                listDocument.Add(document);
                            }
                        }
                    }
                }
            }
            _documentRepository.UpdateBatchIndex(listDocument);
            return(new ContentIndexResult());
        }
コード例 #2
0
        public void can_get_specific_log()
        {
            var luceneConfiguration = new LuceneConfiguration
            {
                MaxSearch = 10,
                Path      = Path.Combine(TestHelper.GetTestLogDirectory(), "Lucene"),
                OpenMode  = OpenMode.CREATE,
                Directory = ""
            };

            var directory = Assembly.GetExecutingAssembly().GetName().Name;

            var searcherService = new LuceneSearcherService(luceneConfiguration);

            var result = searcherService.GetLogWithFilters(null, new DateTime(2, 01, 01), new DateTime(9999, 01, 01), new[] { "LogLevel", "Text" }, new[] { "Info" }, "Text:\"Hello world\"", new[] { directory }, 0);

            result.Should().NotBeNull();
            result.Count.Should().Be(1);
            result[0].LogType.Should().Be(ELogType.Line);

            var log = result[0] as LineViewModel;

            log.Text.Should().Be("Hello world");
            log.LogLevel.Should().Contain("Info");
        }
コード例 #3
0
        public ContentIndexResult ReindexSiteForRecovery(IContent siteRoot)
        {
            SlimContentReader slimContentReader = new SlimContentReader(this._contentRepository, siteRoot.ContentLink, (c =>
            {
                return(true);
            }));
            var listDocument = new List <SearchDocument>();

            while (slimContentReader.Next())
            {
                if (!slimContentReader.Current.ContentLink.CompareToIgnoreWorkID(ContentReference.RootPage))
                {
                    IVersionable current = slimContentReader.Current as IVersionable;
                    if (current == null || current.Status == VersionStatus.Published)
                    {
                        if (LuceneConfiguration.CanIndexContent(slimContentReader.Current))
                        {
                            var document = GetDocFromContent(slimContentReader.Current);
                            if (document != null)
                            {
                                listDocument.Add(document);
                            }
                        }
                    }
                }
            }
            _documentRepository.ReindexSiteForRecovery(listDocument, siteRoot.ContentGuid);
            return(new ContentIndexResult());
        }
コード例 #4
0
        public void log_can_be_search()
        {
            var luceneConfiguration = new LuceneConfiguration
            {
                MaxSearch = 10,
                Path      = Path.Combine(TestHelper.GetTestLogDirectory(), "Lucene"),
                OpenMode  = OpenMode.CREATE,
                Directory = ""
            };
            var directory = Assembly.GetExecutingAssembly().GetName().Name;

            var searcherService = new LuceneSearcherService(luceneConfiguration);

            var result = searcherService.Search("Text:\"Hello world\"", directory);

            result.Should().NotBeNull();
            result.Count.Should().Be(1);
            result[0].LogType.Should().Be(ELogType.Line);

            var log = result[0] as LineViewModel;

            log.Text.Should().Be("Hello world");
            log.LogLevel.Should().Contain("Info");

            result = searcherService.Search("Text:\"CriticalError\"", directory);
            result.Should().NotBeNull();
            result.Count.Should().Be(1);
            result[0].LogType.Should().Be(ELogType.Line);

            log = result[0] as LineViewModel;
            log.Text.Should().Be("CriticalError");
            log.LogLevel.Should().Contain("Error");
        }
コード例 #5
0
 private void DeleteContentLanguage(object sender, ContentEventArgs e)
 {
     Task.Run(() =>
     {
         if (SiteCreationServiceBase.IsSettingUpSite())
         {
             return;
         }
         if (LuceneConfiguration.CanIndexContent(e.Content))
         {
             _indexingHandler.Value.ProcessRequest(new IndexRequestItem(e.Content, IndexRequestItem.REMOVE_LANGUAGE));
         }
     });
 }
        public string IndexSite(List <int> siteStartPageIds)
        {
            var progress = new StringBuilder();

            progress.AppendLine("Start Indexing </br>");
            if (!LuceneConfiguration.Active)
            {
                progress.AppendLine("Lucene not activated </br>");
                return(progress.ToString());
            }
            foreach (var siteId in siteStartPageIds)
            {
                PageData siteRoot;
                if (_contentRepository.TryGet <PageData>(new ContentReference(siteId), out siteRoot))
                {
                    if (siteRoot == null)
                    {
                        continue;
                    }
                    try
                    {
                        SlimContentReader slimContentReader = new SlimContentReader(this._contentRepository, siteRoot.ContentLink, (c =>
                        {
                            return(true);
                        }));
                        while (slimContentReader.Next())
                        {
                            var currentContent = slimContentReader.Current;
                            if (currentContent != null && !currentContent.ContentLink.CompareToIgnoreWorkID(ContentReference.RootPage))
                            {
                                if (LuceneConfiguration.CanIndexContent(currentContent))
                                {
                                    _indexingHandler.ProcessRequest(new IndexRequestItem(currentContent));
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        _logger.Error($"Lucene Index Site Error: {siteRoot.ContentLink.ID} - {siteRoot.Name}", e);
                        progress.AppendLine($"{siteRoot.ContentLink.ID} - {siteRoot.Name} index failed </br>");
                        continue;
                    }
                    progress.AppendLine($"Site: {siteRoot.ContentLink.ID} - {siteRoot.Name} indexed; </br>");
                }
            }
            progress.AppendLine("Indexing completed</br>");
            return(progress.ToString());
        }
コード例 #7
0
 private void UpdateSecurity(object sender, ContentSecurityEventArg e)
 {
     Task.Run(() =>
     {
         if (SiteCreationServiceBase.IsSettingUpSite())
         {
             return;
         }
         var content = _contentRepository.Value.Get <IContent>(e.ContentLink);
         if (LuceneConfiguration.CanIndexContent(content))
         {
             _indexingHandler.Value.ProcessRequest(new IndexRequestItem(content));
         }
     });
 }
コード例 #8
0
 public IndexCkmon(LuceneConfiguration configuration, string pathCkmon)
 {
     using (var indexer = new LuceneIndexer(configuration))
         using (LogReader reader = LogReader.Open(pathCkmon))
         {
             reader.MoveNext();
             for ( ; ;)
             {
                 indexer.IndexLog(reader.CurrentMulticast, configuration.Directory);
                 if (!reader.MoveNext())
                 {
                     return;
                 }
             }
         }
 }
コード例 #9
0
ファイル: Program.cs プロジェクト: pngouin/CK-Glouton
        private static void Main(string[] args)
        {
            Console.WriteLine(".ckmon need to be in ./ckmon");
            foreach (var path in GetFiles())
            {
                var appName = "ckmon-" + Guid.NewGuid().ToString().Substring(0, 8);
                Console.WriteLine($"{path} will be indexed in ${appName}");

                var configuration = new LuceneConfiguration
                {
                    MaxSearch = 100,
                    Directory = appName
                };
                var indexCkmon = new IndexCkmon(configuration, path);
            }
        }
コード例 #10
0
        public void can_get_monitor_id_list()
        {
            var luceneConfiguration = new LuceneConfiguration
            {
                MaxSearch = 10,
                Path      = Path.Combine(TestHelper.GetTestLogDirectory(), "Lucene"),
                OpenMode  = OpenMode.CREATE,
                Directory = ""
            };

            var searcherService = new LuceneSearcherService(luceneConfiguration);

            var result = searcherService.GetMonitorIdList();

            result.Should().NotBeNull();
            result.Count.Should().BeGreaterThan(0);
        }
コード例 #11
0
        public void can_get_all_appName()
        {
            var luceneConfiguration = new LuceneConfiguration
            {
                MaxSearch = 10,
                Path      = Path.Combine(TestHelper.GetTestLogDirectory(), "Lucene"),
                OpenMode  = OpenMode.CREATE,
                Directory = ""
            };

            var searcherService = new LuceneSearcherService(luceneConfiguration);

            var result = searcherService.GetAppNameList();

            result.Should().NotBeNull();
            result.Count.Should().BeGreaterThan(0);
            result.Should().Contain(Assembly.GetExecutingAssembly().GetName().Name);
        }
コード例 #12
0
        public void can_get_all_logs()
        {
            var luceneConfiguration = new LuceneConfiguration
            {
                MaxSearch = 10,
                Path      = Path.Combine(TestHelper.GetTestLogDirectory(), "Lucene"),
                OpenMode  = OpenMode.CREATE,
                Directory = ""
            };

            var directory = Assembly.GetExecutingAssembly().GetName().Name;

            var searcherService = new LuceneSearcherService(luceneConfiguration);

            var result = searcherService.GetAll(new[] { directory });

            result.Should().NotBeNull();
            result.Count.Should().Be(LuceneTestIndexBuilder.TotalLogCount);
        }
コード例 #13
0
ファイル: Lucene.cs プロジェクト: 15831944/SearchEngine
        private void Init(LuceneConfiguration config)
        {
            FSDirectory _directoryTemp;

            System.IO.Directory.CreateDirectory(config.LuceneIndexDirectory);

            _directoryTemp = FSDirectory.Open(new DirectoryInfo(config.LuceneIndexDirectory));

            if (IndexWriter.IsLocked(_directoryTemp))
            {
                IndexWriter.Unlock(_directoryTemp);
            }

            var lockFilePath = Path.Combine(config.LuceneIndexDirectory, "write.lock");

            if (File.Exists(lockFilePath))
            {
                File.Delete(lockFilePath);
            }

            _directory = _directoryTemp;
        }
コード例 #14
0
 public LuceneSearcherService(LuceneConfiguration configuration)
 {
     _configuration   = configuration;
     _searcherManager = new LuceneSearcherManager(_configuration);
 }
コード例 #15
0
 public LuceneSearcherService(IOptions <LuceneConfiguration> configuration)
 {
     _configuration   = configuration.Value;
     _searcherManager = new LuceneSearcherManager(_configuration);
 }