我是狮身人面像的新手,我想使用sphinx在模型中搜索,我做了它并且它运行良好但只有一个字段
这是搜索领域
<%= form_tag welcome_result_path, target: '_blank' , method: :get do%>
<%= text_field_tag :search, params[:search]%>
<%= submit_tag 'Search',name: nil %>
<%end%>
这是我的行动
def result
@firms = ThinkingSphinx.search(params[:search],classes:[Firm])
end
这是我的索引
ThinkingSphinx::Index.define :firm, with: :active_record do
# fields
indexes corporate_name, :sortable => true, :as => :rs
indexes id, :as => :newid
indexes external_id, :as => :oldid
indexes gruik_code, :as => :gruik
#indexes country_id, :as => :country ====> not sure we need this (?)
# indexes usual_corporate_name, :as => :rsu
indexes [contacts.first_name, contacts.last_name], :as => :nom_contact
indexes contacts.role, :as => :role_contact
indexes contacts.contact_methods.value, :as => :second
indexes contacts.contact_methods.method_type, :as => :contact_method
indexes categories(:id), :as => :categorie_id
indexes categories.label, :as => :categorie
indexes [addresses.city.region.name, addresses.free_region], :as => :wilaya
indexes [addresses.street_1, addresses.street_2, addresses.street_3], :as => :adresse
indexes [addresses.city.region.name, addresses.city.name, addresses.street_1, addresses.street_2, addresses.street_3], :as => :ou
indexes [addresses.city.name, addresses.free_city], :as => :ville
indexes tags.name, :as => :tag
indexes categories.tags.name, :as => :categorie_tag
indexes properties.value, :as => :prop
indexes keywords, :as => :keywords
indexes vip_keywords, :as => :vip_keywords
indexes description, :as => :description
end
我想为位置添加一个字段
答案 0 :(得分:0)
如果您想搜索Sphinx索引中的特定字段,可以在搜索调用中使用"my log message"
选项:
:conditions
此外,与您的问题无关,但只是您共享的代码中的内容:如果您只搜索一个模型,则可以在该模型上使用ThinkingSphinx.search(
params[:search],
classes: [Firm],
conditions: {:location => params[:location]}
)
方法,而不是通过search
选项:
:classes