What is the correct syntax for RavenDB Search method in F# -
i trying find posts in ravendb containing word (index there)
here query works, finds starts 'liv'
let post = query { post in session.query<mytype>() (post.text.startswith("liv")) select post }
an attempt use string.contains() method condition of closure, throw notsupportedexception. here
so trying use search method where:
expression<func<t, object>> fieldselector, // expression marking field in terms should looked for.
c# equivalent docs:
list<user> users = session .query<user>("users/bynameandhobbies") .search(x => x.name, "adam") .search(x => x.hobbies, "sport") .tolist();
my first try go with
let x = session.query<mytype>(index).search((fun xe -> xe.text ), "liv")
but getting error because expects object out. tried downcast string object (what strange idea), getting:
cannot understand how translate x => x.invoke(xe)
at moment, out of ideas. supposed mark field search , return object. ideas?
thank you.
edit 1: expression. gets runtime invalidcastexception because can't cast string obj.
let expr = <@ func<mytype, _>(fun xe -> xe.text ) @> |> leafexpressionconverter.quotationtoexpression |> unbox<system.linq.expressions.expression<func<mytype, _>>>
you mentioned tried casting string
object
. tried using :> obj
, work.
here working query:
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
Comments
Post a Comment