2014-11-14 134 views
1

使用思维狮身人面像宝石有人知道如何设置高级搜索表单?创建高级搜索选项

我有单一的搜索表单查询工作,但我也可以选择用户从高级搜索框中选择选项。

这里是正常的,标准的一行搜索框代码的工作原理:

 = form_tag searches_path, method: :get do 
      span.secrch_box_bg 
      input.text_input name='search' type="text" placeholder="e.g (female), likes dogs, has a job)" 
      input.find_btn type="submit" value="Find"/

我想要做的是提供从下拉菜单中选择前选项。用户可以选择在用户表中找到的性别(男性或女性),种族(白人,黑人,亚裔,西班牙裔等),宗教信仰(基督徒,无神论者,犹太人等)以及其他属性。

有人可以提供一个如何做到这一点的例子吗?谢谢

我摆脱了我的自定义高级搜索表单,我想在它的地方使用思维狮身人面像。

    .search_box 
     h1 Search and find a mate. 
     = form_tag searches_path, method: :get do 
      span.secrch_box_bg 
      input.text_input name='search' type="text" placeholder="e.g (female), likes dogs, has a job)" 
      input.find_btn type="submit" value="Find"/
     h4 
     | or use our 
     a.adv_search href="#" 
      = image_tag "adv_link.png" 
      span Advanced Search 
     .advanced_search_div.hide 
     = form_tag searches_path, method: :get do 
      .form_container 
      .row style='padding-top:20px;' 
       .col 
       label I am a 
       select.large 
        option male 
        option female 
       .select2 
       .col.col2 style='width:300px;' 
        label Seeking 
        select.large 
        option female 
        option male 
       .select1 
       .col.col3.col33 style='width:175px;' 
        label Ages 
        = select_tag :min_age, options_for_select((18..65),18), {class: 'small'} 

       .select5 
       .col.col4 
        label to 
        = select_tag :max_age, options_for_select((20..65),65), {class: 'small'} 

       .select4 
       .col.col7 style='margin-left: 10px;width:233px;' 
       = select_tag :ethnicity, options_for_select(['Asian', 'Black', 'Biracial', 'Indian', 'Hispanic/Latin', 'Middle Eastern', 'Native American', 'Pacific Islander', 'White', 'Other']), prompt: 'ethnicity/race' 

      .row style='padding-top:20px;' 
       .col.col5 style='margin-right:18px;' 
       label Near 
       = text_field_tag :zip_code, nil, placeholder: "enter zip here", class: 'text_input' 

       .col.col.col30 style='width:190px;' 
       = select_tag :children, options_for_select(['I want kids now','I want one someday']), prompt: 'child preference' 

       .select5 
       .col.col3.col31 style='width:100px;' 
        = select_tag :religion, options_for_select(['Agnostic', 'Atheist', 'Christian', 'Catholic', 'Buddhist', 'Hindu', 'Jewish', 'Muslim', 'Other']), prompt: 'religion' 
      .btm_sec style='margin-top:20px;' 
       ul.form_list 
       li 
        a href="#" 
        = image_tag "form_icon1.png" 
        span.color Save this Search 
       li 
        a href="#" 
        = image_tag "form_icon2.png" 
        span Load 
       li 
        a href="#" 
        = image_tag "form_icon3.png" 
        span Reset 
       input.find_btn type="submit" value="Find"/
      .btm_search_detail 
      a.simple_search href="#" 
       = image_tag "simple_search_icon.png" 
       span Simple Search 

指数:

ThinkingSphinx::Index.define :location, :with => :active_record do 
    indexes city 

    has "RADIANS(locations.latitude)", :as => :latitude, :type => :float 
    has "RADIANS(locations.longitude)", :as => :longitude, :type => :float 
end 

ThinkingSphinx::Index.define :user, :with => :active_record do 
    indexes name, :as => :user, :sortable => true 
    indexes religion, birthday, about_me, height, career, feet, inches, sexuality, children, user_smoke, user_drink, politics, gender, ethnicity, education, username 
    has created_at, updated_at 
    has "RADIANS(locations.latitude)", :as => :latitude, :type => :float 
    has "RADIANS(locations.longitude)", :as => :longitude, :type => :float 
    has(:id, :as => :user_id) 
    has(:zip_code, :as => :zip_code, :type => :integer) 
    set_property :wordforms => 'lib/word.txt' 
    join location 
end 
+0

这要看你有你的ThinkingSphinx索引组织。什么是'form_for'的'@ search'?它是否解决用户模型? – blelump 2014-11-19 08:53:34

+0

@blelump我上传了视图来反映思维狮身人面像的使用情况,所以我删除了'form_for'的'@ search'(使用用户模型)。我也加了指数。 – xps15z 2014-11-19 14:58:40

+0

好的,谢谢。这些“宗教”,“性”,“儿童”,“种族”用户模型领域还是某个协会? – blelump 2014-11-20 11:03:56

回答

1

你可以设置你的形式,只要你喜欢。关键是你需要将表单参数转换为搜索选项哈希传递给ThinkingSphinx。

例如,对于指数将指定条件:

User.search(query, :conditions => { :ethnicity => params[:ethnicity], :religion => params[:religion] }) 

对于“有”的属性应指定:与作为搜索选项。此外,你应该加入年龄为“有”属性,所以你可以使用狮身人面像做最大的计算,像这样:

User.search(query, :with => { :age => 20..65 }) 

参见:http://pat.github.io/thinking-sphinx/searching.html

+0

谢谢你的帮助!完美的作品 – xps15z 2014-11-26 04:01:01