1
require File.dirname(__FILE__) + "/../test_helper"
2
require File.dirname(__FILE__) + "/number_to_spoken.rb"
5
class IndexThreadSafetyTest < Test::Unit::TestCase
8
INDEX_DIR = File.expand_path(File.join(File.dirname(__FILE__), "index"))
11
ANALYZER = Ferret::Analysis::StandardAnalyzer.new()
14
index = Index.new(:path => INDEX_DIR,
16
:analyzer => ANALYZER,
17
:default_field => :content)
22
index = Index.new(:path => INDEX_DIR,
23
:analyzer => ANALYZER,
24
:default_field => :content)
42
def do_optimize(index)
43
puts "Optimizing the index"
47
def do_delete_doc(index)
48
return if index.size == 0
49
doc_num = rand(index.size)
50
puts "Deleting #{doc_num} from index which has#{index.has_deletions? ? "" : " no"} deletions"
51
puts "document was already deleted" if (index.deleted?(doc_num))
57
d = {:id => n, :content => n.to_spoken}
64
puts("Searching for #{n}")
65
hits = index.search_each(n.to_spoken, :num_docs => 3) do |d, s|
66
puts "Hit for #{n}: #{index[d][:id]} - #{s}"
68
puts("Searched for #{n}: total = #{hits}")
74
threads << Thread.new { indexing_thread }
77
threads.each {|t| t.join}