Skip to content

Commit

Permalink
[1822] change query fields for multilingual query
Browse files Browse the repository at this point in the history
  • Loading branch information
kindly committed Feb 23, 2012
1 parent f7d2964 commit 1bcb885
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions ckanext/multilingual/plugin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import ckan
from ckan.plugins import SingletonPlugin, implements, IPackageController
import pylons
from pylons import config

LANGS = ['en', 'fr', 'de', 'es', 'it', 'nl', 'ro', 'pt', 'pl']

class MultilingualDataset(SingletonPlugin):
implements(IPackageController, inherit=True)
Expand All @@ -9,6 +12,25 @@ def before_index(self, search_params):
return search_params

def before_search(self, search_params):
lang_set = set(LANGS)
current_lang = pylons.request.environ['CKAN_LANG']
# fallback to default locale if locale not in suported langs
if not current_lang in lang_set:
current_lang = config.get('ckan.locale_default')
# fallback to english if default locale is not supported
if not current_lang in lang_set:
current_lang = 'en'
# treat current lang differenly so remove from set
lang_set.remove(current_lang)

# weight current lang more highly
query_fields = 'title_%s^8 text_%s^4' % (current_lang, current_lang)

for lang in lang_set:
query_fields += ' title_%s^2 text_%s' % (lang, lang)

search_params['qf'] = query_fields

return search_params

# FIXME: Look for translation in fallback language when none found in
Expand Down

0 comments on commit 1bcb885

Please sign in to comment.