F# 中 RavenDB 搜索方法的正确语法是什么
What is the correct syntax for RavenDB Search method in F#
我正在尝试在 RavenDB 中查找所有包含单词的帖子(有索引)
这是一个有效的查询,查找以 '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
所以我正在尝试使用搜索方法,其中:
Expression<Func<T, object>> fieldSelector,
// Expression marking a field in which terms should be looked for.
来自文档的 C# 等价物:
List<User> users = session
.Query<User>("Users/ByNameAndHobbies")
.Search(x => x.Name, "Adam")
.Search(x => x.Hobbies, "sport")
.ToList();
我的第一次尝试是
let x = session.Query<MyType>(index).Search((fun xe -> xe.Text ), "Liv")
但是出现错误,因为它期望对象输出。试图将字符串向下转换为对象(多么奇怪的想法),但得到:
Cannot understand how to translate x => x.Invoke(xe)
此刻,我没主意了。我应该标记搜索字段和 return 对象。有什么想法吗?
谢谢。
编辑 1:
我的表情。获取运行时 InvalidCastException,因为它无法将字符串转换为 obj。
let expr =
<@ Func<MyType, _>(fun xe -> xe.Text ) @>
|> LeafExpressionConverter.QuotationToExpression
|> unbox<System.Linq.Expressions.Expression<Func<MyType, _>>>
您提到您尝试将 string
转换为 object
。我用 :> 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
我正在尝试在 RavenDB 中查找所有包含单词的帖子(有索引)
这是一个有效的查询,查找以 '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
所以我正在尝试使用搜索方法,其中:
Expression<Func<T, object>> fieldSelector,
// Expression marking a field in which terms should be looked for.
来自文档的 C# 等价物:
List<User> users = session
.Query<User>("Users/ByNameAndHobbies")
.Search(x => x.Name, "Adam")
.Search(x => x.Hobbies, "sport")
.ToList();
我的第一次尝试是
let x = session.Query<MyType>(index).Search((fun xe -> xe.Text ), "Liv")
但是出现错误,因为它期望对象输出。试图将字符串向下转换为对象(多么奇怪的想法),但得到:
Cannot understand how to translate x => x.Invoke(xe)
此刻,我没主意了。我应该标记搜索字段和 return 对象。有什么想法吗?
谢谢。
编辑 1: 我的表情。获取运行时 InvalidCastException,因为它无法将字符串转换为 obj。
let expr =
<@ Func<MyType, _>(fun xe -> xe.Text ) @>
|> LeafExpressionConverter.QuotationToExpression
|> unbox<System.Linq.Expressions.Expression<Func<MyType, _>>>
您提到您尝试将 string
转换为 object
。我用 :> 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