Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Elastic Search #4998

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

rootDir=$(dirname "$0")

$rootDir/src/HotChocolate/AspNetCore/format.sh
$rootDir/src/HotChocolate/ApolloFederation/format.sh
$rootDir/src/HotChocolate/Data/format.sh
$rootDir/src/HotChocolate/MongoDb/format.sh
$rootDir/src/HotChocolate/ElasticSearch/format.sh
$rootDir/src/HotChocolate/Language/format.sh
$rootDir/src/HotChocolate/Stitching/format.sh
$rootDir/src/HotChocolate/Spatial/format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,29 @@ public static ISchemaBuilder AddFiltering(
this ISchemaBuilder builder,
Action<IFilterConventionDescriptor> configure,
string? name = null) =>
builder.AddFiltering(new FilterConvention(configure), name);

/// <summary>
/// Adds filtering support.
/// </summary>
/// <param name="builder">
/// The <see cref="ISchemaBuilder"/>.
/// </param>
/// <param name="convention">
/// The convention
/// </param>
/// <param name="name">
/// The filter convention name.
/// </param>
/// <returns>
/// Returns the <see cref="ISchemaBuilder"/>.
/// </returns>
public static ISchemaBuilder AddFiltering(
this ISchemaBuilder builder,
IFilterConvention convention,
string? name = null) =>
builder
.TryAddConvention<IFilterConvention>(sp => new FilterConvention(configure), name)
.TryAddConvention<IFilterConvention>(_ => convention, name)
.TryAddTypeInterceptor<FilterTypeInterceptor>();

/// <summary>
Expand Down
27 changes: 27 additions & 0 deletions src/HotChocolate/ElasticSearch/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/test/Data.Filters.SqlServer.Tests/bin/Debug/netcoreapp3.1/Data.Filters.SqlServer.Tests.dll",
"args": [],
"cwd": "${workspaceFolder}/test/Data.Filters.SqlServer.Tests",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
2 changes: 2 additions & 0 deletions src/HotChocolate/ElasticSearch/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
24 changes: 24 additions & 0 deletions src/HotChocolate/ElasticSearch/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "shell",
"args": [
"build",
// Ask dotnet build to generate full paths for file names.
"/property:GenerateFullPaths=true",
// Do not generate summary otherwise it leads to duplicate errors in Problems panel
"/consoleloggerparameters:NoSummary"
],
"group": "build",
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$msCompile"
}
]
}
14 changes: 14 additions & 0 deletions src/HotChocolate/ElasticSearch/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)..\'))" />

<PropertyGroup>
<TargetFrameworks>$(Library2TargetFrameworks)</TargetFrameworks>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<NoWarn>$(NoWarn);CA1062</NoWarn>
<WarningsAsErrors>$(WarningsAsErrors);nullable</WarningsAsErrors>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NeutralLanguage>en</NeutralLanguage>
</PropertyGroup>

</Project>
46 changes: 46 additions & 0 deletions src/HotChocolate/ElasticSearch/HotChocolate.ElasticSearch.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.1.32421.90
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{AED4D809-DEB0-4C6E-AC73-C90863899233}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotChocolate.Data.ElasticSearch.Driver", "src\Data.ElasticSearch.Driver\HotChocolate.Data.ElasticSearch.Driver.csproj", "{B77A0EAE-BEE6-43FA-9D50-5F14B983185A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotChocolate.Data.ElasticSearch", "src\Data.ElasticSearch\HotChocolate.Data.ElasticSearch.csproj", "{5E40AFDA-93CC-4806-880D-6A93537F19CB}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{FBB2FC8D-9373-471B-A0F2-C0AA21D254FC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotChocolate.Data.ElasticSearch.Tests", "test\Data.ElasticSearch.Tests\HotChocolate.Data.ElasticSearch.Tests.csproj", "{5139FD4D-D866-4291-847E-FEE7546EF544}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B77A0EAE-BEE6-43FA-9D50-5F14B983185A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B77A0EAE-BEE6-43FA-9D50-5F14B983185A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B77A0EAE-BEE6-43FA-9D50-5F14B983185A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B77A0EAE-BEE6-43FA-9D50-5F14B983185A}.Release|Any CPU.Build.0 = Release|Any CPU
{5E40AFDA-93CC-4806-880D-6A93537F19CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5E40AFDA-93CC-4806-880D-6A93537F19CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5E40AFDA-93CC-4806-880D-6A93537F19CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5E40AFDA-93CC-4806-880D-6A93537F19CB}.Release|Any CPU.Build.0 = Release|Any CPU
{5139FD4D-D866-4291-847E-FEE7546EF544}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5139FD4D-D866-4291-847E-FEE7546EF544}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5139FD4D-D866-4291-847E-FEE7546EF544}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5139FD4D-D866-4291-847E-FEE7546EF544}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{B77A0EAE-BEE6-43FA-9D50-5F14B983185A} = {AED4D809-DEB0-4C6E-AC73-C90863899233}
{5E40AFDA-93CC-4806-880D-6A93537F19CB} = {AED4D809-DEB0-4C6E-AC73-C90863899233}
{5139FD4D-D866-4291-847E-FEE7546EF544} = {FBB2FC8D-9373-471B-A0F2-C0AA21D254FC}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {66BE188D-3109-456B-B395-FA4E68642064}
EndGlobalSection
EndGlobal
9 changes: 9 additions & 0 deletions src/HotChocolate/ElasticSearch/format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

