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

Issue with search in array using another array #453

Open
Sarletor opened this issue Jun 19, 2024 · 1 comment
Open

Issue with search in array using another array #453

Sarletor opened this issue Jun 19, 2024 · 1 comment

Comments

@Sarletor
Copy link

Right now it's impossible (workaround?) to use Any(Contains) construction.

Code example:

public void TestArrayContainsArray()
{
    _substitute.ClearSubstitute();
    _substitute.Execute(Arg.Any<string>(), Arg.Any<object[]>()).Returns(_mockReply);

    var array = new[] { "Steve" };
    var collection = new RedisCollection<Person>(_substitute, 1000);
    _ = collection.Where(x => array.Any(x.NickNames.Contains)).ToList();
    _substitute.Received().Execute(
        "FT.SEARCH",
        "person-idx",
        "(@NickNames:{Steve})",
        "LIMIT",
        "0",
        "1000"
    );
}

Exception

System.InvalidCastException
Unable to cast object of type 'System.Linq.Expressions.UnaryExpression' to type 'System.Linq.Expressions.LambdaExpression'.
   at Redis.OM.Common.ExpressionParserUtilities.TranslateAnyForEmbeddedObjects(MethodCallExpression exp, List`1 parameters) in C:\Projects\redis-om-dotnet\src\Redis.OM\Common\ExpressionParserUtilities.cs:line 962
   at Redis.OM.Common.ExpressionParserUtilities.TranslateMethodExpressions(MethodCallExpression exp, List`1 parameters) in C:\Projects\redis-om-dotnet\src\Redis.OM\Common\ExpressionParserUtilities.cs:line 199
   at Redis.OM.Common.ExpressionTranslator.BuildQueryFromExpression(Expression exp, List`1 parameters) in C:\Projects\redis-om-dotnet\src\Redis.OM\Common\ExpressionTranslator.cs:line 767
   at Redis.OM.Common.ExpressionTranslator.TranslateWhereMethod(MethodCallExpression expression, List`1 parameters) in C:\Projects\redis-om-dotnet\src\Redis.OM\Common\ExpressionTranslator.cs:line 800
   at Redis.OM.Common.ExpressionTranslator.BuildQueryFromExpression(Expression expression, Type type, Expression mainBooleanExpression, Type rootType) in C:\Projects\redis-om-dotnet\src\Redis.OM\Common\ExpressionTranslator.cs:line 232
   at Redis.OM.Searching.RedisCollectionEnumerator`1..ctor(Expression exp, IRedisConnection connection, Int32 chunkSize, RedisCollectionStateManager stateManager, Expression`1 booleanExpression, Boolean saveState, Type rootType, Type type) in C:\Projects\redis-om-dotnet\src\Redis.OM\Searching\RedisCollectionEnumerator.cs:line 50
   at Redis.OM.Searching.RedisCollection`1.GetEnumerator() in C:\Projects\redis-om-dotnet\src\Redis.OM\Searching\RedisCollection.cs:line 563
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Redis.OM.Unit.Tests.RediSearchTests.SearchTests.TestArrayContainsArray() in C:\Projects\redis-om-dotnet\test\Redis.OM.Unit.Tests\RediSearchTests\SearchTests.cs:line 918
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
@abbottdev
Copy link
Contributor

I think this is currently a limitation of the library, it is probably possible to build what you want but it would not be super performant - i.e. how many values would you allow NickNames to have?

The error message should probably be better, like a NotImplementedException, but I also agree the library should probably add support for this somehow.

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

No branches or pull requests

2 participants