redis-om-dotnet icon indicating copy to clipboard operation
redis-om-dotnet copied to clipboard

Enumerable<string> is treated as a wildcard search

Open zulander1 opened this issue 1 year ago • 1 comments

I am not sure if this is intentional or not but when we execute this code, this generates"FT.SEARCH" "customer:idx" "(@LastName:{*No*})" "LIMIT" "0" "100" caused by this

I think we should add valueType == typeof(IEnumerable<string>) check here

Making to ToList() works fine as expected


using Redis.OM;
using Redis.OM.Modeling;

var provider = new RedisConnectionProvider("redis://localhost:6379");
provider.Connection.CreateIndex(typeof(CustomerModel));
var customers = provider.RedisCollection<CustomerModel>();

// Insert customer
customers.Insert(new CustomerModel()
{
    Id = 1,
    FirstName = "James",
    LastName = "Bond",
}, WhenKey.NotExists);

customers.Insert(new CustomerModel()
{
    Id = 2,
    FirstName = "Dr",
    LastName = "No",
}, WhenKey.NotExists);
var agents = (new[] { "No" }).AsEnumerable();
var materialized = customers.Where(f => agents.Contains(f.LastName)).ToList();
Console.WriteLine("");

[Document(StorageType = StorageType.Json, Prefixes = new[] { Prefix }, IndexName = Prefix + ":idx")]
public class CustomerModel
{
    public const string Prefix = "customer";

    [Indexed][RedisIdField] public int Id { get; set; }
    [Indexed] public string FirstName { get; set; }
    [Indexed] public string LastName { get; set; }
}
 

zulander1 avatar Jan 18 '24 04:01 zulander1

Wouldn't it be easier just to inverse the logic and replace these two line with this:


if (attribute is IndexedAttribute)
{
    if (valueType == typeof(string) && type == typeof(string))
    {
        return $"({memberName}:{{*{EscapeTagField(literal)}*}})";
    }

    return $"({memberName}:{{{EscapeTagField(literal).Replace("\\|", "|")}}})";
}

@slorello89, can't seem to clone the repo: Git failed with a fatal error.

src/Redis.OM.Vectorizers.AllMiniLML6V2/Resources/model.onnx: smudge filter lfs failed

Clone succeeded, but checkout failed.

You can inspect what was checked out with 'git status'

and retry with 'git restore --source=HEAD :/'

zulander1 avatar Jan 18 '24 13:01 zulander1