/
LogMainIndex.cs
122 lines (108 loc) · 4.44 KB
/
LogMainIndex.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using Area52.Services.Contracts;
using Raven.Client.Documents.Indexes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Area52.Services.Implementation.Raven.Indexes;
public class LogMainIndex : AbstractIndexCreationTask<LogEntity>
{
public class Result
{
public string Level
{
get;
init;
}
public int LevelNumeric
{
get;
init;
}
public DateTimeOffset Timestamp
{
get;
init;
}
public DateTime TimestampDateOnly
{
get;
set;
}
public string Message
{
get;
init;
}
public string? Exception
{
get;
init;
}
public Result()
{
this.Level = string.Empty;
this.Message = string.Empty;
}
}
public LogMainIndex()
{
#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type.
this.Map = logs => from log in logs
select new
{
Level = this.CreateField("Level", log.Level, new CreateFieldOptions()
{
Indexing = FieldIndexing.Exact,
Storage = FieldStorage.No,
TermVector = FieldTermVector.No
}),
LevelExact = this.CreateField("Level", log.Level, new CreateFieldOptions()
{
Indexing = FieldIndexing.Default,
Storage = FieldStorage.No,
TermVector = FieldTermVector.No
}),
//Level = log.Level,
LevelNumeric = log.LevelNumeric,
Timestamp = log.Timestamp,
TimestampDateOnly = log.Timestamp.Date.Date,
Message = log.Message,
Exception = log.Exception,
LogFullText = string.Concat(log.Timestamp.ToString("s"),
" ",
log.Level,
" ",
log.Message,
log.Exception),
_Exact = log.Properties.Where(t => t.Values != null).Select(t => this.CreateField(t.Name, t.Values, new CreateFieldOptions()
{
Indexing = FieldIndexing.Exact,
Storage = FieldStorage.No,
TermVector = FieldTermVector.No
})),
_ = log.Properties.Where(t => t.Values != null).Select(t => this.CreateField(t.Name, t.Values, new CreateFieldOptions()
{
Indexing = FieldIndexing.Default,
Storage = FieldStorage.No,
TermVector = FieldTermVector.No
})),
_Numbers = log.Properties.Where(t => t.Valued.HasValue).Select(t => this.CreateField(t.Name, t.Valued!.Value, new CreateFieldOptions()
{
Indexing = FieldIndexing.Exact,
Storage = FieldStorage.No,
TermVector = FieldTermVector.No
})),
};
#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type.
//this.Index(t => t.Level, FieldIndexing.Default);
//this.Index(t => t.Level, FieldIndexing.Exact);
//this.Index("LevelNumeric", FieldIndexing.Exact);
this.Index("LevelNumeric", FieldIndexing.Exact);
this.Index("LogFullText", FieldIndexing.Search);
//this.Store(t => t.Timestamp, FieldStorage.Yes);
//this.Store(t => t.Level, FieldStorage.Yes);
//this.Store(t => t.Message, FieldStorage.Yes);
}
}