是否将多个参数传递给thinking_sphinx搜索方法绝对不可能? [英] Is passing multiple params to thinking_sphinx search method absolutely impossible?

查看:152
本文介绍了是否将多个参数传递给thinking_sphinx搜索方法绝对不可能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,当被浏览时会显示最近活跃的用户。在用户上方有一些过滤选项,例如通过一种或多种过滤方式进行过滤:


  • 位置

  • 性别

  • 性偏好
  • 年龄范围
  • 国家/地区
  • ul>

    我为表单使用form_tag助手。我的问题是将每个参数传递给我的控制器:

      class BrowsersController< ApplicationController 
    def index
    @default_image =/assets/default_avatar.jpg
    @users = Profile.search params [:search],:page => params [:page],:per_page => 26

    结束
    结束

    如果我正在搜索一个字段与参数搜索我会很好,但我有多个字段,在我的表单上选择菜单。我想如何将该信息传递给我的控制器以过滤搜索结果?



    我确定我不是第一个在ruby中使用搜索过滤的人on rails

     <%= form_tag browsers_path,:method => 'get'do%> 
    < p>
    位置:<%= text_field_tag:location%>< br />
    性别:<%= select_tag:性别,
    options_for_select([[Select,nil],
    [Male,1],
    [Female 2]])%>
    < br />
    <%= submit_tagSearch,:name =>无%>
    < / p>
    <%end%>
    < br />

    亲切的问候

    更新

      @users = Profile.search'这里是电源位置',:page => params [:page],:per_page => 20,:conditions_all => {:gender => params [:gender],:location => params [:location]} 

    我使用:conditions_all来获取我的字段参数并在rails服务器日志中可以看到他们正在被拾起..现在我只需要一些如何通过思考狮身人面像让他们都看到



    更新2
    i在define_index块和索引位置有性别,因为它看起来至少需要1个字段。



    这样可以返回性别:

      @users = Profile.search params [:location],:page => params [:page],:per_page => 40,:with => {:gender => [params [:gender]]} 

    我试着检查位置和性别,似乎工作,但我会加倍检查控制台,因为它在1000英国的联合王国返回1女性,这可能是错误的,但我会加倍检查控制台并适当地编辑此更新。
    <我不太清楚你从哪里得到:conditions_all - 如果你正在处理字段,那么:conditions 就是你所追求的:

      @users = Profile.search'这里是电源位置',
    :page => params [:page],
    :per_page => 20,
    :conditions => {:gender => params [:gender],:location => params [:location]}

    但是,听起来您已将性别视为属性,而不是一个字段 - 所以,你想过滤它:

      @users = Profile.search'这里是电源LIES',
    :page => params [:page],
    :per_page => 20,
    :conditions => {:location => params [:location]},
    :with => {:gender => params [:gender]}


    I have a page that when visted brings up the most recently active users. Above the users are some filtering options such as filtering by one or a combination of:

    • location
    • gender
    • sexual preference
    • age range
    • country

    I'm using a form_tag helper for my form. My issue is passing each of these parameters to my controller:

    class BrowsersController < ApplicationController
      def index
        @default_image = "/assets/default_avatar.jpg"
        @users = Profile.search params[:search], :page => params[:page], :per_page => 26
    
      end
    end
    

    If I was searching with one field with the param "Search" I would be fine but I have multiple fields, select menu's on my form. How am I suppose to pass that info to my controller in order to filter the search results?

    I'm sure I'm not the first to use search filtering in ruby on rails

    <%= form_tag browsers_path, :method => 'get' do %>
      <p>
        Location: <%= text_field_tag :location %><br />
        Gender: <%= select_tag :gender, 
                   options_for_select([["Select", nil], 
                      ["Male", 1], 
                     ["Female", 2]]) %>
    <br />
        <%= submit_tag "Search", :name => nil %>
      </p>
      <% end %>
    <br />
    

    Kind regards

    update

    @users = Profile.search 'HERE IS WHERE THE POWER LIES', :page => params[:page], :per_page => 20, :conditions_all => { :gender => params[:gender], :location => params[:location]}
    

    I use :conditions_all to get my field params and in rails server logs I can see that they are being picked up.. now I just need to some how get them all seen by thinking sphinx

    Update 2 i have has gender in the define_index block and indexes location because it seems i need at least 1 field.

    this working to return genders:

    @users = Profile.search params[:location], :page => params[:page], :per_page => 40, :with => { :gender => [params[:gender]]}
    

    I've tried to check for both location and gender and it seems to work but I'll double check in console because it's returning 1 female in united kingdom out of 1000 and that could be wrong but I'll double check in console and edit this update appropriately.

    解决方案

    I'm not quite sure where you got :conditions_all from - if you're dealing with fields, then :conditions is what you're after:

    @users = Profile.search 'HERE IS WHERE THE POWER LIES',
      :page       => params[:page],
      :per_page   => 20,
      :conditions => {:gender => params[:gender], :location => params[:location]}
    

    But, it sounds like you've got gender as an attribute instead of a field - and so, you want to filter on it instead:

    @users = Profile.search 'HERE IS WHERE THE POWER LIES',
      :page       => params[:page],
      :per_page   => 20,
      :conditions => {:location => params[:location]},
      :with       => {:gender => params[:gender]}
    

    这篇关于是否将多个参数传递给thinking_sphinx搜索方法绝对不可能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