BASEDIR=$(dirname "$0")
src=$BASEDIR/src
test=$BASEDIR/test

dotnet format $src/Data.ElasticSearch
dotnet format $src/Data.ElasticSearch.Driver
dotnet format $test/Data.ElasticSearch.Tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace HotChocolate.Data.ElasticSearch.Attributes;

public sealed class ElasticSearchFieldNameAttribute : Attribute
{
public string Path { get; }

public ElasticSearchFieldNameAttribute(string path)
{
Path = path;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace HotChocolate.Data.ElasticSearch;

public class BoolOperation : ISearchOperation
{
public BoolOperation(
IReadOnlyList<ISearchOperation> must,
IReadOnlyList<ISearchOperation> should,
IReadOnlyList<ISearchOperation> mustNot,
IReadOnlyList<ISearchOperation> filter)
{
Must = must;
Should = should;
MustNot = mustNot;
Filter = filter;
}

public IReadOnlyList<ISearchOperation> Must { get; }

public IReadOnlyList<ISearchOperation> Should { get; }

public IReadOnlyList<ISearchOperation> MustNot { get; }

public IReadOnlyList<ISearchOperation> Filter { get; }

public static BoolOperation Create(
IReadOnlyList<ISearchOperation>? must = null,
IReadOnlyList<ISearchOperation>? should = null,
IReadOnlyList<ISearchOperation>? mustNot = null,
IReadOnlyList<ISearchOperation>? filter = null)
=> new(
must ?? Array.Empty<ISearchOperation>(),
should ?? Array.Empty<ISearchOperation>(),
mustNot ?? Array.Empty<ISearchOperation>(),
filter ?? Array.Empty<ISearchOperation>());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace HotChocolate.Data.ElasticSearch;

public enum ElasticSearchOperationKind
{
Filter,
Query
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace HotChocolate.Data.ElasticSearch;

public enum ElasticSearchSortDirection
{
Ascending,
Descending
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace HotChocolate.Data.ElasticSearch;

public class ElasticSearchSortOperation
{
public ElasticSearchSortOperation(string path, ElasticSearchSortDirection direction)
{
Direction = direction;
Path = path;
}

public ElasticSearchSortDirection Direction { get;}

public string Path { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace HotChocolate.Data.ElasticSearch;

public class ExistsOperation : ILeafSearchOperation
{
public ExistsOperation(string path, ElasticSearchOperationKind kind)
{
Path = path;
Kind = kind;
}

public string Path { get; }

public ElasticSearchOperationKind Kind { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace HotChocolate.Data.ElasticSearch;

public interface ILeafSearchOperation : ISearchOperation
{
ElasticSearchOperationKind Kind { get; }

string Path { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace HotChocolate.Data.ElasticSearch;

#pragma warning disable CA1040
public interface ISearchOperation
{
}
#pragma warning restore CA1040
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace HotChocolate.Data.ElasticSearch;

public class MatchOperation : ILeafSearchOperation
{
public MatchOperation(
string path,
ElasticSearchOperationKind kind,
string? value)
{
Path = path;
Value = value;
Kind = kind;
}

public string Path { get; }

public string? Value { get; }

public ElasticSearchOperationKind Kind { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace HotChocolate.Data.ElasticSearch;

public class RangeOperation<T> : ILeafSearchOperation
{
public RangeOperation(
string path,
ElasticSearchOperationKind kind)
{
Path = path;
Kind = kind;
}

public string Path { get; }

public T? GreaterThan { get; init; }

public T? LowerThan { get; init; }

public T? GreaterThanOrEquals { get; init; }

public T? LowerThanOrEquals { get; init; }

public ElasticSearchOperationKind Kind { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace HotChocolate.Data.ElasticSearch;

public class TermOperation : ILeafSearchOperation
{
public TermOperation(
string path,
ElasticSearchOperationKind kind,
object value)
{
Path = path;
Value = value;
Kind = kind;
}

public string Path { get; }

public object Value { get; }

public ElasticSearchOperationKind Kind { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace HotChocolate.Data.ElasticSearch;

public class WildCardOperation : ILeafSearchOperation
{
public WildCardOperation(
string path,
ElasticSearchOperationKind kind,
WildCardOperationKind wildCardOperationKind,
string value)
{
Path = path;
Value = value;
Kind = kind;
WildCardOperationKind = wildCardOperationKind;
}

public string Path { get; }

public string Value { get; }

public ElasticSearchOperationKind Kind { get; }

public WildCardOperationKind WildCardOperationKind { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace HotChocolate.Data.ElasticSearch;

public enum WildCardOperationKind
{
StartsWith,
EndsWith,
Contains
}
Loading