Ejemplo n.º 1
0
        /// <summary>
        /// Create a query to search into the logs.
        /// </summary>
        /// <param name="configuration"></param>
        /// <returns></returns>
        private static Query CreateQuery(ILuceneSearcherConfiguration configuration)
        {
            var bQuery = new BooleanQuery();

            if (configuration.MonitorId != null)
            {
                bQuery.Add(CreateMonitorIdQuery(configuration), Occur.MUST);
            }
            if (configuration.DateEnd.Year != 1 && configuration.DateStart.Year != 1)
            {
                bQuery.Add(CreateTimeQuery(configuration), Occur.MUST);
            }
            if (configuration.LogLevel != null)
            {
                bQuery.Add(CreateLogLevelQuery(configuration), Occur.MUST);
            }
            if (configuration.GroupDepth != null)
            {
                bQuery.Add(CreateGroupDepthQuery(configuration), Occur.MUST);
            }

            bQuery.Add(CreateFieldQuery(configuration), Occur.MUST);

            return(bQuery);
        }
Ejemplo n.º 2
0
 private static Query CreateTimeQuery(ILuceneSearcherConfiguration configuration)
 {
     return(TermRangeQuery.NewStringRange
            (
                LogField.LOG_TIME,
                BuildDate(configuration.DateStart),
                BuildDate(configuration.DateEnd),
                true,
                true
            ));
 }
Ejemplo n.º 3
0
        private static Query CreateLogLevelQuery(ILuceneSearcherConfiguration configuration)
        {
            var levelParser = new QueryParser
                              (
                LuceneVersion.LUCENE_48,
                LogField.LOG_LEVEL,
                new StandardAnalyzer(LuceneVersion.LUCENE_48)
                              );

            var bLevelQuery = new BooleanQuery();

            foreach (var level in configuration.LogLevel)
            {
                bLevelQuery.Add(levelParser.Parse(level), Occur.SHOULD);
            }

            return(bLevelQuery);
        }
Ejemplo n.º 4
0
        private static Query CreateFieldQuery(ILuceneSearcherConfiguration configuration)
        {
            var bFieldQuery = new BooleanQuery();

            if (configuration.Fields == null || configuration.Fields.Length == 0)
            {
                bFieldQuery.Add(new WildcardQuery(new Term(LogField.LOG_LEVEL, "*")), Occur.SHOULD);
                return(bFieldQuery);
            }

            foreach (var field in configuration.Fields)
            {
                if (field == LogField.TEXT && configuration.Query != null)
                {
                    bFieldQuery.Add(new QueryParser(LuceneVersion.LUCENE_48, field, new StandardAnalyzer(LuceneVersion.LUCENE_48)).Parse(configuration.Query), Occur.SHOULD);
                }
                else
                {
                    bFieldQuery.Add(new WildcardQuery(new Term(field, configuration.Query ?? "*")), Occur.SHOULD);
                }
            }

            return(bFieldQuery);
        }
Ejemplo n.º 5
0
 private List <ILogViewModel> Search(ILuceneSearcherConfiguration configuration, Query searchQuery)
 {
     return(CreateLogsResult(_indexSearcher?.Search(searchQuery, configuration.MaxResult, _sort)));
 }
Ejemplo n.º 6
0
 private static Query CreateMonitorIdQuery(ILuceneSearcherConfiguration configuration)
 {
     return(new TermQuery(new Term(LogField.MONITOR_ID, configuration.MonitorId)));
 }
Ejemplo n.º 7
0
 private static Query CreateGroupDepthQuery(ILuceneSearcherConfiguration configuration)
 {
     return(new WildcardQuery(new Term(LogField.GROUP_DEPTH, configuration.GroupDepth.ToString())));
 }