Skip to content

Commit

Permalink
fix split join tokens sending invalid type bool (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
runeanielsen authored Nov 12, 2022
1 parent ca2b235 commit 7a14795
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ executors:
auth:
username: $DOCKER_LOGIN
password: $DOCKER_ACCESSTOKEN
- image: typesense/typesense:0.23.0 # For integration testing
- image: typesense/typesense:0.23.1 # For integration testing
auth:
username: $DOCKER_LOGIN
password: $DOCKER_ACCESSTOKEN
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,5 +354,5 @@ dotnet test --filter Category=Integration
To enable running integration tests you can run Typesense in a docker container using the command below.

```sh
docker run -p 8108:8108 -v/tmp/data:/data typesense/typesense:0.23.0 --data-dir /data --api-key=key
docker run -p 8108:8108 -v/tmp/data:/data typesense/typesense:0.23.1 --data-dir /data --api-key=key
```
11 changes: 9 additions & 2 deletions src/Typesense/SearchParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@

namespace Typesense;

public enum SplitJoinTokenOption
{
Fallback,
Always,
Off
}

public record MultiSearchParameters : SearchParameters
{
/// <summary>
Expand Down Expand Up @@ -230,7 +237,7 @@ public record SearchParameters
/// Treat space as typo: search for q=basket ball if q=basketball is not found or vice-versa.
/// </summary>
[JsonPropertyName("split_join_tokens")]
public bool? SplitJoinTokens { get; set; }
public SplitJoinTokenOption? SplitJoinTokens { get; set; }

/// <summary>
/// If you have some overrides defined but want to disable all of them during
Expand Down Expand Up @@ -285,7 +292,7 @@ public record GroupedSearchParameters : SearchParameters
/// </summary>
[JsonPropertyName("group_by")]
public string GroupBy { get; set; }

/// <summary>
/// Maximum number of hits to be returned for every group. If the `group_limit` is
/// set as `K` then only the top K hits in each group are returned in the response.
Expand Down
12 changes: 11 additions & 1 deletion src/Typesense/TypesenseClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,17 @@ private static string CreateUrlSearchParameters(SearchParameters searchParameter
if (searchParameters.EnableOverrides is not null)
urlParameters += $"&enable_overrides={searchParameters.EnableOverrides.Value.ToString().ToLowerInvariant()}";
if (searchParameters.SplitJoinTokens is not null)
urlParameters += $"&split_join_tokens={searchParameters.SplitJoinTokens.Value.ToString().ToLowerInvariant()}";
{
var splitJoinTokensStringRepresentation = searchParameters.SplitJoinTokens switch
{
SplitJoinTokenOption.Fallback => "fallback",
SplitJoinTokenOption.Always => "always",
SplitJoinTokenOption.Off => "off",
_ => throw new ArgumentException($"Cannot handle value {searchParameters.SplitJoinTokens}")
};

urlParameters += $"&split_join_tokens={splitJoinTokensStringRepresentation}";
}
if (searchParameters.MaxCandiates is not null)
urlParameters += $"&max_candidates={searchParameters.MaxCandiates.Value.ToString().ToLowerInvariant()}";
if (searchParameters.FacetQueryNumberTypos is not null)
Expand Down
26 changes: 26 additions & 0 deletions test/Typesense.Tests/TypesenseClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,32 @@ public async Task Search_query_by_just_text()
}
}

[Fact, TestPriority(11)]
public async Task Search_query_by_just_text_with_split_join_tokens_set()
{
var expected = new Company
{
Id = "124",
CompanyName = "Stark Industries",
NumEmployees = 6000,
Country = "USA",
};

var query = new SearchParameters("Stark", "company_name")
{
SplitJoinTokens = SplitJoinTokenOption.Fallback
};

var response = await _client.Search<Company>("companies", query);

using (var scope = new AssertionScope())
{
response.Found.Should().Be(1);
response.Hits.First().Document.Should().BeEquivalentTo(expected);
}
}


[Fact, TestPriority(11)]
public async Task Search_query_by_two_fields()
{
Expand Down

0 comments on commit 7a14795

Please sign in to comment.