Skip to content

Commit 7e2a366

Browse files
Fix whitespaces.
1 parent 35360a2 commit 7e2a366

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

backend/src/Squidex.Data.EntityFramework/Providers/Postgres/PostgresDialect.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@ public override string OrderBy(PropertyPath path, SortOrder order, bool isJson)
5353

5454
public override string WhereMatch(PropertyPath path, string query, SqlParams queryParameters)
5555
{
56-
var searchTerm = query.Replace(" ", " & ", StringComparison.Ordinal);
56+
if (query.Contains(' ', StringComparison.OrdinalIgnoreCase))
57+
{
58+
query = query.Replace(" ", " & ", StringComparison.Ordinal);
59+
}
5760

58-
return $"to_tsvector('simple', {FormatField(path, false)}) @@ to_tsquery({queryParameters.AddPositional(searchTerm)})";
61+
return $"to_tsvector('simple', {FormatField(path, false)}) @@ to_tsquery({queryParameters.AddPositional(query)})";
5962
}
6063

6164
public override string Where(PropertyPath path, CompareOperator op, ClrValue value, SqlParams queryParameters, bool isJson)

backend/src/Squidex.Data.EntityFramework/Providers/SqlServer/SqlServerDialect.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ public override string OrderBy(PropertyPath path, SortOrder order, bool isJson)
7575

7676
public override string WhereMatch(PropertyPath path, string query, SqlParams queryParameters)
7777
{
78+
if (query.Contains(' ', StringComparison.OrdinalIgnoreCase))
79+
{
80+
query = $"\"{query}\"";
81+
}
82+
7883
return $"CONTAINS({FormatField(path, false)}, {queryParameters.AddPositional(query)})";
7984
}
8085

backend/tests/Squidex.Data.Tests/EntityFramework/Infrastructure/Queries/EFQueryTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,21 @@ public async Task Should_query_full_text()
510510
Assert.Equal(20, dbResult.Count);
511511
}
512512

513+
[Fact]
514+
public async Task Should_query_full_text_with_space()
515+
{
516+
var builder =
517+
new TestSqlBuilder(fixture.Dialect, "TestEntity")
518+
.WhereMatch("FullText", "hello world");
519+
520+
var (sql, parameters) = builder.Compile();
521+
522+
var dbContext = await CreateAndPrepareDbContextAsync();
523+
var dbResult = await PollAsync(dbContext, sql, parameters, 0);
524+
525+
Assert.Empty(dbResult);
526+
}
527+
513528
private static long[] Range(int from, int to)
514529
{
515530
var result = new List<long>();

0 commit comments

Comments
 (0)