Hi Carl,
Sorry, there is a bug. I''ll make up another release now. Please let me
know if it doesn''t fix the problem.
Cheers,
Dave
On 12/8/05, Carl Youngblood <carl at youngbloods.org>
wrote:> I have a model class in rails that has a class variable that is a
> ferret index. For some reason, the methods in my class that refer to
> the class variable are getting lock conflicts. Can anybody see any
> obvious reason why? I notice that it keeps leaving a lock file in the
> index directory. I thought auto_flush was supposed to remove the lock
> automatically after every operation. Is there something I''m doing
> wrong? FYI, I''m doing my development on Windows.
>
> Thanks,
>
> Carl
>
> class Resume < ActiveRecord::Base
> include Ferret
> has_and_belongs_to_many :users
> @@index = Index::Index.new(:path => RAILS_ROOT +
''/searchindex'',
> :key => :email,
> :create_if_missing => true,
> :auto_flush => true,
> :close_dir => true)
>
> # syncronization with ferret index
> def after_save
> @@index << {:id => id, :email => email, :contents =>
contents,
> :date => found_on}
> end
>
> def after_destroy
> @@index.delete(id)
> end
>
> def self.optimize_index
> @@index.optimize
> end
>
> def self.search(query, options)
> docs = []
> count = @@index.search_each(query, options) do |id, score|
> doc = {}
> doc[:id] = id
> doc[:email] = @@index[id][''email'']
> doc[:contents] = @@index[id][''contents'']
> doc[:date] = @@index[id][''date'']
> ind = doc[:contents].downcase.index(query)
> ind = (ind > 20) ? (ind - 20) : 0
> doc[:teaser] = doc[:contents][ind..(ind + 220)]
> docs << doc
> end
> [count, docs]
> end
>
> def mark_as_viewed(user_id)
> # user = self.users.find(user_id)
> end
>
> def self.delete_old
> @p = Pref.find_by_setting(''autodelete'')
> if @p and @p.value.to_i > 0
> val = @p.value.to_i
> destroy_all(["found_on <= DATE_SUB(CURDATE(), INTERVAL ?
DAY)", val])
> end
> end
>
> def self.delete_before(params)
> date = sprintf("%04d-%02d-%02d", params[:foundon][:year],
> params[:foundon][:month],
> params[:foundon][:day])
> deleted = Resume.destroy_all(["found_on <= ?", date])
> optimize_index
> deleted.length
> end
>
> validates_uniqueness_of :email
> end
>
> _______________________________________________
> Ferret-talk mailing list
> Ferret-talk at rubyforge.org
> http://rubyforge.org/mailman/listinfo/ferret-talk
>