-
-
Notifications
You must be signed in to change notification settings - Fork 527
Description
Hey there,
First off, just wanted to apologize in advance if I'm completely missing something here as I'm not super familiar with how Postgres' built-in text search functions work under the hood.
I'm currently messing around with using Marten in an F# project and I had a quick question on an issue I'm running into. I'm currently trying to use full text searching with an F# record representing an aggregate with this structure:
[<CLIMutable>]
type MealAggregate =
{ Id: Guid
Name: string
Protein: string option
Source: string option
Created: DateTime
Updated: DateTime option
Deleted: DateTime option }Everything standard with regards to writing and retrieving the data is working as expected. I'm using inline projections and the row is being written correctly to mt_doc_mealaggregate (FSharp.SystemTextJson is being used for serialization of F# types).
My problem is with searching against one specific field of the record. My search functionality is currently written as such:
let private getNonDeletedItemsQuery<'T> (session: IQuerySession) =
query {
for aggregate in session.Query<'T>() do
where (aggregate.MatchesSql("data->> 'Deleted' IS NULL"))
select aggregate
}
let search<'T> (documentStore: DocumentStore) (text: string option) =
let session = documentStore.QuerySession()
let queryable = getNonDeletedItemsQuery<'T> session
let result =
match text with
| Some parameter ->
query {
for aggregate in queryable do
where (aggregate.WebStyleSearch(parameter))
select aggregate
}
| None -> queryable
task {
let! aggregates = result.ToListAsync()
return aggregates |> Seq.toList
}As you can see, I'm trying to run a WebStyleSearch on the aggregate record. My problem is that virtually every field of the aggregate is searchable except for the Source field which specifically contains URL's.
Here's an example of a stored projection:
{
"Id": "402680f5-b29c-4136-be1b-22866a3e4314",
"Name": "Greek Chicken",
"Source": "https://example-recipes.com/greek-chicken",
"Created": "2024-08-15T19:04:51.009561Z",
"Deleted": null,
"Protein": "Chicken",
"Updated": "2024-08-15T19:06:19.331963Z"
}So in the example above, searching for "greek" would return the record, while searching for "recipes" would not. I thought it might be a problem with F# Option types, but the Protein field is also an option and searching on that works fine as well.
I wanted to check if I was potentially missing some additional configuration or if this might be a limitation of Postgres that I'm not familiar with?
Also, in case it's helpful, here's the creation of my DocumentStore:
DocumentStore.For(fun options ->
options.Connection(connectionString)
options.AutoCreateSchemaObjects <- AutoCreate.All
// Projections
options.Projections.Snapshot<MealAggregate> SnapshotLifecycle.Inline |> ignore
// Schema
options.Schema.For<MealAggregate>().FullTextIndex() |> ignore
let serializer = Services.SystemTextJsonSerializer()
serializer.Configure(fun options -> options.Converters.Add(JsonFSharpConverter()))
options.Serializer serializer)Thanks in advance!