-
Notifications
You must be signed in to change notification settings - Fork 58
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
Add federated multisearch to MeilisearchClient #571
Open
apt-TebbeM
wants to merge
6
commits into
meilisearch:main
Choose a base branch
from
apt-TebbeM:federated-multisearch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6ce6924
add federated multisearch to MeilisearchClient.cs
apt-TebbeM b50817b
remove commented code in tests
apt-TebbeM 1597f9c
remove unused code
apt-TebbeM b9566c5
change function and class descriptions, removed some comments and mad…
apt-TebbeM 1ff060e
run dotnet format
apt-TebbeM bc3b89e
Merge branch 'main' into federated-multisearch
apt-TebbeM File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
MEILISEARCH_VERSION=v1.9.0 | ||
MEILISEARCH_VERSION=v1.10.0 | ||
PROXIED_MEILISEARCH=http://nginx/api/ | ||
MEILISEARCH_URL=http://meilisearch:7700 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/Meilisearch/Converters/AlwaysIncludeEmptyObjectConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Meilisearch.Converters | ||
{ | ||
/// <summary> | ||
/// Always include property in json. MultiSearchFederationOptions will be serialized as "{}" | ||
/// | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
Check warning on line 13 in src/Meilisearch/Converters/AlwaysIncludeEmptyObjectConverter.cs GitHub Actions / integration-tests
|
||
public class MultiSearchFederationOptionsConverter : JsonConverter<MultiSearchFederationOptions> | ||
{ | ||
public override MultiSearchFederationOptions Read(ref Utf8JsonReader reader, Type typeToConvert, | ||
JsonSerializerOptions options) | ||
{ | ||
return JsonSerializer.Deserialize<MultiSearchFederationOptions>(ref reader, options); | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, MultiSearchFederationOptions value, | ||
JsonSerializerOptions options) | ||
{ | ||
if (value == null || !HasAnyValueSet(value)) | ||
{ | ||
WriteEmptyObject(writer); | ||
} | ||
else | ||
{ | ||
var sanitizedOptions = | ||
RemoveSelfFromSerializerOptions(options); //Prevents getting stuck in a loop during serialization | ||
JsonSerializer.Serialize(writer, value, sanitizedOptions); | ||
} | ||
} | ||
|
||
private static JsonSerializerOptions RemoveSelfFromSerializerOptions(JsonSerializerOptions options) | ||
{ | ||
var sanitizedOptions = new JsonSerializerOptions(options); | ||
sanitizedOptions.Converters.Remove(sanitizedOptions.Converters.First(c => | ||
c.GetType() == typeof(MultiSearchFederationOptionsConverter))); | ||
return sanitizedOptions; | ||
} | ||
|
||
private static void WriteEmptyObject(Utf8JsonWriter writer) | ||
{ | ||
writer.WriteStartObject(); | ||
writer.WriteEndObject(); | ||
} | ||
|
||
private bool HasAnyValueSet(MultiSearchFederationOptions value) | ||
{ | ||
foreach (var property in | ||
value.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) | ||
{ | ||
var propertyValue = property.GetValue(value); | ||
var defaultValue = GetDefaultValue(property.PropertyType); | ||
|
||
if (!Equals(propertyValue, defaultValue)) | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private object GetDefaultValue(Type type) | ||
{ | ||
return type.IsValueType ? Activator.CreateInstance(type) : null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.Collections.Generic; | ||
using System.Text.Json.Serialization; | ||
|
||
using Meilisearch.Converters; | ||
|
||
namespace Meilisearch | ||
{ | ||
/// <summary> | ||
/// Search query used in federated multi-index search | ||
/// </summary> | ||
public class FederatedMultiSearchQuery | ||
{ | ||
/// <summary> | ||
/// Default constructor that ensures FederationOptions are always set | ||
/// </summary> | ||
public FederatedMultiSearchQuery() | ||
{ | ||
FederationOptions = new MultiSearchFederationOptions(); | ||
} | ||
|
||
/// <summary> | ||
/// The queries | ||
/// </summary> | ||
[JsonPropertyName("queries")] | ||
public List<FederatedSearchQuery> Queries { get; set; } | ||
|
||
/// <summary> | ||
/// The federated search query options | ||
/// </summary> | ||
[JsonInclude] | ||
[JsonPropertyName("federation")] | ||
[JsonConverter(typeof(MultiSearchFederationOptionsConverter))] | ||
public MultiSearchFederationOptions FederationOptions { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Meilisearch | ||
{ | ||
/// <summary> | ||
/// Search query for federated multi-index search | ||
/// </summary> | ||
public class FederatedSearchQuery : SearchQueryBase | ||
{ | ||
/// <summary> | ||
/// Federated search options | ||
/// </summary> | ||
[JsonPropertyName("federationOptions")] | ||
public MultiSearchFederationOptions FederationOptions { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just add the converter as an annotation?