Skip to content

Commit

Permalink
Merge branch 'meilisearch:main' into language-settings-and-search-par…
Browse files Browse the repository at this point in the history
…ameter
  • Loading branch information
danFbach authored Jan 15, 2025
2 parents c0e50dc + c6810ca commit 2cb26f9
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 61 deletions.
39 changes: 16 additions & 23 deletions src/Meilisearch/Extensions/ObjectExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;

Expand Down Expand Up @@ -43,31 +42,25 @@ internal static string ToQueryString(this object source, BindingFlags bindingAtt

if (value != null)
{
var type = value.GetType();

if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List<>))
if (value is List<string> stringValue)
{
values.Add(key + "=" + string.Join(",", stringValue));
}
else if (value is List<int> intValue)
{
values.Add(key + "=" + string.Join(",", intValue));
}
else if (value is List<TaskInfoStatus> taskInfoStatusValue)
{
values.Add(key + "=" + string.Join(",", taskInfoStatusValue.Select(x => x.ToString())));
}
else if (value is List<TaskInfoType> taskInfoTypeValue)
{
var itemType = type.GetGenericArguments()[0];
if (itemType == typeof(string))
{
values.Add(key + "=" + string.Join(",", (List<string>)value));
}
else if (itemType == typeof(int))
{
values.Add(key + "=" + string.Join(",", (List<int>)value));
}
else if (itemType == typeof(TaskInfoStatus))
{
values.Add(key + "=" + string.Join(",", ((List<TaskInfoStatus>)value).Select(x => x.ToString())));
}
else if (itemType == typeof(TaskInfoType))
{
values.Add(key + "=" + string.Join(",", ((List<TaskInfoType>)value).Select(x => x.ToString())));
}
values.Add(key + "=" + string.Join(",", taskInfoTypeValue.Select(x => x.ToString())));
}
else if (value is DateTime)
else if (value is DateTime datetimeValue)
{
values.Add(key + "=" + Uri.EscapeDataString(((DateTime)value).ToString("yyyy-MM-dd'T'HH:mm:ss.fffzzz")));
values.Add(key + "=" + Uri.EscapeDataString(datetimeValue.ToString("yyyy-MM-dd'T'HH:mm:ss.fffzzz")));
}
else
{
Expand Down
10 changes: 5 additions & 5 deletions tests/Meilisearch.Tests/DocumentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public async Task BasicDocumentAdditionFromCsvStringInBatches()

var csvDocuments = await File.ReadAllTextAsync(Datasets.SongsCsvPath);
var tasks = (await index.AddDocumentsCsvInBatchesAsync(csvDocuments, 250)).ToList();
Assert.Equal(2, tasks.Count());
Assert.Equal(2, tasks.Count);
foreach (var u in tasks)
{
u.TaskUid.Should().BeGreaterOrEqualTo(0);
Expand Down Expand Up @@ -190,7 +190,7 @@ public async Task BasicDocumentAdditionFromCsvWithDelimiterInBatches()

var csvDocuments = await File.ReadAllTextAsync(Datasets.SongsCsvCustomDelimiterPath);
var tasks = (await index.AddDocumentsCsvInBatchesAsync(csvDocuments, 15, csvDelimiter: ';')).ToList();
Assert.Equal(2, tasks.Count());
Assert.Equal(2, tasks.Count);
foreach (var u in tasks)
{
u.TaskUid.Should().BeGreaterOrEqualTo(0);
Expand Down Expand Up @@ -218,7 +218,7 @@ public async Task BasicDocumentAdditionFromNdjsonStringInBatches()

var ndjsonDocuments = await File.ReadAllTextAsync(Datasets.SongsNdjsonPath);
var tasks = (await index.AddDocumentsNdjsonInBatchesAsync(ndjsonDocuments, 150)).ToList();
Assert.Equal(2, tasks.Count());
Assert.Equal(2, tasks.Count);
foreach (var u in tasks)
{
u.TaskUid.Should().BeGreaterOrEqualTo(0);
Expand Down Expand Up @@ -469,7 +469,7 @@ public async Task BasicDocumentUpdateFromCsvStringInBatches()

var csvDocuments = await File.ReadAllTextAsync(Datasets.SongsCsvPath);
var tasks = (await index.UpdateDocumentsCsvInBatchesAsync(csvDocuments, 250)).ToList();
Assert.Equal(2, tasks.Count());
Assert.Equal(2, tasks.Count);
foreach (var u in tasks)
{
u.TaskUid.Should().BeGreaterOrEqualTo(0);
Expand Down Expand Up @@ -505,7 +505,7 @@ public async Task BasicDocumentUpdateFromNdjsonStringInBatches()

var ndjsonDocuments = await File.ReadAllTextAsync(Datasets.SongsNdjsonPath);
var tasks = (await index.UpdateDocumentsNdjsonInBatchesAsync(ndjsonDocuments, 150)).ToList();
Assert.Equal(2, tasks.Count());
Assert.Equal(2, tasks.Count);
foreach (var u in tasks)
{
u.TaskUid.Should().BeGreaterOrEqualTo(0);
Expand Down
4 changes: 0 additions & 4 deletions tests/Meilisearch.Tests/IndexSwapTest.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;

using Microsoft.AspNetCore.WebUtilities;

using Xunit;

Expand Down
6 changes: 5 additions & 1 deletion tests/Meilisearch.Tests/Movie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class FormattedMovie

public string Genre { get; set; }

#pragma warning disable SA1300
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Naming convention used to match meilisearch.")]
public Movie _Formatted { get; set; }
}

Expand All @@ -57,6 +57,8 @@ public class MovieWithRankingScore
public string Name { get; set; }

public string Genre { get; set; }

[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Naming convention used to match meilisearch.")]
public double? _RankingScore { get; set; }
}

Expand All @@ -67,6 +69,8 @@ public class MovieWithRankingScoreDetails
public string Name { get; set; }

public string Genre { get; set; }

[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Naming convention used to match meilisearch.")]
public IDictionary<string, JsonElement> _RankingScoreDetails { get; set; }
}
}
1 change: 0 additions & 1 deletion tests/Meilisearch.Tests/MultiIndexSearchTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
Expand Down
3 changes: 0 additions & 3 deletions tests/Meilisearch.Tests/ObjectExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;

using Meilisearch.Converters;
using Meilisearch.Extensions;
using Meilisearch.QueryParameters;

Expand Down
12 changes: 12 additions & 0 deletions tests/Meilisearch.Tests/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"profiles": {
"Meilisearch.Tests": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:52605;http://localhost:52606"
}
}
}
10 changes: 5 additions & 5 deletions tests/Meilisearch.Tests/SearchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public async Task CustomSearchWithFilter()
});
movies.Hits.Should().NotBeEmpty();
movies.FacetDistribution.Should().BeNull();
Assert.Equal(2, movies.Hits.Count());
Assert.Equal(2, movies.Hits.Count);
Assert.Equal("12", movies.Hits.First().Id);
Assert.Equal("Star Wars", movies.Hits.First().Name);
Assert.Equal("SF", movies.Hits.First().Genre);
Expand Down Expand Up @@ -247,7 +247,7 @@ public async Task CustomSearchWithFilterArray()
});
movies.Hits.Should().NotBeEmpty();
movies.FacetDistribution.Should().BeNull();
Assert.Equal(2, movies.Hits.Count());
Assert.Equal(2, movies.Hits.Count);
Assert.Equal("12", movies.Hits.First().Id);
Assert.Equal("Star Wars", movies.Hits.First().Name);
Assert.Equal("SF", movies.Hits.First().Genre);
Expand All @@ -265,7 +265,7 @@ public async Task CustomSearchWithFilterMultipleArray()
});
movies.Hits.Should().NotBeEmpty();
movies.FacetDistribution.Should().BeNull();
Assert.Equal(2, movies.Hits.Count());
Assert.Equal(2, movies.Hits.Count);
Assert.Equal("12", movies.Hits.First().Id);
Assert.Equal("Star Wars", movies.Hits.First().Name);
Assert.Equal("SF", movies.Hits.First().Genre);
Expand Down Expand Up @@ -392,7 +392,7 @@ public async Task CustomSearchWithSort()
});
movies.Hits.Should().NotBeEmpty();
movies.FacetDistribution.Should().BeNull();
Assert.Equal(2, movies.Hits.Count());
Assert.Equal(2, movies.Hits.Count);
Assert.Equal("14", movies.Hits.First().Id);
}

