To edit pages or tickets please login with username/password: aaf/aaf

{5} Assigned, Active Tickets by Owner (Full Description) (10 matches)

List tickets assigned, group by ticket owner. This report demonstrates the use of full-row display.

jk

Ticket Summary Component Milestone Type Created
Description
#151 strange no-results problem with special sequence of queries, DRb and find_by_contents 0plugin 0.5 defect 07/04/07

see this thread: http://www.ruby-forum.com/topic/113861#new

multi_search not affected.


#51 rebuild_index should not use it's own index instance 0plugin 0.5 enhancement 10/10/06

would be better to use the index instance returned by ferret_index instead, so it is accessible in custom to_doc methods.


#96 [PATCH] Allow passing an association as :fields or :additional_fields 0plugin 0.5 enhancement 03/30/07

This patch allows you to pass an association as :fields or :additional_fields Altough, it removes the possibility of referencing a instance variable, but isn't a better practice setup an accessor for instance variables?

The patch iterates over the associated objects calling either to_index or to_s in each of the objects and pushing the returned value to a string, which will be indexed.

Example:

class Person < ActiveRecord::Base
  acts_as_ferret :additional_fields => [:addresses]
  has_many :addresses
end

class Address < ActiveRecord::Base
  def to_index
    "#{self.address} #{self.city} #{self.state} #{self.country}"
  end
end

Person.find_by_contents("addresses: *whathever*")

I couldn't find the perfect place to document that, so.... :)


#164 Make the number of hits from the index before conditions/filtering available 0plugin 0.5 enhancement 08/17/07

The search I use aaf for defaults to excluding inactive people.

Person.find_by_contents(keyword, {}, { :conditions => { :inactive => false } })

The app needs to know if a search filtered out any results. Eg: the index returns 6 people, and the inactivity filter takes 1 out. I've added an all_hits accessor to the SearchResults? class to make this number available (index_hits may be a better name).

Here's the diff I applied to the copy of the plugin I was working with, I haven't bothered creating a patch file because it's only a couple of lines:

Index: /trunk/rails/vendor/plugins/acts_as_ferret/lib/acts_as_ferret.rb
===================================================================
--- /trunk/rails/vendor/plugins/acts_as_ferret/lib/acts_as_ferret.rb (revision 966)
+++ /trunk/rails/vendor/plugins/acts_as_ferret/lib/acts_as_ferret.rb (revision 1003)
@@ -80,8 +80,9 @@
   # decorator that adds a total_hits accessor to search result arrays
   class SearchResults
-    attr_reader :total_hits
-    def initialize(results, total_hits)
+    attr_reader :total_hits, :all_hits
+    def initialize(results, total_hits, all_hits)
       @results = results
       @total_hits = total_hits
+      @all_hits = all_hits
     end
     def method_missing(symbol, *args, &block)
Index: /trunk/rails/vendor/plugins/acts_as_ferret/lib/class_methods.rb
===================================================================
--- /trunk/rails/vendor/plugins/acts_as_ferret/lib/class_methods.rb (revision 966)
+++ /trunk/rails/vendor/plugins/acts_as_ferret/lib/class_methods.rb (revision 1003)
@@ -62,7 +62,7 @@
     # set (e.g. :num_docs and some :conditions).
     def find_by_contents(q, options = {}, find_options = {})
-      total_hits, result = find_records_lazy_or_not q, options, find_options
+      total_hits, all_hits, result = find_records_lazy_or_not q, options, find_options
       logger.debug "Query: #{q}\ntotal hits: #{total_hits}, results delivered: #{result.size}"
-      return SearchResults.new(result, total_hits)
+      return SearchResults.new(result, total_hits, all_hits)
     end 
 
@@ -151,5 +151,5 @@
     def ar_find_by_contents(q, options = {}, find_options = {})
       result_ids = {}
-      total_hits = find_id_by_contents(q, options) do |model, id, score, data|
+      all_hits = total_hits = find_id_by_contents(q, options) do |model, id, score, data|
         # stores ids, index of each id for later ordering of
         # results, and score
@@ -173,5 +173,5 @@
       end
 
-      [ total_hits, result ]
+      [ total_hits, all_hits, result ]
     end

#179 Index updated even if database transaction rolled back 0plugin later enhancement 10/18/07

If you modify a few items within a transaction, eg

