6
6
using Foundatio . Parsers . LuceneQueries ;
7
7
using Foundatio . Parsers . LuceneQueries . Nodes ;
8
8
using Foundatio . Parsers . LuceneQueries . Visitors ;
9
+ using System . Threading . Tasks ;
9
10
10
11
namespace Exceptionless . Core . Processors {
11
12
public class QueryProcessor {
@@ -19,7 +20,7 @@ public class QueryProcessor {
19
20
"stack"
20
21
} ;
21
22
22
- public static QueryProcessResult Process ( string query ) {
23
+ public static async Task < QueryProcessResult > ProcessAsync ( string query ) {
23
24
if ( String . IsNullOrWhiteSpace ( query ) )
24
25
return new QueryProcessResult { IsValid = true } ;
25
26
@@ -33,7 +34,7 @@ public static QueryProcessResult Process(string query) {
33
34
34
35
var validator = new QueryProcessorVisitor ( _freeFields ) ;
35
36
var context = new ElasticQueryVisitorContext ( ) ;
36
- result . Accept ( validator , context ) ;
37
+ await result . AcceptAsync ( validator , context ) . AnyContext ( ) ;
37
38
38
39
var expandedQuery = validator . UsesDataFields ? GenerateQueryVisitor . Run ( result ) : query ;
39
40
return new QueryProcessResult {
@@ -43,7 +44,7 @@ public static QueryProcessResult Process(string query) {
43
44
} ;
44
45
}
45
46
46
- public static QueryProcessResult Validate ( string query ) {
47
+ public static async Task < QueryProcessResult > ValidateAsync ( string query ) {
47
48
if ( String . IsNullOrEmpty ( query ) )
48
49
return new QueryProcessResult { IsValid = true } ;
49
50
@@ -57,7 +58,7 @@ public static QueryProcessResult Validate(string query) {
57
58
58
59
var validator = new QueryProcessorVisitor ( _freeFields ) ;
59
60
var context = new ElasticQueryVisitorContext ( ) ;
60
- result . Accept ( validator , context ) ;
61
+ await result . AcceptAsync ( validator , context ) . AnyContext ( ) ;
61
62
62
63
return new QueryProcessResult {
63
64
IsValid = true ,
@@ -73,7 +74,7 @@ public QueryProcessorVisitor(HashSet<string> freeFields) {
73
74
_freeFields = freeFields ?? new HashSet < string > ( ) ;
74
75
}
75
76
76
- public void Visit ( GroupNode node , IQueryVisitorContext context ) {
77
+ public async Task VisitAsync ( GroupNode node , IQueryVisitorContext context ) {
77
78
var childTerms = new List < string > ( ) ;
78
79
var leftTermNode = node . Left as TermNode ;
79
80
if ( leftTermNode != null && leftTermNode . Field == null )
@@ -97,29 +98,33 @@ public void Visit(GroupNode node, IQueryVisitorContext context) {
97
98
98
99
node . Field = GetCustomFieldName ( node . Field , childTerms . ToArray ( ) ) ?? node . Field ;
99
100
foreach ( var child in node . Children )
100
- child . Accept ( this , context ) ;
101
+ await child . AcceptAsync ( this , context ) . AnyContext ( ) ;
101
102
}
102
103
103
- public void Visit ( TermNode node , IQueryVisitorContext context ) {
104
+ public Task VisitAsync ( TermNode node , IQueryVisitorContext context ) {
104
105
// using all fields search
105
106
if ( String . IsNullOrEmpty ( node . Field ) ) {
106
107
UsesPremiumFeatures = true ;
107
- return ;
108
+ return Task . CompletedTask ;
108
109
}
109
110
110
111
node . Field = GetCustomFieldName ( node . Field , node . Term ) ?? node . Field ;
112
+ return Task . CompletedTask ;
111
113
}
112
114
113
- public void Visit ( TermRangeNode node , IQueryVisitorContext context ) {
115
+ public Task VisitAsync ( TermRangeNode node , IQueryVisitorContext context ) {
114
116
node . Field = GetCustomFieldName ( node . Field , node . Min , node . Max ) ?? node . Field ;
117
+ return Task . CompletedTask ;
115
118
}
116
119
117
- public void Visit ( ExistsNode node , IQueryVisitorContext context ) {
120
+ public Task VisitAsync ( ExistsNode node , IQueryVisitorContext context ) {
118
121
node . Field = GetCustomFieldName ( node . Field ) ?? node . Field ;
122
+ return Task . CompletedTask ;
119
123
}
120
124
121
- public void Visit ( MissingNode node , IQueryVisitorContext context ) {
125
+ public Task VisitAsync ( MissingNode node , IQueryVisitorContext context ) {
122
126
node . Field = GetCustomFieldName ( node . Field ) ?? node . Field ;
127
+ return Task . CompletedTask ;
123
128
}
124
129
125
130
private string GetCustomFieldName ( string field , params string [ ] terms ) {
0 commit comments