Thanks for those details Terence, and great to know the searches are working when you specify the indices (though I’m surprised it’s different when specifying models instead - are you using STI for any of these indexed models?)
Regarding the filters, there’s a few things to note: The :with option is for attributes, and yet you’re only defining fields in your index definitions (the indexes method is for fields, the has method is for attributes). Some logic that may help for deciding which to use: Is the data something you want to match against search queries (e.g. params[:search] in your earlier example)? Then it should be a field. Do you also want to be able to sort by this data? Then add :sortable => true. But, if you only want to sort by that data, or you’re filtering or grouping by it - which is often the case for non-string data like floats, integers and timestamps - then they should be attributes (which are sortable by their very nature - thus, the :sortable option is not needed). Alongside that knowledge, it’s also worth noting that NULL values are stored as 0 by Sphinx. Now, in the case of your country_id filter, there’s a few different approaches. For all of them, though, I’m presuming country_id is an integer, and thus is an attribute in your index definitions. If you’re filtering by country, do you want all Source values to be returned? Add a country_id method to your Source model, which returns 0, and a corresponding attribute. Filter on both the supplied country_id value (as an integer), and 0: :with => {:country_id => [params[:country].to_i, 0]} Or, if you want no Source values to be returned, you still add that method and attribute, but filter only by the supplied country value. However, if some providers don’t have countries, their country_id values will be NULL/0, so the first approach won’t work. Instead, I’d recommend using floats and then have Source country_ids to be -1.0, and update your filter accordingly. I’m pretty sure integers in Sphinx are unsigned, hence the need to switch to floats. Hope this helps! — Pat > On 9 Sep 2016, at 12:47 AM, Terence Leong <holysinx...@gmail.com> wrote: > > Ah noted on the lower-case symbol will do adjustments accordingly! > > Here are the other index definition: > ThinkingSphinx::Index.define :PocketWifi, :with => :real_time do > # fields > indexes number_of_user, :sortable => true, :match_mode => :any, :sort_mode > => :desc > indexes origin_country, :sortable => true, :match_mode => :any, :sort_mode > => :desc > indexes destination_country, :sortable => true, :match_mode => :any, > :sort_mode => :desc > > ThinkingSphinx::Index.define :SimSize, :with => :real_time do > # fields > indexes sim_name, :sortable => true, :match_mode => :any, :sort_mode => > :desc > indexes sim_type, :sortable => true, :match_mode => :any, :sort_mode => > :desc > > ThinkingSphinx::Index.define :Rechargeable, :with => :real_time do > # fields > indexes recharge_quota, :sortable => true, :match_mode => :any, :sort_mode > => :desc > indexes recharge_price, :sortable => true, :match_mode => :any, :sort_mode > => :desc > indexes recharge_desc, :sortable => true, :match_mode => :any, :sort_mode > => :desc > > I figured it was a problem with the where clause during the query and made > some adjustments. > It is working but can I assign thinking sphinx search to only search through > an index? > > @results = ThinkingSphinx.search( > :with => { :country_id => "#{params[:country]}", :plan_day => > "#{params[:duration]}"}, > :select => '*', > :indices => ['Provider_core', 'Source_core'] > ) > > provider_core contains country but source_core does not and it's giving me an > error due to that, any way I can simplify this? > > > -- > You received this message because you are subscribed to the Google Groups > "Thinking Sphinx" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to thinking-sphinx+unsubscr...@googlegroups.com > <mailto:thinking-sphinx+unsubscr...@googlegroups.com>. > To post to this group, send email to thinking-sphinx@googlegroups.com > <mailto:thinking-sphinx@googlegroups.com>. > Visit this group at https://groups.google.com/group/thinking-sphinx > <https://groups.google.com/group/thinking-sphinx>. > For more options, visit https://groups.google.com/d/optout > <https://groups.google.com/d/optout>. -- You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group. To unsubscribe from this group and stop receiving emails from it, send an email to thinking-sphinx+unsubscr...@googlegroups.com. To post to this group, send email to thinking-sphinx@googlegroups.com. Visit this group at https://groups.google.com/group/thinking-sphinx. For more options, visit https://groups.google.com/d/optout.