Expand Down Expand Up @@ -494,7 +494,7 @@ public async Task CustomSearchWithMatchingStrategyLast()
var searchQuery = new SearchQuery() { MatchingStrategy = "last" };
var movies = await _nestedIndex.SearchAsync<MovieWithInfo>("movie about rich", searchQuery);

Assert.True(movies.Hits.Count() > 1);
Assert.True(movies.Hits.Count > 1);
}

[Fact]
Expand Down
4 changes: 1 addition & 3 deletions tests/Meilisearch.Tests/ServerConfigs/BaseUriServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ public class ConfigFixture : IndexFixture
{
public override string MeilisearchAddress()
{
var env = Environment.GetEnvironmentVariable("MEILISEARCH_URL");

return env == null ? MeilisearchTestAddress : env;
return Environment.GetEnvironmentVariable("MEILISEARCH_URL") ?? MeilisearchTestAddress;
}
}

Expand Down
4 changes: 1 addition & 3 deletions tests/Meilisearch.Tests/ServerConfigs/ProxiedUriServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ public class ConfigFixture : IndexFixture
{
public override string MeilisearchAddress()
{
var env = Environment.GetEnvironmentVariable("PROXIED_MEILISEARCH");

return env == null ? MeilisearchTestAddress : env;
return Environment.GetEnvironmentVariable("PROXIED_MEILISEARCH") ?? MeilisearchTestAddress;
}
}

