etianen / django-watson

Full-text multi-table search application for Django. Easy to install and use, with good performance.
BSD 3-Clause "New" or "Revised" License
1.21k stars 129 forks source link

Update `WATSON_POSTGRES_SEARCH_CONFIG` at each call of search method #248

Closed CuriousLearner closed 4 years ago

CuriousLearner commented 6 years ago

I'm trying to support English and Chinese search in a Django based backend.

I've made a separate config for supporting Chinese and it works well when using normal Postgres queries, but I did notice that using watson, it always picks up English and I'm not able to dynamically change the WATSON_POSTGRES_SEARCH_CONFIG based on what language I want the search to work in.

How do I accomplish this flow? Are there any more details needed?

etianen commented 6 years ago

Unfortunately, django-watson does not support multiple postgres search configs. It would be quite a refactor to do so.

On 7 June 2018 at 13:22, Sanyam Khurana notifications@github.com wrote:

I'm trying to support English and Chinese search in a Django based backend.

I've made a separate config for supporting Chinese and it works well when using normal Postgres queries, but I did notice that using watson, it always picks up English and I'm not able to dynamically change the WATSON_POSTGRES_SEARCH_CONFIG based on what language I want the search to work in.

How do I accomplish this flow? Are there any more details needed?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/etianen/django-watson/issues/248, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJFCHXF2-wuXYG1J4GZsemE73CVJlMxks5t6RsAgaJpZM4UeTYg .

CuriousLearner commented 6 years ago

@etianen Alright, I understand. I'm trying to do a refactor and I am able to pass the correct search config.

django.db.connection.queries shows me this result:

    {
        'sql': 'SELECT "watson_searchentry"."id", "watson_searchentry"."engine_slug", "watson_searchentry"."content_type_id", "watson_searchentry"."object_id", "watson_searchentry"."object_id_int", "watson_searchentry"."title", "watson_searchentry"."description", "watson_searchentry"."content", "watson_searchentry"."url", "watson_searchentry"."meta_encoded", (ts_rank_cd(watson_searchentry.search_tsv, to_tsquery(\'pg_catalog.english\', \'$$Awesome$$:*\'))) AS "watson_rank" FROM "watson_searchentry" WHERE ("watson_searchentry"."engine_slug" = \'default\' AND "watson_searchentry"."content_type_id" = 10 AND (search_tsv @@ to_tsquery(\'pg_catalog.english\', \'$$Awesome$$:*\'))) ORDER BY "watson_rank" DESC LIMIT 21',
        'time': '0.001'
    },
    {
        'sql': 'SELECT "watson_searchentry"."id", "watson_searchentry"."engine_slug", "watson_searchentry"."content_type_id", "watson_searchentry"."object_id", "watson_searchentry"."object_id_int", "watson_searchentry"."title", "watson_searchentry"."description", "watson_searchentry"."content", "watson_searchentry"."url", "watson_searchentry"."meta_encoded", (ts_rank_cd(watson_searchentry.search_tsv, to_tsquery(\'testzhcfg\', \'$$真棒$$:*\'))) AS "watson_rank" FROM "watson_searchentry" WHERE ("watson_searchentry"."engine_slug" = \'default\' AND "watson_searchentry"."content_type_id" = 10 AND (search_tsv @@ to_tsquery(\'testzhcfg\', \'$$真棒$$:*\'))) ORDER BY "watson_rank" DESC LIMIT 21',
        'time': '0.001'
    }

I'm able to retrieve the results via this normal query:

Venue.objects.annotate(search=SearchVector('name', 'name_zh_cn', config="testzhcfg"),).filter(search='真棒')

Does something look odd here? If you want I can put up a WIP PR.