How can I use sphinx to search french words which the entries in the db is actually english?
The situation is:
I have a ROR project with a table in the db called "categories", and the category names are in english, category has many "question" entries.
In localization file config/locals/fr.yml, these categories were translated to french.
Consider about expandability, we can't change the category names in the db to french.
User can search by type part of the key word.
Here is a example: Category Name: Health and Medical In french: Santé et médecine
so how can 开发者_如何学运维I do this: type "Santé médecine abc" in the search field and sphinx will return the "questions" under "Health and Medical" category and have keyword "abc"?
First, I think that you shouldn't use yml file to translate db data. You can use yml to translate db column names, or model names and so on, but not data that is stored in db. It is bad design. The best would be to store different translations in db, but you wanted to know how to do such search without storing it in db, so:
You can do it in many various ways. If you generate links to tags (like here on SO) then it is very easy. You should generate those links like this:
# controller
@tags = Tag.all
# view
<% @tags.each do |tag| %>
<%= link_to I18n.t tag.name, search_tag_path(tag) %>
<% end %>
Or something similar according to your models and routes.
If you want to have some checkboxes or select fields with which you select tags, then you should do it similary to above example:
# controller
@tags = Tag.all
# view
<% form_tag search_path do |f| %>
<% @tags.each do |tag| %>
<%= I18n.t tag.name %> <%= check_box_tag "tags[#{tag.id}]" %>
<% end %>
<% end %>
Here on submit you would get array of ids of selected tags: params[tags]
.
精彩评论