Hi Chris
Unfortunately the excerpts object only ties into the underlying model,
and doesn't add shortcuts to the defined fields.
A work around could be to add a file_names method in your model:
def file_names
files.collect { |file| file.name }.join(" ")
end
And then result.excerpts.file_name will work.
--
Pat
On 19/11/2009, at 11:19 PM, Chris Roos wrote:
> Given this (fictional) setup.
>
> class Folder < ActiveRecord::Base
> # Fields: id, name
> has_many :files
> define_index do
> indexes name
> indexes files.name, :as => :file_names
> end
> end
> class File < ActiveRecord::Base
> # Fields: id, folder_id, name
> belongs_to :folder
> end
>
> irb> folder = Folder.create!(:name => 'no-match')
> irb> folder.files.create!(:name => 'matching-text')
>
> Given that I've indexed, I can issue these queries to return the
> matching folder object:
>
> irb> ThinkingSphinx.search 'matching-text'
> irb> Folder.search 'matching-text'
>
> How would I go about displaying an excerpt in this case? The
> #excerpts method just returns the folder object with the name field
> html escaped. I'd expect (although I'm new to thinking_sphinx/sphinx
> so this might not be possible) to be able to use something like
> result.excerpts.file_names (i.e. the alias in Folder.define_index) to
> get something that I could display in my search results. Should I be
> doing something else or is this not possible at the moment?
>
> Cheers, Chris
>
> --
>
> 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].
> For more options, visit this group at
> http://groups.google.com/group/thinking-sphinx?hl=
> .
>
>
--
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.