Comments (5)
Yeah, I've got some Ideas. At first, you need to index your localized values. Assume you have User model with localized name:
class UsersIndex < Chewy::Index
define_type User do
# storing name translations as object
field :name_translations, type: 'object'
# you can even define custom properties for every translation (this goes first because of ES dynamic templates resolving rules)
template 'name_translations.ru', type: 'string', index: 'analyzed', analyzer: 'custom_russian_analyzer'
# in order to define every name translation properties, we are using dynamic templates
template 'name_translations.*', type: 'string', index: 'analyzed', analyzer: 'custom_name_analyzer'
# we are using `name_translations` field name instead of `name` to define type own methods
# It will be useful if you will decide to use loaded and wrapped ES documents instead of loading AR objects.
# UsersIndex.query( .... ).first.name # will return name in current locale.
def name
name_translations[I18n.locale.to_s]
end
end
end
So, after indexing you have to query for data:
# you have to specify fields for current query according to current locale
UsersIndex.query(query_string: {fields: ["name_translations.#{I18n.locale}"], query: 'Jonny', default_operator: 'and', lenient: true})
That's it. I was recalling this from memory, so I'm not sure examples will work as is, you'll have to experiment.
I would appreciate if you will describe you adventure somewhere in wiki here. Would be a great first howto.
from chewy.
Thank you, it's work like a charm. My English is very poor. I am Quebecois. So I forker your example to make a multilang example. I give you permission to clone and put the documentation that you desire.
Free for you to do what you want it
https://github.com/sasselin/chewy_example_multilang
By the way, your solution work A1. I add the existing_filter for the model do not have all traduction.
from chewy.
https://github.com/sasselin/chewy_example_multilang/blob/master/app/chewy/page_index.rb#L17-L18
It will be better to use wildcard notation here, since this templates are similar: template 'title_translations.*', type: 'string', index: 'analyzed'
And thanks for example.
from chewy.
Yes I know, but in the futur i'll create a analyzer for each languages. Thank for your help. The gem is awesome! Very usefull.
from chewy.
Got it. Thanks for your testimonial :)
from chewy.
Related Issues (20)
- Mapping fields is not working after upgrade from version 5
- Index field looses date precision if type not explicitly set to `date` (and causes sync to always update all documents)
- Unknown key for a START_ARRAY in [index].
- How do I connect to an Elastic instance at https://cloud.elastic.co/
- Bug in the `mock_elasticsearch_response_sources` method
- Redundant crutch call when :update_fields does not contain related field
- bundle gem chewy 7.2.x auto install gem elasticsearch 8.x ?? HOT 8
- A particular search term returns a result count, but the wrappers are empty HOT 6
- Support PITs (points in time) and search_after HOT 4
- is there a way to set `Chewy.strategy(:lazy_sidekiq)` globally? to make all updates asynchronously HOT 2
- Readme comment on Ruby 3 + Rails 6.1
- `Elasticsearch::Transport::Transport::Errors::Found`
- Cleanup journal throws `Yajl::EncodeError: Max nesting depth of 256 exceeded`
- Old indices are not being cleared up after a reset
- Port PR #874 to the 7.0.x branch
- Trying to use Pagy pagination with Chewy, running into autoloading will_paginate gem
- Breaking change at 7.2.4
- I have a question regarding elasticsearch-ruby gem
- Support rails parallel testing
- Warning when upgrading to Rails 7.1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chewy.