Hi Miha What I recommend here is moving/copying the relevant scopes, fields and attributes over to your AdPrice index, referencing them through the ad association as needed. e.g.
indexes description Would become indexes ad.description, :as => :description It’s a bit of a hassle, I know, but it will let you search on specific prices/currencies for specific ads, while keeping all of your other logic. — Pat > On 15 May 2015, at 7:10 pm, Miha Jakovac <[email protected]> wrote: > > Hi Pat. > > Well I also have other filters and keyword search on the Ad model, and I am > not sure if I can to what you suggest. > > @search = Ad.is_approved.is_visible.search keyword, :order => (order), > :match_mode => :extended, :with => ts_filters, :page => params[:page], > :per_page => 20 > > price range is one of the filters, which I want to use in the Ad > search/filter page. > > Sorry I might have not give you enough info in the first message. > > Kind regards, Miha > > On Fri, May 15, 2015 at 10:58 AM, Pat Allan <[email protected] > <mailto:[email protected]>> wrote: > Hi Miha > > What I’m suggesting would replace a search on Ad - while Sphinx certainly > lets you search across multiple models, any attributes referenced in filters, > order clauses, grouping need to exist across all indices. > > But in this situation, you should get the results you want from searching > AdPrice and then each ad from each result. For smarter SQL queries under the > hood, you should probably use the :include option: > > AdPrice.search :with => { … }, :include => :ad > > — > Pat > >> On 15 May 2015, at 6:33 pm, Miha Jakovac <[email protected] >> <mailto:[email protected]>> wrote: >> >> Hi Pat! >> >> Thank you for this. Can I merge the results from both searches? >> >> Kind regards, Miha >> >> On Fri, May 15, 2015 at 2:10 AM, Pat Allan <[email protected] >> <mailto:[email protected]>> wrote: >> Hi Miha >> >> While Sphinx can have arrays of integers, it can’t have arrays of floats - >> and even if it could, there’s no link between one item in one array (e.g. a >> price) and one item in another array (e.g. a currency). >> >> The best approach here is to add a Sphinx index for AdPrice, and search from >> that perspective instead. >> >> AdPrice.search :with => { >> :currency_id => params[:c_currency_id].to_i, >> :price => params[:price_from].to_f..params[:price_to].to_f >> } >> >> Cheers >> >> — >> Pat >> >> > On 15 May 2015, at 2:04 am, Treeninja <[email protected] >> > <mailto:[email protected]>> wrote: >> > >> > Hi guys! >> > >> > I am using TS 2.0. >> > >> > I have an Ad which has many prices, all in different currency. I am using >> > Fixer API to convert a price to other prices and store them in DB. I would >> > like to index column price and currency_id from the ad_prices table: >> > >> > # id :integer not null, primary key >> > # ad_id :integer >> > # currency_id :integer >> > # price :decimal(8, 2) >> > # is_up_or_down :integer >> > # is_default :boolean default(FALSE) >> > # created_at :datetime not null >> > # updated_at :datetime not null >> > >> > In the ad model I have define_index section: >> > >> > has ad_prices.price, :as => :price, :type => :float >> > has ad_prices.currency_id, :as => :c_currency_id >> > >> > How can I force the sphinx to use combination of prices and currencies at >> > the same time. For example if user sets param[c_currency_id]=1, how can >> > sphinx filter only the prices in selected currency? I have a range filter >> > for prices: price_from, price_to, c_curency_id >> > >> > Thank you very much for the support! >> > >> > Kind regards, Miha >> > >> > -- >> > 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 [email protected] >> > <mailto:thinking-sphinx%[email protected]>. >> > To post to this group, send email to [email protected] >> > <mailto:[email protected]>. >> > Visit this group at http://groups.google.com/group/thinking-sphinx >> > <http://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 [email protected] >> <mailto:thinking-sphinx%[email protected]>. >> To post to this group, send email to [email protected] >> <mailto:[email protected]>. >> Visit this group at http://groups.google.com/group/thinking-sphinx >> <http://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 [email protected] >> <mailto:[email protected]>. >> To post to this group, send email to [email protected] >> <mailto:[email protected]>. >> Visit this group at http://groups.google.com/group/thinking-sphinx >> <http://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 [email protected] > <mailto:[email protected]>. > To post to this group, send email to [email protected] > <mailto:[email protected]>. > Visit this group at http://groups.google.com/group/thinking-sphinx > <http://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 [email protected] > <mailto:[email protected]>. > To post to this group, send email to [email protected] > <mailto:[email protected]>. > Visit this group at http://groups.google.com/group/thinking-sphinx > <http://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 [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/thinking-sphinx. For more options, visit https://groups.google.com/d/optout.
