The Task
So I am working in task to create a text search over a list of records in my PostgreSQL data base using ecto migrations.
The problem overview
The problem is that the full text search is working properly on my local machine but it does have severe problems when deployed to AWS.
for example if you search
Orang → you get many results among them “Orange juice”
but when you type more of the word it resets and has not results
Orange → Has 0 results
Setup
The schema I am trying to index and search on is
schema "ingredients" do
field :name, :string
end
The migration was taken from this tutorial and it looks like this:
def up do
execute """
ALTER TABLE ingredients
ADD COLUMN searchable tsvector
GENERATED ALWAYS AS (
setweight(to_tsvector('english', coalesce(name, '')), 'A')
) STORED;
"""
execute """
CREATE INDEX ingredient_searchable_idx ON ingredients USING gin(searchable);
"""
end
The search function looks like this:
from(i in Ingredient,
where:
i.category_id not in ^secondary_ids and
fragment(
"searchable @@ websearch_to_tsquery(?)",
^search_term
),
limit: 20,
order_by: {
:desc,
fragment(
"ts_rank_cd(searchable, websearch_to_tsquery(?), 4)",
^search_term
)
}
)
Postgres Version online: 13.15
Since the whole search task is working properly in when I run it from my local setup I keep hitting my head against the whole but I can’t find what to pursue to get some answers on this any direction is greatly appreciated
Cheers,