I am trying to find all posts in RavenDB containing a word (index is there)
Here is a query that works, finds everything that starts with 'Liv'
let post = query {
for post in session.Query<MyType>() do
where (post.Text.StartsWith("Liv"))
select post
}
An attempt to use string.Contains() method as condition of Where closure, will throw NotSupportedException. Here
So I am trying to use Search method where:
Expression<Func<T, object>> fieldSelector,
// Expression marking a field in which terms should be looked for.
C# equivalent from docs:
List<User> users = session
.Query<User>("Users/ByNameAndHobbies")
.Search(x => x.Name, "Adam")
.Search(x => x.Hobbies, "sport")
.ToList();
My first try was to go with
let x = session.Query<MyType>(index).Search((fun xe -> xe.Text ), "Liv")
But getting error because it expects object out. Tried to downcast String to Object (what a strange idea), but getting:
Cannot understand how to translate x => x.Invoke(xe)
At the moment, I am out of ideas. I am supposed to mark field for search and return object. Any ideas?
Thank you.
EDIT 1: My expression. Gets runtime InvalidCastException because it can't cast string to obj.
let expr =
<@ Func<MyType, _>(fun xe -> xe.Text ) @>
|> LeafExpressionConverter.QuotationToExpression
|> unbox<System.Linq.Expressions.Expression<Func<MyType, _>>>