Expand Down
23 changes: 11 additions & 12 deletions tests/Meilisearch.Tests/SettingsTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -11,14 +12,12 @@ namespace Meilisearch.Tests
public abstract class SettingsTests<TFixture> : IAsyncLifetime where TFixture : IndexFixture
{
private readonly Settings _defaultSettings;
private readonly MeilisearchClient _client;
private Index _index;
private readonly TFixture _fixture;

public SettingsTests(TFixture fixture)
{
_fixture = fixture;
_client = fixture.DefaultClient;

_defaultSettings = new Settings
{
Expand All @@ -34,19 +33,19 @@ public SettingsTests(TFixture fixture)
DistinctAttribute = null,
SearchableAttributes = new string[] { "*" },
DisplayedAttributes = new string[] { "*" },
Dictionary = new string[] { },
StopWords = new string[] { },
Dictionary = Array.Empty<string>(),
StopWords = Array.Empty<string>(),
SeparatorTokens = new List<string> { },
NonSeparatorTokens = new List<string> { },
Synonyms = new Dictionary<string, IEnumerable<string>> { },
FilterableAttributes = new string[] { },
SortableAttributes = new string[] { },
FilterableAttributes = Array.Empty<string>(),
SortableAttributes = Array.Empty<string>(),
ProximityPrecision = "byWord",
TypoTolerance = new TypoTolerance
{
Enabled = true,
DisableOnAttributes = new string[] { },
DisableOnWords = new string[] { },
DisableOnAttributes = Array.Empty<string>(),
DisableOnWords = Array.Empty<string>(),
MinWordSizeForTypos = new TypoTolerance.TypoSize
{
OneTypo = 5,
Expand Down Expand Up @@ -483,7 +482,7 @@ public async Task UpdateTypoTolerance()
var returnedTypoTolerance = new TypoTolerance
{
Enabled = true,
DisableOnAttributes = new string[] { },
DisableOnAttributes = Array.Empty<string>(),
DisableOnWords = new string[] { "harry", "potter" },
MinWordSizeForTypos = new TypoTolerance.TypoSize
{
Expand Down Expand Up @@ -541,7 +540,7 @@ public async Task ResetTypoTolerance()
var returnedTypoTolerance = new TypoTolerance
{
Enabled = true,
DisableOnAttributes = new string[] { },
DisableOnAttributes = Array.Empty<string>(),
DisableOnWords = new string[] { "harry", "potter" },
MinWordSizeForTypos = new TypoTolerance.TypoSize
{
Expand Down Expand Up @@ -734,13 +733,13 @@ private static Settings SettingsWithDefaultedNullFields(Settings inputSettings,
};
}

private async Task AssertGetEquality<TValue>(IndexGetMethod<TValue> getMethod, TValue expectedValue)
private static async Task AssertGetEquality<TValue>(IndexGetMethod<TValue> getMethod, TValue expectedValue)
{
var value = await getMethod();
value.Should().BeEquivalentTo(expectedValue);
}

private async Task AssertGetInequality<TValue>(IndexGetMethod<TValue> getMethod, TValue expectedValue)
private static async Task AssertGetInequality<TValue>(IndexGetMethod<TValue> getMethod, TValue expectedValue)
{
var value = await getMethod();
value.Should().NotBeEquivalentTo(expectedValue);
Expand Down
1 change: 0 additions & 1 deletion tests/Meilisearch.Tests/TaskInfoTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand Down

0 comments on commit 2cb26f9

Please sign in to comment.