Model.transaction do
  a = Model.new.save! # valid, saves, ferret entry created
  b = Model.new(:title => 'invalid').save! # invalid, doesn't save, ferret entry not created
end

a was saved, but is rolled back when the transaction is left due to b throwing an exception.

However, the ferret index has an entry for a.


#186 Receive :include parameters when rebuilding index (allow eager loading) 0plugin 0.5 enhancement 12/01/07

Let's suppose you have 20000 entries in your database and you have to rebuild the index. The model is:

class Book < ActiveRecord::Base

belongs_to :author acts_as_ferret :fields => [:title, :author_name]

def author_name

return "#{self.author.first_name} #{self.author.last_name}"

end

end

So it will do 20000 + 20 queries in the database (if the batch_size is 1000) because rebuild_index doesn't get associations. If we can set :include => :book (maybe in acts_as_ferret options) it will reduce the queries total to only 20!


#202 [PATCH] Large speed improvement on indexing (15x) 0plugin 0.5 enhancement 02/04/08

When adding acts_as_ferret to an existing application, with a few thousands of entries in th DB, the initial indexing time is prohibitive : on a MacBook?, 15000 entries are indexed in about 215s. This may lead to the improper conclusion that ferret / acts_as_ferret is slow (but other experiment show that it is not !) In fact, the bulk indexer does not really perform bulk indexing, as the documents are basically indexed one by one. The solution I have found is to change slightly the index_records function in bulk_indexer.rb file revision 316 to :



def index_records(records, offset) 
      docs = {}
      batch_time = measure_time {        
        records.each { |rec| docs[rec.id] = rec.to_doc if rec.ferret_enabled?(true) }
        @index.update_batch(docs)
      }.to_f

      ...
 end

This use a new function, update_batch, that I added in ferret 0.11.6, in index.rb :

  def update_batch(docs)
      @dir.synchrolock do
        ensure_writer_open()
        commit = false
        docs.each do |id, value| 
          delete(id)
          commit = true if id.is_a?(String) or id.is_a?(Symbol)
        end
        if commit
          @writer.commit
        end
        ensure_writer_open()
        docs.each do |id, new_doc| 
          @writer << new_doc
        end
          flush() if @auto_flush
      end
    end

This function performs the same operation as update, but on a set of documents instead of one document at a time. The result is that initial indexing took only 17s instead of 215s, a nice improvement. This of course would need some consistency validation on the ferret side. There may too some subtler improvements to be done, as the delete part of this patch is not totally "batched". And this could be used to speed up other operations in acts_as_ferret I suppose.

Francois Lagunas francois.lagunas@gmail.com http://www.tourteaser.com


#172 Model.disable_ferret in environment.rb does not work in development mode 0plugin 0.5 defect 09/12/07

the reason is automatic model class reloading, which lets aaf forget about being disabled. Maybe introduce a config mechanism like rails has, and let aaf read the status of the disabled flag from there.

Workaround for the time being: add a before_filter that's only active in dev env to call disable_ferret before every request:

before_filter :disable_ferret if RAILS_ENV == 'development'

def disable_ferret
  MyModel.disable_ferret
end

#177 total_hits incorrect when group_by used (group_by option used in actual select, but ignored in count) 0plugin 0.5 defect 10/15/07

find_with_ferret accepts normal finder options as the third param. When those options include a group_by clause, the clause is applied in the actual results returned, but NOT in the "SELECT count(*) as count_all" query. As a result, total_hits is incorrect, which means paging is incorrect, which is a big problem (three pages of results, with links to 7 pages -- not great for the end user).

SVN: 534


#161 Prevent unnecessary DB access when highlight method is called on FerretResult objects 0plugin 0.5 enhancement 08/07/07

This is a more general solution to the problem referred to in Ticket #158: Use of the the highlight method on a FerretResult? object triggering loading of the AR model instance even when the highlighted fields can be lazy loaded.

Add the following to the top of the method_missing method in ferret_result.rb

if [:highlight, :document_number, :query_for_record].include?(method.to_sym)
  @model.send method, id, *args
elsif ...

Then add highlight, document_number, and query_for_record AAF class methods, each taking an id first parameter, and change the instance methods to call these class methods.

One other useful addition to ferret_result to prevent unnecessary AR loading is:

def [](attr) method_missing(attr) end

Note: See TracReports for help on using and creating reports.

To edit pages or tickets please login with username/password: aaf/aaf