-
Notifications
You must be signed in to change notification settings - Fork 62
Add federated multisearch to MeilisearchClient #571
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
Open
apt-TebbeM
wants to merge
14
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 13 commits
Commits
Show all changes
14 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 093e63f
move converter to attribute, and remove static jsonOptions
apt-TebbeM 625bfcd
Merge branch 'main' into federated-multisearch
apt-TebbeM 22da0ba
run dotnet format
apt-TebbeM e973642
fix serialization issue
apt-TebbeM 8ece4e4
Merge branch 'main' into federated-multisearch
apt-TebbeM 1feea8e
Merge branch 'main' into federated-multisearch
apt-TebbeM fcf9073
run dotnet format
apt-TebbeM 38a88ad
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 hidden or 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 hidden or 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
72 changes: 72 additions & 0 deletions
72
src/Meilisearch/Converters/AlwaysIncludeEmptyObjectConverter.cs
This file contains hidden or 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,72 @@ | ||
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> | ||
public class MultiSearchFederationOptionsConverter : JsonConverter<MultiSearchFederationOptions> | ||
{ | ||
/// <summary> | ||
/// Would override the default read logic, but here we use the default | ||
/// </summary> | ||
/// <param name="reader"></param> | ||
/// <param name="typeToConvert"></param> | ||
/// <param name="options"></param> | ||
/// <returns></returns> | ||
public override MultiSearchFederationOptions Read(ref Utf8JsonReader reader, Type typeToConvert, | ||
JsonSerializerOptions options) | ||
{ | ||
return JsonSerializer.Deserialize<MultiSearchFederationOptions>(ref reader, options); | ||
} | ||
|
||
/// <summary> | ||
/// Write json for MultiSearchFederationOptions and include it always as empty object | ||
/// </summary> | ||
/// <param name="writer"></param> | ||
/// <param name="value"></param> | ||
/// <param name="options"></param> | ||
public override void Write(Utf8JsonWriter writer, MultiSearchFederationOptions value, | ||
JsonSerializerOptions options) | ||
{ | ||
if (value == null || !HasAnyValueSet(value)) | ||
{ | ||
WriteEmptyObject(writer); | ||
} | ||
else | ||
{ | ||
JsonSerializer.Serialize(writer, value); | ||
} | ||
} | ||
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 hidden or 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 hidden or 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 hidden or 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.
I don't see what problem does this converter solve
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.
The API requiers a empty "federation" object when calling the /multisearch endpoint this is to respond in the expected format:
When the empty object parameter is not included it responds in a totaly different way: