ultrasphinx 1.5.2 → 1.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +2 -3
- data/CHANGELOG +2 -0
- data/Manifest +134 -28
- data/TODO +0 -1
- data/examples/{app.multi → ap.multi} +1 -1
- data/examples/default.base +2 -0
- data/lib/ultrasphinx.rb +19 -17
- data/lib/ultrasphinx/configure.rb +36 -28
- data/lib/ultrasphinx/core_extensions.rb +11 -1
- data/lib/ultrasphinx/fields.rb +16 -9
- data/lib/ultrasphinx/hex_to_int.sql +15 -0
- data/lib/ultrasphinx/is_indexed.rb +9 -7
- data/lib/ultrasphinx/search.rb +27 -13
- data/lib/ultrasphinx/search/internals.rb +36 -16
- data/lib/ultrasphinx/spell.rb +13 -4
- data/lib/ultrasphinx/ultrasphinx.rb +30 -20
- data/tasks/ultrasphinx.rake +31 -6
- data/test/integration/app/README +182 -0
- data/test/integration/app/Rakefile +10 -0
- data/test/integration/app/app/controllers/addresses_controller.rb +85 -0
- data/test/integration/app/app/controllers/application.rb +7 -0
- data/test/integration/app/app/controllers/sellers_controller.rb +85 -0
- data/test/integration/app/app/controllers/states_controller.rb +85 -0
- data/test/integration/app/app/controllers/users_controller.rb +85 -0
- data/test/integration/app/app/helpers/addresses_helper.rb +2 -0
- data/test/integration/app/app/helpers/application_helper.rb +3 -0
- data/test/integration/app/app/helpers/sellers_helper.rb +28 -0
- data/test/integration/app/app/helpers/states_helper.rb +2 -0
- data/test/integration/app/app/helpers/users_helper.rb +2 -0
- data/test/integration/app/app/models/geo/address.rb +8 -0
- data/test/integration/app/app/models/geo/state.rb +5 -0
- data/test/integration/app/app/models/person/user.rb +9 -0
- data/test/integration/app/app/models/seller.rb +20 -0
- data/test/integration/app/app/views/addresses/edit.html.erb +12 -0
- data/test/integration/app/app/views/addresses/index.html.erb +18 -0
- data/test/integration/app/app/views/addresses/new.html.erb +11 -0
- data/test/integration/app/app/views/addresses/show.html.erb +3 -0
- data/test/integration/app/app/views/layouts/addresses.html.erb +17 -0
- data/test/integration/app/app/views/layouts/sellers.html.erb +17 -0
- data/test/integration/app/app/views/layouts/states.html.erb +17 -0
- data/test/integration/app/app/views/layouts/users.html.erb +17 -0
- data/test/integration/app/app/views/sellers/edit.html.erb +12 -0
- data/test/integration/app/app/views/sellers/index.html.erb +20 -0
- data/test/integration/app/app/views/sellers/new.html.erb +11 -0
- data/test/integration/app/app/views/sellers/show.html.erb +3 -0
- data/test/integration/app/app/views/states/edit.html.erb +12 -0
- data/test/integration/app/app/views/states/index.html.erb +19 -0
- data/test/integration/app/app/views/states/new.html.erb +11 -0
- data/test/integration/app/app/views/states/show.html.erb +3 -0
- data/test/integration/app/app/views/users/edit.html.erb +12 -0
- data/test/integration/app/app/views/users/index.html.erb +22 -0
- data/test/integration/app/app/views/users/new.html.erb +11 -0
- data/test/integration/app/app/views/users/show.html.erb +3 -0
- data/test/integration/app/config/boot.rb +45 -0
- data/test/integration/app/config/database.yml +21 -0
- data/test/integration/app/config/environment.rb +11 -0
- data/test/integration/app/config/environments/development.rb +7 -0
- data/test/integration/app/config/environments/production.rb +18 -0
- data/test/integration/app/config/environments/test.rb +19 -0
- data/test/integration/app/config/locomotive.yml +6 -0
- data/test/integration/app/config/routes.rb +33 -0
- data/test/integration/app/config/ultrasphinx/default.base +56 -0
- data/test/integration/app/config/ultrasphinx/development.conf +159 -0
- data/test/integration/app/config/ultrasphinx/development.conf.canonical +159 -0
- data/test/integration/app/db/migrate/001_create_users.rb +16 -0
- data/test/integration/app/db/migrate/002_create_sellers.rb +14 -0
- data/test/integration/app/db/migrate/003_create_addresses.rb +19 -0
- data/test/integration/app/db/migrate/004_create_states.rb +12 -0
- data/test/integration/app/db/migrate/005_add_capitalization_to_seller.rb +9 -0
- data/test/integration/app/db/migrate/006_add_deleted_to_user.rb +9 -0
- data/test/integration/app/db/migrate/007_add_lat_and_long_to_address.rb +11 -0
- data/test/integration/app/db/migrate/008_add_mission_statement_to_seller.rb +9 -0
- data/test/integration/app/db/schema.rb +45 -0
- data/test/integration/app/doc/README_FOR_APP +2 -0
- data/test/integration/app/public/404.html +30 -0
- data/test/integration/app/public/500.html +30 -0
- data/test/integration/app/public/dispatch.cgi +10 -0
- data/test/integration/app/public/dispatch.fcgi +24 -0
- data/test/integration/app/public/dispatch.rb +10 -0
- data/test/integration/app/public/favicon.ico +0 -0
- data/test/integration/app/public/images/rails.png +0 -0
- data/test/integration/app/public/index.html +277 -0
- data/test/integration/app/public/javascripts/application.js +2 -0
- data/test/integration/app/public/javascripts/controls.js +833 -0
- data/test/integration/app/public/javascripts/dragdrop.js +942 -0
- data/test/integration/app/public/javascripts/effects.js +1088 -0
- data/test/integration/app/public/javascripts/prototype.js +2515 -0
- data/test/integration/app/public/robots.txt +1 -0
- data/test/integration/app/public/stylesheets/scaffold.css +74 -0
- data/test/integration/app/script/about +3 -0
- data/test/integration/app/script/breakpointer +3 -0
- data/test/integration/app/script/console +3 -0
- data/test/integration/app/script/destroy +3 -0
- data/test/integration/app/script/generate +3 -0
- data/test/integration/app/script/performance/benchmarker +3 -0
- data/test/integration/app/script/performance/profiler +3 -0
- data/test/integration/app/script/plugin +3 -0
- data/test/integration/app/script/process/inspector +3 -0
- data/test/integration/app/script/process/reaper +3 -0
- data/test/integration/app/script/process/spawner +3 -0
- data/test/integration/app/script/runner +3 -0
- data/test/integration/app/script/server +3 -0
- data/test/integration/app/test/fixtures/addresses.yml +13 -0
- data/test/integration/app/test/fixtures/sellers.yml +11 -0
- data/test/integration/app/test/fixtures/states.yml +216 -0
- data/test/integration/app/test/fixtures/users.yml +11 -0
- data/test/integration/app/test/functional/addresses_controller_test.rb +57 -0
- data/test/integration/app/test/functional/sellers_controller_test.rb +57 -0
- data/test/integration/app/test/functional/states_controller_test.rb +57 -0
- data/test/integration/app/test/functional/users_controller_test.rb +57 -0
- data/test/integration/app/test/test_helper.rb +28 -0
- data/test/integration/app/test/unit/address_test.rb +10 -0
- data/test/integration/app/test/unit/seller_test.rb +10 -0
- data/test/integration/app/test/unit/state_test.rb +10 -0
- data/test/integration/app/test/unit/user_test.rb +10 -0
- data/test/integration/configure_test.rb +23 -0
- data/test/integration/search_test.rb +221 -0
- data/test/integration/server_test.rb +38 -0
- data/test/integration/spell_test.rb +15 -0
- data/test/setup.rb +12 -0
- data/test/test_all.rb +1 -0
- data/test/test_helper.rb +13 -24
- data/test/ts.multi +2 -0
- data/test/unit/parser_test.rb +86 -86
- data/ultrasphinx.gemspec +12 -5
- metadata +136 -30
- metadata.gz.sig +0 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
require 'sellers_controller'
|
3
|
+
|
4
|
+
# Re-raise errors caught by the controller.
|
5
|
+
class SellersController; def rescue_action(e) raise e end; end
|
6
|
+
|
7
|
+
class SellersControllerTest < Test::Unit::TestCase
|
8
|
+
fixtures :sellers
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@controller = SellersController.new
|
12
|
+
@request = ActionController::TestRequest.new
|
13
|
+
@response = ActionController::TestResponse.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_should_get_index
|
17
|
+
get :index
|
18
|
+
assert_response :success
|
19
|
+
assert assigns(:sellers)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_should_get_new
|
23
|
+
get :new
|
24
|
+
assert_response :success
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_should_create_seller
|
28
|
+
assert_difference('Seller.count') do
|
29
|
+
post :create, :seller => { }
|
30
|
+
end
|
31
|
+
|
32
|
+
assert_redirected_to seller_path(assigns(:seller))
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_should_show_seller
|
36
|
+
get :show, :id => 1
|
37
|
+
assert_response :success
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_should_get_edit
|
41
|
+
get :edit, :id => 1
|
42
|
+
assert_response :success
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_should_update_seller
|
46
|
+
put :update, :id => 1, :seller => { }
|
47
|
+
assert_redirected_to seller_path(assigns(:seller))
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_should_destroy_seller
|
51
|
+
assert_difference('Seller.count', -1) do
|
52
|
+
delete :destroy, :id => 1
|
53
|
+
end
|
54
|
+
|
55
|
+
assert_redirected_to sellers_path
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
require 'states_controller'
|
3
|
+
|
4
|
+
# Re-raise errors caught by the controller.
|
5
|
+
class StatesController; def rescue_action(e) raise e end; end
|
6
|
+
|
7
|
+
class StatesControllerTest < Test::Unit::TestCase
|
8
|
+
fixtures :states
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@controller = StatesController.new
|
12
|
+
@request = ActionController::TestRequest.new
|
13
|
+
@response = ActionController::TestResponse.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_should_get_index
|
17
|
+
get :index
|
18
|
+
assert_response :success
|
19
|
+
assert assigns(:states)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_should_get_new
|
23
|
+
get :new
|
24
|
+
assert_response :success
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_should_create_state
|
28
|
+
assert_difference('State.count') do
|
29
|
+
post :create, :state => { }
|
30
|
+
end
|
31
|
+
|
32
|
+
assert_redirected_to state_path(assigns(:state))
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_should_show_state
|
36
|
+
get :show, :id => 1
|
37
|
+
assert_response :success
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_should_get_edit
|
41
|
+
get :edit, :id => 1
|
42
|
+
assert_response :success
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_should_update_state
|
46
|
+
put :update, :id => 1, :state => { }
|
47
|
+
assert_redirected_to state_path(assigns(:state))
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_should_destroy_state
|
51
|
+
assert_difference('State.count', -1) do
|
52
|
+
delete :destroy, :id => 1
|
53
|
+
end
|
54
|
+
|
55
|
+
assert_redirected_to states_path
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
require 'users_controller'
|
3
|
+
|
4
|
+
# Re-raise errors caught by the controller.
|
5
|
+
class UsersController; def rescue_action(e) raise e end; end
|
6
|
+
|
7
|
+
class UsersControllerTest < Test::Unit::TestCase
|
8
|
+
fixtures :users
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@controller = UsersController.new
|
12
|
+
@request = ActionController::TestRequest.new
|
13
|
+
@response = ActionController::TestResponse.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_should_get_index
|
17
|
+
get :index
|
18
|
+
assert_response :success
|
19
|
+
assert assigns(:users)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_should_get_new
|
23
|
+
get :new
|
24
|
+
assert_response :success
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_should_create_user
|
28
|
+
assert_difference('User.count') do
|
29
|
+
post :create, :user => { }
|
30
|
+
end
|
31
|
+
|
32
|
+
assert_redirected_to user_path(assigns(:user))
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_should_show_user
|
36
|
+
get :show, :id => 1
|
37
|
+
assert_response :success
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_should_get_edit
|
41
|
+
get :edit, :id => 1
|
42
|
+
assert_response :success
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_should_update_user
|
46
|
+
put :update, :id => 1, :user => { }
|
47
|
+
assert_redirected_to user_path(assigns(:user))
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_should_destroy_user
|
51
|
+
assert_difference('User.count', -1) do
|
52
|
+
delete :destroy, :id => 1
|
53
|
+
end
|
54
|
+
|
55
|
+
assert_redirected_to users_path
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
3
|
+
require 'test_help'
|
4
|
+
|
5
|
+
class Test::Unit::TestCase
|
6
|
+
# Transactional fixtures accelerate your tests by wrapping each test method
|
7
|
+
# in a transaction that's rolled back on completion. This ensures that the
|
8
|
+
# test database remains unchanged so your fixtures don't have to be reloaded
|
9
|
+
# between every test method. Fewer database queries means faster tests.
|
10
|
+
#
|
11
|
+
# Read Mike Clark's excellent walkthrough at
|
12
|
+
# http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
|
13
|
+
#
|
14
|
+
# Every Active Record database supports transactions except MyISAM tables
|
15
|
+
# in MySQL. Turn off transactional fixtures in this case; however, if you
|
16
|
+
# don't care one way or the other, switching from MyISAM to InnoDB tables
|
17
|
+
# is recommended.
|
18
|
+
self.use_transactional_fixtures = true
|
19
|
+
|
20
|
+
# Instantiated fixtures are slow, but give you @david where otherwise you
|
21
|
+
# would need people(:david). If you don't want to migrate your existing
|
22
|
+
# test cases which use the @david style and don't mind the speed hit (each
|
23
|
+
# instantiated fixtures translates to a database query per test method),
|
24
|
+
# then set this back to true.
|
25
|
+
self.use_instantiated_fixtures = false
|
26
|
+
|
27
|
+
# Add more helper methods to be used by all tests here...
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
require "#{File.dirname(__FILE__)}/../test_helper"
|
3
|
+
|
4
|
+
class ConfigureTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
CONF = "#{RAILS_ROOT}/config/ultrasphinx/development.conf"
|
7
|
+
|
8
|
+
def test_configuration_hasnt_changed
|
9
|
+
|
10
|
+
File.delete CONF if File.exist? CONF
|
11
|
+
Dir.chdir RAILS_ROOT do
|
12
|
+
Ultrasphinx::Configure.run
|
13
|
+
end
|
14
|
+
|
15
|
+
@offset = 4
|
16
|
+
@current = open(CONF).readlines[@offset..-1]
|
17
|
+
@canonical = open(CONF + ".canonical").readlines[@offset..-1]
|
18
|
+
@canonical.each_with_index do |line, index|
|
19
|
+
assert_equal line, @current[index], "line #{index}:#{line.inspect} is incorrect"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,221 @@
|
|
1
|
+
|
2
|
+
require "#{File.dirname(__FILE__)}/../test_helper"
|
3
|
+
|
4
|
+
class SearchTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
S = Ultrasphinx::Search
|
7
|
+
E = Ultrasphinx::UsageError
|
8
|
+
STRFTIME = "%b %d %Y %H:%M:%S" # Chronic can't parse the default date .to_s
|
9
|
+
|
10
|
+
def test_simple_query
|
11
|
+
assert_nothing_raised do
|
12
|
+
@s = S.new(:query => 'seller').run
|
13
|
+
end
|
14
|
+
assert_equal 20, @s.results.size
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_query_must_be_run
|
18
|
+
@s = S.new
|
19
|
+
assert_raises(E) { @s.total_entries }
|
20
|
+
assert_raises(E) { @s.response }
|
21
|
+
assert_raises(E) { @s.facets }
|
22
|
+
assert_raises(E) { @s.results }
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_subtotals
|
26
|
+
@s = S.new.run
|
27
|
+
assert_equal @s.total_entries, @s.subtotals.values._sum
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_query_retries_and_fails
|
31
|
+
system("cd #{RAILS_ROOT}; rake ultrasphinx:daemon:stop &> /dev/null")
|
32
|
+
assert_raises(Sphinx::SphinxConnectError) do
|
33
|
+
S.new.run
|
34
|
+
end
|
35
|
+
system("cd #{RAILS_ROOT}; rake ultrasphinx:daemon:start &> /dev/null")
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_accessors
|
39
|
+
@per_page = 5
|
40
|
+
@page = 3
|
41
|
+
@s = S.new(:query => 'seller', :per_page => @per_page, :page => @page).run
|
42
|
+
assert_equal @per_page, @s.per_page
|
43
|
+
assert_equal @page, @s.page
|
44
|
+
assert_equal @page - 1, @s.previous_page
|
45
|
+
assert_equal @page + 1, @s.next_page
|
46
|
+
assert_equal @per_page * (@page - 1), @s.offset
|
47
|
+
assert @s.page_count >= @s.total_entries / @per_page.to_f
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_empty_query
|
51
|
+
@total = Ultrasphinx::MODEL_CONFIGURATION.keys.inject(0) do |acc, class_name|
|
52
|
+
acc + class_name.constantize.count
|
53
|
+
end - User.count(:conditions => {:deleted => true })
|
54
|
+
|
55
|
+
assert_nothing_raised do
|
56
|
+
@s = S.new.run
|
57
|
+
end
|
58
|
+
|
59
|
+
assert_equal(
|
60
|
+
@total,
|
61
|
+
@s.total_entries
|
62
|
+
)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_sort_by_date
|
66
|
+
assert_equal(
|
67
|
+
Seller.find(:all, :limit => 5, :order => 'created_at DESC').map(&:created_at),
|
68
|
+
S.new(:class_names => 'Seller', :sort_by => 'created_at', :sort_mode => 'descending', :per_page => 5).run.map(&:created_at)
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_sort_by_float
|
73
|
+
assert_equal(
|
74
|
+
Seller.find(:all, :limit => 5, :order => 'capitalization ASC').map(&:capitalization),
|
75
|
+
S.new(:class_names => 'Seller', :sort_by => 'capitalization', :sort_mode => 'ascending', :per_page => 5).run.map(&:capitalization)
|
76
|
+
)
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_sort_by_string
|
80
|
+
# XXX waiting for feedback from Andrew; this seems like a Sphinx bug
|
81
|
+
# assert_equal(
|
82
|
+
# Seller.find(:all, :limit => 5, :order => 'mission_statement DESC').map(&:mission_statement),
|
83
|
+
# S.new(:class_names => 'Seller', :sort_by => 'mission_statement', :sort_mode => 'descending', :per_page => 5).run.map(&:mission_statement)
|
84
|
+
# )
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_filter
|
88
|
+
assert_equal(
|
89
|
+
Seller.count(:conditions => 'user_id = 17'),
|
90
|
+
S.new(:class_names => 'Seller', :filters => {'user_id' => 17}).run.size
|
91
|
+
)
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_nil_filter
|
95
|
+
# XXX
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_float_range_filter
|
99
|
+
@count = Seller.count(:conditions => 'capitalization <= 29.5 AND capitalization >= 10')
|
100
|
+
assert_equal(@count,
|
101
|
+
S.new(:class_names => 'Seller', :filters => {'capitalization' => 10..29.5}).run.size)
|
102
|
+
assert_equal(@count,
|
103
|
+
S.new(:class_names => 'Seller', :filters => {'capitalization' => 29.5..10}).run.size)
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_date_range_filter
|
107
|
+
# XXX some strange boundary error in this one
|
108
|
+
@first, @last = Seller.find(5).created_at, Seller.find(10).created_at
|
109
|
+
@items = Seller.find(:all, :conditions => ['created_at => ? AND created_at <= ?', @last, @first]).sort_by(&:id)
|
110
|
+
@count = @items.size
|
111
|
+
|
112
|
+
@search = S.new(:class_names => 'Seller', :filters => {'created_at' => @first..@last}).run.sort_by(&:id)
|
113
|
+
assert_equal(@count, @search.size)
|
114
|
+
assert_equal(@items.first, @search.first)
|
115
|
+
assert_equal(@items.last, @search.last)
|
116
|
+
|
117
|
+
assert_equal(@count,
|
118
|
+
S.new(:class_names => 'Seller', :filters => {'created_at' => @last..@first}).run.size)
|
119
|
+
assert_equal(@count,
|
120
|
+
S.new(:class_names => 'Seller', :filters => {'created_at' => @last.strftime(STRFTIME)...@first.strftime(STRFTIME)}).run.size)
|
121
|
+
|
122
|
+
assert_raises(Ultrasphinx::UsageError) do
|
123
|
+
S.new(:class_names => 'Seller', :filters => {'created_at' => "bogus".."sugob"}).run.size
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_text_filter
|
128
|
+
assert_equal(
|
129
|
+
Seller.count(:conditions => "company_name = 'seller17'"),
|
130
|
+
S.new(:class_names => 'Seller', :filters => {'company_name' => 'seller17'}).run.size
|
131
|
+
)
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_invalid_filter
|
135
|
+
assert_raises(Sphinx::SphinxArgumentError) do
|
136
|
+
S.new(:class_names => 'Seller', :filters => {'bogus' => 17}).run
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_conditions
|
141
|
+
@deleted_count = User.count(:conditions => {:deleted => true })
|
142
|
+
assert_equal 1, @deleted_count
|
143
|
+
assert_equal User.count - @deleted_count, S.new(:class_name => 'User').run.total_entries
|
144
|
+
end
|
145
|
+
|
146
|
+
# def test_mismatched_facet_configuration
|
147
|
+
# assert_raises(Ultrasphinx::ConfigurationError) do
|
148
|
+
# Ultrasphinx::Search.new(:facets => 'company_name').run
|
149
|
+
# end
|
150
|
+
# end
|
151
|
+
|
152
|
+
def test_bogus_facet_name
|
153
|
+
assert_raises(Ultrasphinx::UsageError) do
|
154
|
+
Ultrasphinx::Search.new(:facets => 'bogus').run
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_unconfigured_sortable_name
|
159
|
+
assert_raises(Sphinx::SphinxInternalError) do
|
160
|
+
S.new(:class_names => 'Seller', :sort_by => 'company_name',:per_page => 5).run
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_nonexistent_sortable_name
|
165
|
+
assert_raises(Sphinx::SphinxInternalError) do
|
166
|
+
S.new(:class_names => 'Seller', :sort_by => 'bogus',:per_page => 5).run
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_text_facet
|
171
|
+
@s = Ultrasphinx::Search.new(:facets => ['company_name']).run
|
172
|
+
assert_equal 21, @s.facets['company_name'].size
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_numeric_facet
|
176
|
+
@user_id_count = Seller.find(:all).map(&:user_id).uniq.size
|
177
|
+
|
178
|
+
@s = Ultrasphinx::Search.new(:class_name => 'Seller', :facets => 'user_id').run
|
179
|
+
assert_equal @user_id_count, @s.facets['user_id'].size
|
180
|
+
|
181
|
+
@s = Ultrasphinx::Search.new(:facets => 'user_id').run
|
182
|
+
assert_equal @user_id_count + 1, @s.facets['user_id'].size
|
183
|
+
assert @s.facets['user_id'][0] > 1
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_multi_facet
|
187
|
+
@facets = ['user_id', 'capitalization', 'company_name']
|
188
|
+
@s = Ultrasphinx::Search.new(:facets => @facets).run
|
189
|
+
@facets.each do |facet|
|
190
|
+
assert @s.facets[facet]
|
191
|
+
assert @s.facets[facet].any?
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_float_facet
|
196
|
+
@s = Ultrasphinx::Search.new(:class_name => 'Seller', :facets => 'capitalization').run
|
197
|
+
@s.facets['capitalization'].keys.each do |key|
|
198
|
+
# XXX Requires full Sphinx 0.9.8 compatibility
|
199
|
+
# assert key.is_a?(Float)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
def test_association_sql
|
204
|
+
# XXX
|
205
|
+
end
|
206
|
+
|
207
|
+
def test_weights
|
208
|
+
@unweighted = Ultrasphinx::Search.new(:query => 'seller1', :per_page => 1).run.first
|
209
|
+
@weighted = Ultrasphinx::Search.new(:query => 'seller1', :weights => {'company' => 2}, :per_page => 1).run.first
|
210
|
+
assert_not_equal @unweighted.class, @weighted.class
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_excerpts
|
214
|
+
@s = Ultrasphinx::Search.new(:query => 'seller10')
|
215
|
+
@excerpted_item = @s.excerpt.first
|
216
|
+
@item = @s.run.first
|
217
|
+
assert_not_equal @item.name, @excerpted_item.name
|
218
|
+
assert_match /strong/, @excerpted_item.name
|
219
|
+
end
|
220
|
+
|
221
|
+
end
|