Well, you're passing in the :include => :comments, so it'll just be a single extra SQL query, not one per comment per project.
-- Pat On 04/08/2012, at 2:32 PM, Guirec Corbel wrote: > So it will produce an extra SQL request and give all the comments, not > just the one with text.... I think it's not really what I want. > > Thanks. > > On 4 août, 09:20, "Pat Allan" <[email protected]> wrote: >> The fields aren't returned by Sphinx, so you just need to refer to the >> associations/columns that the fields are built from: >> >> projects.each do |project| >> puts project.comments.message.join("\n") >> end >> >> Cheers >> >> -- >> Pat >> >> On 04/08/2012, at 1:31 PM, Guirec Corbel wrote: >> >> >> >> >> >> >> >>> Hello, >> >>> This question is the same as here : >>> http://stackoverflow.com/questions/11804742/how-to-load-extra-fields-.... >> >>> I use thinking-sphinx like this : >> >>> class Project < ActiveRecord::Base >>> define_index do >>> indexes title >>> indexes comments.message, as: :comment_message >>> indexes category_projects.description, as: :category_description >>> end >> >>> class << self >>> def text_search(word) >>> ThinkingSphinx.search(word, include: :comments) >>> end >>> end >>> end >> >>> When I do this Project.text_search('test') it works but I want to do >>> this : >> >>> @projects = Project.text_search('test') >>> @projects.each do |project| >>> puts project.comment_message >>> end >> >>> I have this message : >> >>> undefined method `comment_message' for #<ThinkingSphinx::Search: >>> 0x000000057e11c0> >>> from /home/dougui/.rvm/gems/ruby-1.9.3-p194- >>> perf@comment_my_projects/bundler/gems/thinking-sphinx-b293abdbdf0c/lib/ >>> thinking_sphinx/search.rb:185:in `method_missing' >>> from (irb):1 >>> from /home/dougui/.rvm/gems/ruby-1.9.3-p194- >>> perf@comment_my_projects/gems/railties-3.2.6/lib/rails/commands/ >>> console.rb:47:in `start' >>> from /home/dougui/.rvm/gems/ruby-1.9.3-p194- >>> perf@comment_my_projects/gems/railties-3.2.6/lib/rails/commands/ >>> console.rb:8:in `start' >>> from /home/dougui/.rvm/gems/ruby-1.9.3-p194- >>> perf@comment_my_projects/gems/railties-3.2.6/lib/rails/commands.rb: >>> 41:in `<top (required)>' >>> from script/rails:6:in `require' >>> from script/rails:6:in `<main>' >> >>> So, how to load fields into a model from thinking-sphinx? >> >>> I didn't find anything one the doc. >> >>> Thanks! >> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Thinking Sphinx" group. >>> To post to this group, send email to [email protected]. >>> To unsubscribe from this group, send email to >>> [email protected]. >>> For more options, visit this group >>> athttp://groups.google.com/group/thinking-sphinx?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Thinking Sphinx" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/thinking-sphinx?hl=en. > -- You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/thinking-sphinx?hl=en.
