Skip to content

Commit fa4f5ab

Browse files
authored
Merge branch 'master' into dependabot/nuget/src/Foundatio.Parsers.ElasticQueries/System.Text.Json-8.0.4
2 parents 87bcb07 + 09a41f9 commit fa4f5ab

28 files changed

+1898
-352
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@ _NCrunch_*
5151
# Rider auto-generates .iml files, and contentModel.xml
5252
**/.idea/**/*.iml
5353
**/.idea/**/contentModel.xml
54-
**/.idea/**/modules.xml
54+
**/.idea/**/modules.xml
55+
**/.idea/copilot/chatSessions/

Foundatio.Parsers.sln

+12
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
2222
EndProject
2323
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Foundatio.Parsers.ElasticQueries.Tests", "tests\Foundatio.Parsers.ElasticQueries.Tests\Foundatio.Parsers.ElasticQueries.Tests.csproj", "{C353E601-874C-4855-9B01-2980BC624BC4}"
2424
EndProject
25+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Foundatio.Parsers.SqlQueries", "src\Foundatio.Parsers.SqlQueries\Foundatio.Parsers.SqlQueries.csproj", "{53C0B9D8-6398-437C-AE15-43BD4CB7AD8D}"
26+
EndProject
27+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Foundatio.Parsers.SqlQueries.Tests", "tests\Foundatio.Parsers.SqlQueries.Tests\Foundatio.Parsers.SqlQueries.Tests.csproj", "{B30934E7-C69F-465B-BACF-61AAEC7DA775}"
28+
EndProject
2529
Global
2630
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2731
Debug|Any CPU = Debug|Any CPU
@@ -44,6 +48,14 @@ Global
4448
{C353E601-874C-4855-9B01-2980BC624BC4}.Debug|Any CPU.Build.0 = Debug|Any CPU
4549
{C353E601-874C-4855-9B01-2980BC624BC4}.Release|Any CPU.ActiveCfg = Release|Any CPU
4650
{C353E601-874C-4855-9B01-2980BC624BC4}.Release|Any CPU.Build.0 = Release|Any CPU
51+
{53C0B9D8-6398-437C-AE15-43BD4CB7AD8D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
52+
{53C0B9D8-6398-437C-AE15-43BD4CB7AD8D}.Debug|Any CPU.Build.0 = Debug|Any CPU
53+
{53C0B9D8-6398-437C-AE15-43BD4CB7AD8D}.Release|Any CPU.ActiveCfg = Release|Any CPU
54+
{53C0B9D8-6398-437C-AE15-43BD4CB7AD8D}.Release|Any CPU.Build.0 = Release|Any CPU
55+
{B30934E7-C69F-465B-BACF-61AAEC7DA775}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
56+
{B30934E7-C69F-465B-BACF-61AAEC7DA775}.Debug|Any CPU.Build.0 = Debug|Any CPU
57+
{B30934E7-C69F-465B-BACF-61AAEC7DA775}.Release|Any CPU.ActiveCfg = Release|Any CPU
58+
{B30934E7-C69F-465B-BACF-61AAEC7DA775}.Release|Any CPU.Build.0 = Release|Any CPU
4759
EndGlobalSection
4860
GlobalSection(SolutionProperties) = preSolution
4961
HideSolutionNode = FALSE

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ Debug.WriteLine(DebugQueryVisitor.Run(result));
3232
Here is the parse result as shown from the `DebugQueryVisitor`
3333
```
3434
Group:
35-
Left - Term:
35+
Left - Term:
3636
TermMax: 2
3737
TermMin: 1
3838
MinInclusive: True
3939
MaxInclusive: True
40-
Field:
40+
Field:
4141
Name: field
4242
```
4343

@@ -80,7 +80,7 @@ System.Diagnostics.Debug.Assert(query == generatedQuery);
8080
- Automatically resolves non-analyzed keyword sub-fields for sorting and aggregations
8181
- Aliases can be defined right on your NEST mappings
8282
- Supports both root and inner field name aliases
83-
84-
## Thanks to all the people who have contributed
8583

84+
## Thanks to all the people who have contributed
85+
8686
[![contributors](https://contributors-img.web.app/image?repo=FoundatioFx/Foundatio.Parsers)](https://github.com/FoundatioFx/Foundatio.Parsers/graphs/contributors)

build/common.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard2.0</TargetFrameworks>
4+
<TargetFrameworks>netstandard2.0;</TargetFrameworks>
55
<Product>Foundatio.Parsers</Product>
66
<Description>A lucene style query parser that is extensible and allows additional syntax features.</Description>
77
<PackageProjectUrl>https://github.com/FoundatioFx/Foundatio.Parsers</PackageProjectUrl>

docker-compose.yml

+21
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,27 @@ services:
2222
networks:
2323
- foundatio
2424

25+
sqlserver:
26+
image: mcr.microsoft.com/azure-sql-edge:1.0.7
27+
ports:
28+
- "1433:1433" # login with sa:P@ssword1
29+
environment:
30+
- "ACCEPT_EULA=Y"
31+
- "SA_PASSWORD=P@ssword1"
32+
- "MSSQL_PID=Developer"
33+
healthcheck:
34+
test:
35+
[
36+
"CMD",
37+
"/opt/mssql-tools/bin/sqlcmd",
38+
"-Usa",
39+
"-PP@ssword1",
40+
"-Q",
41+
"select 1",
42+
]
43+
interval: 1s
44+
retries: 20
45+
2546
ready:
2647
image: andrewlock/wait-for-dependencies
2748
command: elasticsearch:9200

src/Foundatio.Parsers.ElasticQueries/Foundatio.Parsers.ElasticQueries.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<PackageReference Include="Exceptionless.DateTimeExtensions" Version="3.4.3" />
55
<PackageReference Include="NEST" Version="7.17.5" />
66
<PackageReference Include="System.Text.Json" Version="8.0.4" />
7-
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0" />
7+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0" />
88
</ItemGroup>
99
<ItemGroup>
1010
<ProjectReference Include="..\Foundatio.Parsers.LuceneQueries\Foundatio.Parsers.LuceneQueries.csproj" />

src/Foundatio.Parsers.LuceneQueries/Nodes/ExistsNode.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public override string ToString()
4545
builder.Append(Prefix);
4646
builder.Append("_exists_");
4747
builder.Append(":");
48-
builder.Append(this.Field);
48+
builder.Append(Field);
4949

5050
return builder.ToString();
5151
}

src/Foundatio.Parsers.LuceneQueries/Nodes/MissingNode.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public override string ToString()
4545
builder.Append(Prefix);
4646
builder.Append("_missing_");
4747
builder.Append(":");
48-
builder.Append(this.Field);
48+
builder.Append(Field);
4949

5050
return builder.ToString();
5151
}

src/Foundatio.Parsers.LuceneQueries/Visitors/IncludeVisitor.cs

+7-5
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ public class IncludeVisitor : ChainableMutatingQueryVisitor
1313
{
1414
private readonly LuceneQueryParser _parser = new();
1515
private readonly ShouldSkipIncludeFunc _shouldSkipInclude;
16+
private readonly string _includeName;
1617

17-
public IncludeVisitor(ShouldSkipIncludeFunc shouldSkipInclude = null)
18+
public IncludeVisitor(ShouldSkipIncludeFunc shouldSkipInclude = null, string includeName = "include")
1819
{
1920
_shouldSkipInclude = shouldSkipInclude;
21+
_includeName = includeName;
2022
}
2123

2224
public override async Task<IQueryNode> VisitAsync(TermNode node, IQueryVisitorContext context)
2325
{
24-
if (node.Field != "@include" || (_shouldSkipInclude != null && _shouldSkipInclude(node, context)))
26+
if (node.Field != "@" + _includeName || (_shouldSkipInclude != null && _shouldSkipInclude(node, context)))
2527
return node;
2628

2729
var includeResolver = context.GetIncludeResolver();
@@ -34,7 +36,7 @@ public override async Task<IQueryNode> VisitAsync(TermNode node, IQueryVisitorCo
3436
var includeStack = context.GetIncludeStack();
3537
if (includeStack.Contains(node.Term))
3638
{
37-
context.AddValidationError($"Recursive include ({node.Term})");
39+
context.AddValidationError($"Recursive {_includeName} ({node.Term})");
3840
return node;
3941
}
4042

@@ -43,7 +45,7 @@ public override async Task<IQueryNode> VisitAsync(TermNode node, IQueryVisitorCo
4345
string includedQuery = await includeResolver(node.Term).ConfigureAwait(false);
4446
if (includedQuery == null)
4547
{
46-
context.AddValidationError($"Unresolved include ({node.Term})");
48+
context.AddValidationError($"Unresolved {_includeName} ({node.Term})");
4749
context.GetValidationResult().UnresolvedIncludes.Add(node.Term);
4850
}
4951

@@ -62,7 +64,7 @@ public override async Task<IQueryNode> VisitAsync(TermNode node, IQueryVisitorCo
6264
}
6365
catch (Exception ex)
6466
{
65-
context.AddValidationError($"Error in include resolver callback when resolving include ({node.Term}): {ex.Message}");
67+
context.AddValidationError($"Error in {_includeName} resolver callback when resolving {_includeName} ({node.Term}): {ex.Message}");
6668
context.GetValidationResult().UnresolvedIncludes.Add(node.Term);
6769

6870
return node;

src/Foundatio.Parsers.LuceneQueries/Visitors/ValidationVisitor.cs

+9-6
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public override void Visit(TermNode node, IQueryVisitorContext context)
3333
AddOperation(validationResult, node.GetOperationType(), node.Field);
3434

3535
var validationOptions = context.GetValidationOptions();
36-
if (validationOptions != null && !validationOptions.AllowLeadingWildcards && node.Term != null && (node.Term.StartsWith("*") || node.Term.StartsWith("?")))
36+
if (validationOptions is { AllowLeadingWildcards: false } && node.Term != null && (node.Term.StartsWith("*") || node.Term.StartsWith("?")))
3737
context.AddValidationError("Terms must not start with a wildcard: " + node.Term);
3838
}
3939

@@ -72,7 +72,7 @@ private void AddField(QueryValidationResult validationResult, IFieldQueryNode no
7272
}
7373
else
7474
{
75-
var fields = node.GetDefaultFields(context.DefaultFields);
75+
string[] fields = node.GetDefaultFields(context.DefaultFields);
7676
if (fields == null || fields.Length == 0)
7777
validationResult.ReferencedFields.Add("");
7878
else
@@ -120,11 +120,14 @@ internal async Task ApplyQueryRestrictions(IQueryVisitorContext context)
120120

121121
if (options.AllowedFields.Count > 0 && result.ReferencedFields.Count > 0)
122122
{
123-
var nonAllowedFields = result.ReferencedFields.Where(f => !String.IsNullOrEmpty(f)).Distinct().ToList();
124-
foreach (var field in options.AllowedFields)
123+
var nonAllowedFields = new List<string>();
124+
foreach (var field in result.ReferencedFields)
125125
{
126-
if (nonAllowedFields.Any(f => !String.IsNullOrEmpty(f) && field.Equals(f)))
127-
nonAllowedFields.Remove(field);
126+
if (String.IsNullOrWhiteSpace(field))
127+
continue;
128+
129+
if (!options.AllowedFields.Contains(field, StringComparer.OrdinalIgnoreCase))
130+
nonAllowedFields.Add(field);
128131
}
129132
if (nonAllowedFields.Count > 0)
130133
context.AddValidationError($"Query uses field(s) ({String.Join(",", nonAllowedFields)}) that are not allowed to be used.");

0 commit comments

Comments
 (0)