redis / redis-om-dotnet

Object mapping, and more, for Redis and .NET
MIT License
468 stars 79 forks source link

QueryFlags - An item with the same key has already been added #310

Open mitjaahlin opened 1 year ago

mitjaahlin commented 1 year ago

Hi, while testing Redis.OM library we bumped into the problem with internal logic of SearchResponse.

Adding WithScores query flag to SearchAsync causes internal dictionary to try break if two documents have the same score. var query = new RedisQuery("companies"); query.QueryText = ($"(@LastName:%{lastName}%)|(@FirstName:%{firstName}%)|(@Aliases:%{aliases}%)"); query.Flags = (long)QueryFlags.WithScores; var companies = await _client.Connection.SearchAsync<Company>(query);

An item with the same key has already been added. Key: 38 System.ArgumentException: An item with the same key has already been added. Key: 38 at System.Collections.Generic.Dictionary.TryInsert(TKey key, TValue value, InsertionBehavior behavior) at System.Collections.Generic.Dictionary.Add(TKey key, TValue value) at Redis.OM.Searching.SearchResponse..ctor(RedisReply val) at Redis.OM.RediSearchCommands.SearchAsync[T](IRedisConnection connection, RedisQuery query)

slorello89 commented 1 year ago

Hmm interesting, yeah this is using the raw Search API(which admittedly isn't fully tested outside what we do with LINQ expressions), I suspect there's something a bit different about the way the result is formatted coming back from RediSearch that's causing this to break like this - will have to dig into it. Thanks for bringing this to my attention @mitjaahlin