Mischa Berger
2007-Feb-06 22:22 UTC
[Ferret-talk] Which method to use to get content from index with a_a_f?
Hi everybody, After staring at the a_a_f API for quite sometime now, I decided it''s time to ask... Which method should I use to get content from the index without using highlight? Consider the following controller action: def preview if params[:search].blank? # normal case @text = @myfile. # which method do I use here to get the :text from the index??? else # if we come from the search results page @text = @myfile.highlight(params[:search], { :field => :text, :excerpt_length => :all, :pre_tag => ''[highlight]'', :post_tag => ''[/highlight]'' }) end end I didn''t store my text in the database, only in the index. When I''m coming from a search I use the highlight method, so the term I searched for gets highlighted, but how do I get the text from the index in a ''normal case''. The highlight method feels inappropriate, because I don''t want to highlight anything. I don''t see what other method to use. Thanks in advance! Mischa. -- Posted via http://www.ruby-forum.com/.
Jens Kraemer
2007-Feb-07 10:48 UTC
[Ferret-talk] Which method to use to get content from index with a_a_f?
On Tue, Feb 06, 2007 at 11:22:39PM +0100, Mischa Berger wrote:> Hi everybody, > > After staring at the a_a_f API for quite sometime now, I decided it''s > time to ask... > > Which method should I use to get content from the index without using > highlight? Consider the following controller action: > > def preview > if params[:search].blank? # normal case > @text = @myfile. # which method do I use here to get the :text from > the index??? > else # if we come from the search results page > @text = @myfile.highlight(params[:search], { :field => :text, > :excerpt_length => :all, :pre_tag => ''[highlight]'', :post_tag => > ''[/highlight]'' }) > end > end > > I didn''t store my text in the database, only in the index. When I''m > coming from a search I use the highlight method, so the term I searched > for gets highlighted, but how do I get the text from the index in a > ''normal case''. The highlight method feels inappropriate, because I don''t > want to highlight anything. I don''t see what other method to use.that''s because there is currently no aaf way to do this. You can however get a handle to the Ferret::Index instance by calling YourModel.ferret_index (or YourModel.aaf_index.ferret_index if you''re using the latest aaf trunk). Now you can query this index instance for your primary key with something in the lines of "id:#{self.id}", and then retrieve field values via the standard ferret api. Note that this won''t work with a remote index, since the index in this case is not necessarily on the same machine and therefore cannot be accessed via Ferret''s own API. I already started thinking about a way to integrate this into the API, maybe via an option to find_by_contents that allows to specify the fields you want to fetch directly from the index. That could then be combined with lazy-loading of the ''real'' record from DB for more speed when it comes to live-searches and the like. Jens -- webit! Gesellschaft f?r neue Medien mbH www.webit.de Dipl.-Wirtschaftsingenieur Jens Kr?mer kraemer at webit.de Schnorrstra?e 76 Tel +49 351 46766 0 D-01069 Dresden Fax +49 351 46766 66
Mischa Berger
2007-Feb-07 20:44 UTC
[Ferret-talk] Which method to use to get content from index with a_a_f
Thanks for the tip! I expected aaf to have a method for this, but the way you describe works fine. I''m doing it like this now: @text = Myfile.ferret_index[@myfile.document_number][:text] -- Posted via http://www.ruby-forum.com/.