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

Contains only searches inside string[] & List<string>() NOT HashSet<string>()

Open VagyokC4 opened this issue 1 year ago • 5 comments

Hello @slorello89

Looking at the following example:

[Document(StorageType = StorageType.Json)]
public class Customer
{
    [RedisIdField] public Ulid Id { get; set; }
    [Indexed] public string FirstName { get; set; }
    [Indexed] public string LastName { get; set; }
    public string Email { get; set; }
    [Indexed(Sortable = true)] public int Age { get; set; }
    [Indexed] public string[] NickNames { get; set; }
}

// Find all customers with the nickname of Jim
customer.Where(x=>x.NickNames.Contains("Jim"));

This only works if the underlying type is string[]. Can we add List, and HashSet as acceptable types for this logic as well?

UPDATE: Tested and working with both List(), and HashSet(), but ONLY when I create the index as string[]. I.e. changing to this type got things working, then as I went back to test List and HashSet, both would still return results.

Once I reindex as Hashset, I lost functionality. Once I reindex as List or string[] I get functionality back.

So since it looks like I can get data back with my model as HashSet, maybe the issue is just in the index creation?

VagyokC4 avatar Aug 21 '22 17:08 VagyokC4

Have you confirmed that the index has those list and hashset fields defined in it?

I spent hours the other days trying to figure out why the search didn't work and turn out I had to delete and recreate the index to reflect the change from the ORM.

frostshoxx avatar Aug 21 '22 20:08 frostshoxx

Have you confirmed that the index has those list and hashset fields defined in it?

I spent hours the other days trying to figure out why the search didn't work and turn out I had to delete and recreate the index to reflect the change from the ORM.

Yeah. I was getting no results back using HashSet<string> and once I changed only the model to be string[] then I got results back.

VagyokC4 avatar Aug 22 '22 04:08 VagyokC4

Right, so List and string[] should both work, only reason I'd think to keep a hash-set out is that the data-type in Redis is not going to be a set, it's a going to be a JSON array, so the unordered/non-duplication policies of a hash-set will not be enforceable.

slorello89 avatar Aug 22 '22 16:08 slorello89

Right, so List and string[] should both work, only reason I'd think to keep a hash-set out is that the data-type in Redis is not going to be a set, it's a going to be a JSON array, so the unordered/non-duplication policies of a hash-set will not be enforceable.

@slorello89 Except that they will be enforced once the model is loaded and if it's resaved, any duplicates are automatically removed. Which is the effect I was going for. I think it should be indexed in addition to the string[] and List<string>.

VagyokC4 avatar Aug 22 '22 18:08 VagyokC4