diff --git a/src/Typesense/TypesenseClient.cs b/src/Typesense/TypesenseClient.cs index e05ffff..44188fc 100644 --- a/src/Typesense/TypesenseClient.cs +++ b/src/Typesense/TypesenseClient.cs @@ -202,7 +202,7 @@ public async Task> ExportDocuments(string collection, ExportParameter var extraParameters = new List(); if (exportParameters.IncludeFields is not null) - extraParameters.Add($"include_fields={exportParameters.ExcludeFields}"); + extraParameters.Add($"include_fields={exportParameters.IncludeFields}"); if (exportParameters.FilterBy is not null) extraParameters.Add($"filter_by={exportParameters.FilterBy}"); if (exportParameters.ExcludeFields is not null) @@ -212,6 +212,7 @@ public async Task> ExportDocuments(string collection, ExportParameter var response = await Get($"/collections/{collection}/documents/export?{searchParameters}").ConfigureAwait(false); return response.Split('\n') + .Where(x => !string.IsNullOrWhiteSpace(x)) .Select((x) => JsonSerializer.Deserialize(x, _jsonNameCaseInsentiveTrue) ?? throw new ArgumentException("Null is not valid for documents")) .ToList(); diff --git a/test/Typesense.Tests/TypesenseClientTests.cs b/test/Typesense.Tests/TypesenseClientTests.cs index 8c8ce82..50f410f 100644 --- a/test/Typesense.Tests/TypesenseClientTests.cs +++ b/test/Typesense.Tests/TypesenseClientTests.cs @@ -370,6 +370,93 @@ public async Task Export_documents() response.OrderBy(x => x.Id).Should().BeEquivalentTo(expected); } + [Fact, TestPriority(8)] + public async Task Export_documents_filter_by_query() + { + var expected = new List + { + new Company + { + Id = "124", + CompanyName = "Stark Industries", + NumEmployees = 5215, + Country = "USA", + } + }; + + var response = await _client.ExportDocuments("companies", new ExportParameters { FilterBy = "id: [124]" }); + + response.OrderBy(x => x.Id).Should().BeEquivalentTo(expected); + } + + [Fact, TestPriority(8)] + public async Task Export_documents_include_fields() + { + var expected = new List + { + new Company + { + Id = "124", + CompanyName = "Stark Industries" + }, + new Company + { + Id = "125", + CompanyName = "Future Technology" + }, + new Company + { + Id = "126", + CompanyName = "Random Corp." + }, + new Company + { + Id = "999", + CompanyName = "Awesome A/S" + } + }; + + var response = await _client.ExportDocuments("companies", new ExportParameters { IncludeFields = "id,company_name" }); + + response.OrderBy(x => x.Id).Should().BeEquivalentTo(expected); + } + + [Fact, TestPriority(8)] + public async Task Export_documents_exclude_fields() + { + var expected = new List + { + new Company + { + Id = "124", + CompanyName = "Stark Industries", + Country = "USA", + }, + new Company + { + Id = "125", + CompanyName = "Future Technology", + Country = "UK", + }, + new Company + { + Id = "126", + CompanyName = "Random Corp.", + Country = "AU", + }, + new Company + { + Id = "999", + CompanyName = "Awesome A/S", + Country = "SWE", + } + }; + + var response = await _client.ExportDocuments("companies", new ExportParameters { ExcludeFields = "num_employees" }); + + response.OrderBy(x => x.Id).Should().BeEquivalentTo(expected); + } + [Fact, TestPriority(9)] public async Task Retrieve_document() {