F#中RavenDB搜索方法的正确语法是什么

Dim*_*mka 6 f# ravendb

我试图找到RavenDB中包含一个单词的所有帖子(索引就在那里)

这是一个有效的查询,找到以'Liv'开头的所有内容

let post = query {
    for post in session.Query<MyType>() do
    where (post.Text.StartsWith("Liv"))
    select post
}
Run Code Online (Sandbox Code Playgroud)

尝试使用string.Contains()方法作为Where闭包的条件,将抛出NotSupportedException. 这里

所以我试图使用搜索方法,其中:

Expression<Func<T, object>> fieldSelector, 
// Expression marking a field in which terms should be looked for.
Run Code Online (Sandbox Code Playgroud)

来自docs的C#等价物:

List<User> users = session
    .Query<User>("Users/ByNameAndHobbies")
    .Search(x => x.Name, "Adam")
    .Search(x => x.Hobbies, "sport")
    .ToList();
Run Code Online (Sandbox Code Playgroud)

我的第一次尝试就是去

let x = session.Query<MyType>(index).Search((fun xe -> xe.Text ), "Liv")
Run Code Online (Sandbox Code Playgroud)

但是因为它期望对象出错而得到错误.试图将String转换为Object(这是一个奇怪的想法),但得到:

无法理解如何翻译x => x.Invoke(xe)

目前,我没有想法.我应该为搜索和返回对象标记字段.有任何想法吗?

谢谢.

编辑1:我的表达.获取运行时InvalidCastException,因为它无法将字符串转换为obj.

let expr = 
  <@ Func<MyType, _>(fun xe -> xe.Text ) @>
  |> LeafExpressionConverter.QuotationToExpression 
  |> unbox<System.Linq.Expressions.Expression<Func<MyType, _>>>
Run Code Online (Sandbox Code Playgroud)

Jay*_*Jay 4

您提到您尝试将其强制转换stringobject. 我尝试使用它:> obj并且确实有效。

这是我的工作查询:

let expr = <@ Func<MyType,_>(fun x -> x.Text :> obj ) @>
                |> LeafExpressionConverter.QuotationToExpression
                |> unbox<Linq.Expressions.Expression<Func<MyType,_>>>
let events = session.Query<MyType>()
                .Search(expr, "Liv*", decimal 1, SearchOptions.Or, EscapeQueryOptions.AllowAllWildcards)
                |> List.ofSeq
Run Code Online (Sandbox Code Playgroud)