Question on FullTextSearch with field containing URL in F# #3395
Replies: 3 comments
-
If your using web style search then I would suggest having a look at Under the hood the full text index in postgres tokenises the indexed value. It does break apart urls, but I don't believe it does so in a way that would support your search use case e.g.
Will tokenise as:
None of those will match on a search term of In this instance you might want to change your approach to combine a free-text search with a |
Beta Was this translation helpful? Give feedback.
-
@bittercoder Thanks a ton for the response. With regards to your last suggestion of tweaking the index for the For what it's worth, I tried adding a calculated index to that field just to test it out: let getSourceIndex = FunctionAs.LinqExpression<MealAggregate, obj> (fun (aggregate: MealAggregate) ->
match aggregate.Source with
| Some source ->
Regex.Replace(source, @"[\W_]+", " ") |> box
| None -> "" |> box)
options.Schema.For<MealAggregate>().Index(getSourceIndex, (fun x -> x.Name <- "test_index")) |> ignore (The compiler wasn't playing nicely with automatically converting the F# function to a LINQ expression so I had to do it) The index creation succeeded, but resulted in the following: CREATE INDEX IF NOT EXISTS test_index
ON public.mt_doc_mealaggregate USING btree
("((data -> 'Source'::text) ->> 'Value'::text)" COLLATE pg_catalog."default" ASC NULLS LAST)
TABLESPACE pg_default; which doesn't look like it's completing the Regex transformation I need. I don't see any examples for creating indexes in the docs outside of relatively simple property selection ( Either way, greatly appreciate your help. |
Beta Was this translation helpful? Give feedback.
-
I was more meaning changing the how the fulltext index statement is generated, here's a rough C# example that should hopefully help:
I haven't tested the above code, so there may well be problems - but hopefully this is enough to help you find a potential solution. |
Beta Was this translation helpful? Give feedback.
-
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:
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:
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 theSource
field which specifically contains URL's.Here's an example of a stored projection:
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
:Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions