Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
VagyokC4 opened this issue Aug 21, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@VagyokC4
Copy link

VagyokC4 commented Aug 21, 2022

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?

@frostshoxx
Copy link
Contributor

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.

@VagyokC4
Copy link
Author

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 VagyokC4 changed the title Contains only searches inside string[], not List<string>() or HashSet<string>() Contains only searches inside string[] & List<string>() NOT HashSet<string>() Aug 22, 2022
@slorello89
Copy link
Member

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.

@VagyokC4
Copy link
Author

VagyokC4 commented Aug 22, 2022

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>.

@slorello89 slorello89 added the enhancement New feature or request label Oct 27, 2022
@VagyokC4
Copy link
Author

VagyokC4 commented Aug 12, 2023

@slorello89 Bumped into this again the other day. I'm expecting a HashSet<string> to be treated just like a List<string> when I index and query it, but I get no results back using HashSet<string>. Once I change it to List<string> I get results back.

Can we add HashSet<string> to the collection types we support for indexing/querying? I would think this is pretty low hanging fruit.

EDIT: If we can target IEnumerable<string> that would be even better and more inclusive of the various array like properties. Is there any reason not to support this for querying?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants