Skip to content

Commit fa80a84

Browse files
authored
crossed wires between inverted contains and infix (#413)
1 parent 13b0143 commit fa80a84

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/Redis.OM/Common/ExpressionParserUtilities.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,15 +833,21 @@ private static string TranslateContainsStandardQuerySyntax(MethodCallExpression
833833
}
834834

835835
type = Nullable.GetUnderlyingType(propertyExpression.Type) ?? propertyExpression.Type;
836+
var valueType = Nullable.GetUnderlyingType(valuesExpression.Type) ?? valuesExpression.Type;
836837
memberName = GetOperandStringForMember(propertyExpression);
837838
var treatEnumsAsInts = type.IsEnum && !(propertyExpression.Member.GetCustomAttributes(typeof(JsonConverterAttribute)).FirstOrDefault() is JsonConverterAttribute converter && converter.ConverterType == typeof(JsonStringEnumConverter));
838839
literal = GetOperandStringForQueryArgs(valuesExpression, treatEnumsAsInts);
839840

840-
if ((type == typeof(string) || type == typeof(string[]) || type == typeof(List<string>) || type == typeof(Guid) || type == typeof(Guid[]) || type == typeof(List<Guid>) || type == typeof(Ulid) || (type.IsEnum && !treatEnumsAsInts)) && attribute is IndexedAttribute)
841+
if ((valueType == typeof(List<string>) || valueType == typeof(string[]) || type == typeof(string[]) || type == typeof(List<string>) || type == typeof(Guid) || type == typeof(Guid[]) || type == typeof(List<Guid>) || type == typeof(Guid[]) || type == typeof(List<Guid>) || type == typeof(Ulid) || (type.IsEnum && !treatEnumsAsInts)) && attribute is IndexedAttribute)
841842
{
842843
return $"({memberName}:{{{EscapeTagField(literal).Replace("\\|", "|")}}})";
843844
}
844845

846+
if (type == typeof(string) && attribute is IndexedAttribute)
847+
{
848+
return $"({memberName}:{{*{EscapeTagField(literal)}*}})";
849+
}
850+
845851
if (type == typeof(string) && attribute is SearchableAttribute)
846852
{
847853
return $"({memberName}:{literal})";

test/Redis.OM.Unit.Tests/RediSearchTests/SearchTests.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ public void TestMatchEndsWith()
372372
"0",
373373
"100");
374374
}
375-
375+
376376
[Fact]
377377
public void TestMatchContains()
378378
{
@@ -390,6 +390,34 @@ public void TestMatchContains()
390390
"100");
391391
}
392392

393+
[Fact]
394+
public void TestTagContains()
395+
{
396+
_substitute.ClearSubstitute();
397+
_substitute.Execute(Arg.Any<string>(), Arg.Any<string[]>()).Returns(_mockReply);
398+
399+
var ste = "Ste";
400+
var person = new Person() { TagField = "ath" };
401+
var collection = new RedisCollection<Person>(_substitute);
402+
_ = collection.Where(x => x.TagField.Contains(ste)).ToList();
403+
_ = collection.Where(x => x.TagField.Contains(person.TagField)).ToList();
404+
_substitute.Received().Execute(
405+
"FT.SEARCH",
406+
"person-idx",
407+
"(@TagField:{*Ste*})",
408+
"LIMIT",
409+
"0",
410+
"100");
411+
412+
_substitute.Received().Execute(
413+
"FT.SEARCH",
414+
"person-idx",
415+
"(@TagField:{*ath*})",
416+
"LIMIT",
417+
"0",
418+
"100");
419+
}
420+
393421
[Fact]
394422
public void TestTagStartsWith()
395423
{

0 commit comments

Comments
 (0)