private async Task <Keyword[]> CalculateKeywords(Article article) { var articleContent = await DownloadArticleContent(article.Url); var concatenatedText = string.Join(" ", articleContent, article.Title, article.Summary); return(_keywordsParser.Parse(concatenatedText).Take(50).ToArray()); }
private static async Task <ApplicationLogSearchResults> FilterLogsAsync(ILogStore logStore, ApplicationLogFilterModel filter, int offset) { Debug.Assert(filter.dfrom.HasValue); Debug.Assert(filter.dto.HasValue); var levels = new List <LogRecord.ELogLevel>(); for (short lvl = filter.lfrom ?? 0; lvl <= filter.lto; lvl++) { levels.Add((LogRecord.ELogLevel)lvl); } var searchResults = await logStore.FilterLogsAsync(new LogSearchCriteria { ApplicationPath = filter.apppath, Server = filter.server, FromUtc = filter.dfrom.Value.ToUniversalTime(), ToUtc = filter.dto.Value.ToUniversalTime(), Logger = filter.logger, Keywords = KeywordsParser.Parse(filter.keywords), Levels = levels.ToArray(), Limit = MaxLogsCount + 1, Offset = offset }); var foundItems = searchResults.FoundItems.ToArray(); LogRecord[] finalResults; if (foundItems.Length < MaxLogsCount + 1) { finalResults = foundItems; } else { finalResults = new LogRecord[foundItems.Length - 1]; Array.Copy(foundItems, finalResults, finalResults.Length); } return(new ApplicationLogSearchResults { FoundItems = finalResults, Limit = MaxLogsCount, Offset = offset, IsLastPage = foundItems.Length < MaxLogsCount + 1 }); }
public void Keywords_are_words_with_more_than_2_letters(string text) { _keywordsParser.Parse(text) .Should() .BeEquivalentTo(new Keyword("test", 2)); }
public void Test() { var s = "http:200.0.1 test test2 ip:192.168.0.1 bla bla2 "; var keywordsParsed = KeywordsParser.Parse(s); Assert.Equal("200.0.1", keywordsParsed.HttpStatus); Assert.Equal("192.168.0.1", keywordsParsed.ClientIp); Assert.Null(keywordsParsed.Url); Assert.Null(keywordsParsed.Service); Assert.Equal("test test2 bla bla2 ", keywordsParsed.FreeText); s = "http:200.0.1"; keywordsParsed = KeywordsParser.Parse(s); Assert.Equal("200.0.1", keywordsParsed.HttpStatus); Assert.Null(keywordsParsed.ClientIp); Assert.Null(keywordsParsed.Url); Assert.Null(keywordsParsed.Service); Assert.Equal("", keywordsParsed.FreeText); s = null; keywordsParsed = KeywordsParser.Parse(s); Assert.NotNull(keywordsParsed); Assert.Null(keywordsParsed.Url); Assert.Null(keywordsParsed.Service); Assert.Null(keywordsParsed.HttpStatus); Assert.Null(keywordsParsed.ClientIp); Assert.Null(keywordsParsed.FreeText); s = "testurl:test lkjsdflksjf ghttp:sdfsf"; keywordsParsed = KeywordsParser.Parse(s); Assert.NotNull(keywordsParsed); Assert.Null(keywordsParsed.Url); Assert.Null(keywordsParsed.Service); Assert.Null(keywordsParsed.HttpStatus); Assert.Null(keywordsParsed.ClientIp); Assert.Equal(s, keywordsParsed.FreeText); s = " url:'test url with space' 1test 2test service:'service name with space' '"; keywordsParsed = KeywordsParser.Parse(s); Assert.Equal("test url with space", keywordsParsed.Url); Assert.Equal("service name with space", keywordsParsed.Service); Assert.Null(keywordsParsed.HttpStatus); Assert.Null(keywordsParsed.ClientIp); Assert.Equal(" 1test 2test '", keywordsParsed.FreeText); s = " url: service:'test' 1test2"; keywordsParsed = KeywordsParser.Parse(s); Assert.Null(keywordsParsed.Url); Assert.Equal("test", keywordsParsed.Service); Assert.Null(keywordsParsed.HttpStatus); Assert.Null(keywordsParsed.ClientIp); Assert.Equal(" url: 1test2", keywordsParsed.FreeText); s = " url:' service:'test' 1test2"; keywordsParsed = KeywordsParser.Parse(s); Assert.Equal(" service:", keywordsParsed.Url); Assert.Null(keywordsParsed.Service); Assert.Null(keywordsParsed.HttpStatus); Assert.Null(keywordsParsed.ClientIp); Assert.Equal("est' 1test2", keywordsParsed.FreeText); // TODO: we consider this valid? s = "test test2 url:"; keywordsParsed = KeywordsParser.Parse(s); Assert.Null(keywordsParsed.Url); Assert.Null(keywordsParsed.Service); Assert.Null(keywordsParsed.HttpStatus); Assert.Null(keywordsParsed.ClientIp); Assert.Equal("test test2 url:", keywordsParsed.FreeText); s = "test test2 url:'"; keywordsParsed = KeywordsParser.Parse(s); Assert.Null(keywordsParsed.Url); Assert.Null(keywordsParsed.Service); Assert.Null(keywordsParsed.HttpStatus); Assert.Null(keywordsParsed.ClientIp); Assert.Equal("test test2 url:'", keywordsParsed.FreeText); }