Rails Postgresql - synonym dictionary somewhat not updating
NickName:Arty.Simon Ask DateTime:2014-01-08T04:45:10

Rails Postgresql - synonym dictionary somewhat not updating

I have a Rails4 app with Postgresql(PG_search) on a MAC. I created the synonym dictionary through rails migration. The synonym dictionary is somewhat working. Setup below

Migrations

CREATE TEXT SEARCH DICTIONARY custom_synonyms_for_keywords ( TEMPLATE = synonym, SYNONYMS = synonyms_for_keywords );
CREATE TEXT SEARCH CONFIGURATION simple_syns_keywords (copy=simple);
ALTER TEXT SEARCH CONFIGURATION simple_syns_keywords ALTER MAPPING FOR asciiword WITH custom_synonyms_for_keywords;

my_synonyms file:
fshk bim24os
fridge refrigerator
postgres pgsql
postgresql pgsql
indices index*

Controller

class Product < ActiveRecord::Base
   pg_search_scope :pg_search, against: :sku,
         using: {
           tsearch: { prefix: true, dictionary: "simple_syns_keywords" }
         }
end

When i run

Product.pg_search("fshk") # returns record of "bim24os"
Product.pg_search("fridge") # returns no record of "refrigerator"

But when i run this, it returns the correct value

SELECT ts_lexize('custom_synonyms_for_keywords', 'fshk');  # returns "bim24os"
SELECT ts_lexize('custom_synonyms_for_keywords', 'fridge');    # returns "refrigerator"

RESULTS

Product.pg_search("fshk")
   Product Load (3.0ms)  SELECT "products".*, ((ts_rank((to_tsvector('simple_syns_keywords', coalesce("products"."sku"::text, ''))), (to_tsquery('simple_syns_keywords', ''' ' || 'fshk' || ' ''' || ':*')), 0))) AS pg_search_rank FROM "products" WHERE (((to_tsvector('simple_syns_keywords', coalesce("products"."sku"::text, ''))) @@ (to_tsquery('simple_syns_keywords', ''' ' || 'fshk' || ' ''' || ':*')))) ORDER BY pg_search_rank DESC, "products"."id" ASC
=> #<ActiveRecord::Relation [#Product id: 1, sku: "BIM24OS"]

Product.pg_search("fridge")
   Product Load (1.8ms)  SELECT "products".*, ((ts_rank((to_tsvector('simple_syns_keywords', coalesce("products"."sku"::text, ''))), (to_tsquery('simple_syns_keywords', ''' ' || 'fridge' || ' ''' || ':*')), 0))) AS pg_search_rank FROM "products" WHERE (((to_tsvector('simple_syns_keywords', coalesce("products"."sku"::text, ''))) @@ (to_tsquery('simple_syns_keywords', ''' ' || 'fridge' || ' ''' || ':*')))) ORDER BY pg_search_rank DESC, "products"."id" ASC
=> ActiveRecord::Relation []

I'm i missing a step because i'm not sure why it's not working. Any help is appreciated.

Thanks

Copyright Notice:Content Author:「Arty.Simon」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/20981514/rails-postgresql-synonym-dictionary-somewhat-not-updating

More about “Rails Postgresql - synonym dictionary somewhat not updating” related questions

Rails Postgresql - synonym dictionary somewhat not updating

I have a Rails4 app with Postgresql(PG_search) on a MAC. I created the synonym dictionary through rails migration. The synonym dictionary is somewhat working. Setup below Migrations CREATE TEXT S...

Show Detail

Synonym DICTIONARY for `simple` language is not working

I am supposing that we can use this old recipe and only replace the language german to language simple (that is the "no language")... But it is not working. CREATE TEXT SEARCH DICTIONARY my_syn...

Show Detail

PostgreSQL: Usage synonym dictionary as table

Is it possible use (instead text file synonym dictionary) table with two columns? Synonym dictionary often changed, regenerate dictionary and replacement impossible.

Show Detail

Create synonym dictionary to add instead of replace words in PostgreSQL

I am building an application where I added a Full Text Search feature using PostgreSQL's built in FTS. The app lists Mutual Funds in India. In some cases, mutual fund companies get acquired and their

Show Detail

Multiple synonym dictionary matches in full-text searching

I am trying to do full-text searching in PostgreSQL 8.3. It worked splendidly, so I added in synonym matching (e.g. 'bob' == 'robert') using a synonym dictionary. That works great too. However, I've

Show Detail

Add dictionary file to postgresql docker container

I am using the postgresql docker image https://hub.docker.com/_/postgres/ To improve my full text search experience with a synonym dictionary according to http://www.postgresql.org/docs/9.5/inter...

Show Detail

How to create a synonym for a user in PostgreSQL

I am migrating this Oracle command to PostgreSQL: create view DBA_ha as select * from DBA_USER where username!='ha'; create synonym ha.DBA_USER for DBA_ha; Please suggest to me how I can migrate ...

Show Detail

Synonym words are not being stemmed correctly in text search

In PostgreSQL, I have a text search configuration with a synonym dictionary and then I use the english_stem file. The problem is that for example, I have the word 'tv' as a synonym for 'television'...

Show Detail

Lexicon dictionary for synonym words

There are few dictionaries available for natural language processing. Like positive, negative words dictionaries etc. Is there any dictionary available which contains list of synonym for all dict...

Show Detail

How to create a synonym for a table in PostgreSQL

I am migrating this Oracle command to PostgreSQL: CREATE SYNONYM &amp;user..emp FOR &amp;schema..emp; Please suggest to me how I can migrate the above command.

Show Detail