websolr-rails 1.4.4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. data/.gitignore +1 -10
  2. data/LICENSE +17 -16
  3. data/README.rdoc +16 -62
  4. data/Rakefile +2 -60
  5. data/VERSION +1 -1
  6. data/lib/websolr-rails.rb +54 -1
  7. data/lib/websolr.rb +2 -1
  8. metadata +12 -215
  9. data/CHANGELOG +0 -8
  10. data/TESTING_THE_PLUGIN +0 -25
  11. data/bin/websolr +0 -10
  12. data/config/solr.yml +0 -15
  13. data/config/solr_environment.rb +0 -22
  14. data/generate_rdoc.sh +0 -13
  15. data/lib/acts_as_solr.rb +0 -65
  16. data/lib/acts_methods.rb +0 -281
  17. data/lib/class_methods.rb +0 -243
  18. data/lib/common_methods.rb +0 -89
  19. data/lib/deprecation.rb +0 -61
  20. data/lib/instance_methods.rb +0 -181
  21. data/lib/lazy_document.rb +0 -18
  22. data/lib/parser_methods.rb +0 -230
  23. data/lib/search_results.rb +0 -72
  24. data/lib/solr.rb +0 -21
  25. data/lib/solr/connection.rb +0 -190
  26. data/lib/solr/document.rb +0 -78
  27. data/lib/solr/exception.rb +0 -13
  28. data/lib/solr/field.rb +0 -39
  29. data/lib/solr/importer.rb +0 -19
  30. data/lib/solr/importer/array_mapper.rb +0 -26
  31. data/lib/solr/importer/delimited_file_source.rb +0 -38
  32. data/lib/solr/importer/hpricot_mapper.rb +0 -27
  33. data/lib/solr/importer/mapper.rb +0 -51
  34. data/lib/solr/importer/solr_source.rb +0 -43
  35. data/lib/solr/importer/xpath_mapper.rb +0 -35
  36. data/lib/solr/indexer.rb +0 -52
  37. data/lib/solr/request.rb +0 -26
  38. data/lib/solr/request/add_document.rb +0 -63
  39. data/lib/solr/request/base.rb +0 -36
  40. data/lib/solr/request/commit.rb +0 -31
  41. data/lib/solr/request/delete.rb +0 -50
  42. data/lib/solr/request/dismax.rb +0 -46
  43. data/lib/solr/request/index_info.rb +0 -22
  44. data/lib/solr/request/modify_document.rb +0 -51
  45. data/lib/solr/request/optimize.rb +0 -21
  46. data/lib/solr/request/ping.rb +0 -36
  47. data/lib/solr/request/select.rb +0 -56
  48. data/lib/solr/request/spellcheck.rb +0 -30
  49. data/lib/solr/request/standard.rb +0 -402
  50. data/lib/solr/request/update.rb +0 -23
  51. data/lib/solr/response.rb +0 -27
  52. data/lib/solr/response/add_document.rb +0 -17
  53. data/lib/solr/response/base.rb +0 -42
  54. data/lib/solr/response/commit.rb +0 -17
  55. data/lib/solr/response/delete.rb +0 -13
  56. data/lib/solr/response/dismax.rb +0 -8
  57. data/lib/solr/response/index_info.rb +0 -26
  58. data/lib/solr/response/modify_document.rb +0 -17
  59. data/lib/solr/response/optimize.rb +0 -14
  60. data/lib/solr/response/ping.rb +0 -28
  61. data/lib/solr/response/ruby.rb +0 -42
  62. data/lib/solr/response/select.rb +0 -17
  63. data/lib/solr/response/spellcheck.rb +0 -20
  64. data/lib/solr/response/standard.rb +0 -64
  65. data/lib/solr/response/xml.rb +0 -42
  66. data/lib/solr/solrtasks.rb +0 -27
  67. data/lib/solr/util.rb +0 -32
  68. data/lib/solr/xml.rb +0 -44
  69. data/lib/solr_fixtures.rb +0 -13
  70. data/lib/tasks/database.rake +0 -18
  71. data/lib/tasks/solr.rake +0 -94
  72. data/lib/tasks/test.rake +0 -7
  73. data/lib/websolr_controller.rb +0 -233
  74. data/lib/websolr_option_parser.rb +0 -61
  75. data/lib/websolr_rails.rb +0 -1
  76. data/lib/websolr_rails/tasks.rb +0 -4
  77. data/lib/will_paginate_support.rb +0 -12
  78. data/solr/CHANGES.txt +0 -1207
  79. data/solr/LICENSE.txt +0 -712
  80. data/solr/NOTICE.txt +0 -90
  81. data/solr/etc/jetty.xml +0 -205
  82. data/solr/etc/webdefault.xml +0 -379
  83. data/solr/lib/easymock.jar +0 -0
  84. data/solr/lib/jetty-6.1.3.jar +0 -0
  85. data/solr/lib/jetty-util-6.1.3.jar +0 -0
  86. data/solr/lib/jsp-2.1/ant-1.6.5.jar +0 -0
  87. data/solr/lib/jsp-2.1/core-3.1.1.jar +0 -0
  88. data/solr/lib/jsp-2.1/jsp-2.1.jar +0 -0
  89. data/solr/lib/jsp-2.1/jsp-api-2.1.jar +0 -0
  90. data/solr/lib/servlet-api-2.4.jar +0 -0
  91. data/solr/lib/servlet-api-2.5-6.1.3.jar +0 -0
  92. data/solr/lib/xpp3-1.1.3.4.O.jar +0 -0
  93. data/solr/logs/.empty-dir-for-git +0 -0
  94. data/solr/solr/README.txt +0 -52
  95. data/solr/solr/bin/abc +0 -176
  96. data/solr/solr/bin/abo +0 -176
  97. data/solr/solr/bin/backup +0 -108
  98. data/solr/solr/bin/backupcleaner +0 -142
  99. data/solr/solr/bin/commit +0 -128
  100. data/solr/solr/bin/optimize +0 -129
  101. data/solr/solr/bin/readercycle +0 -129
  102. data/solr/solr/bin/rsyncd-disable +0 -77
  103. data/solr/solr/bin/rsyncd-enable +0 -76
  104. data/solr/solr/bin/rsyncd-start +0 -145
  105. data/solr/solr/bin/rsyncd-stop +0 -105
  106. data/solr/solr/bin/scripts-util +0 -83
  107. data/solr/solr/bin/snapcleaner +0 -148
  108. data/solr/solr/bin/snapinstaller +0 -168
  109. data/solr/solr/bin/snappuller +0 -248
  110. data/solr/solr/bin/snappuller-disable +0 -77
  111. data/solr/solr/bin/snappuller-enable +0 -77
  112. data/solr/solr/bin/snapshooter +0 -109
  113. data/solr/solr/conf/admin-extra.html +0 -31
  114. data/solr/solr/conf/protwords.txt +0 -21
  115. data/solr/solr/conf/schema.xml +0 -126
  116. data/solr/solr/conf/scripts.conf +0 -24
  117. data/solr/solr/conf/solrconfig.xml +0 -458
  118. data/solr/solr/conf/stopwords.txt +0 -57
  119. data/solr/solr/conf/synonyms.txt +0 -31
  120. data/solr/solr/conf/xslt/example.xsl +0 -132
  121. data/solr/solr/conf/xslt/example_atom.xsl +0 -63
  122. data/solr/solr/conf/xslt/example_rss.xsl +0 -62
  123. data/solr/start.jar +0 -0
  124. data/solr/tmp/.empty-dir-for-git +0 -0
  125. data/solr/webapps/solr.war +0 -0
  126. data/test/config/solr.yml +0 -2
  127. data/test/db/connections/mysql/connection.rb +0 -10
  128. data/test/db/connections/sqlite/connection.rb +0 -8
  129. data/test/db/migrate/001_create_books.rb +0 -15
  130. data/test/db/migrate/002_create_movies.rb +0 -12
  131. data/test/db/migrate/003_create_categories.rb +0 -11
  132. data/test/db/migrate/004_create_electronics.rb +0 -16
  133. data/test/db/migrate/005_create_authors.rb +0 -12
  134. data/test/db/migrate/006_create_postings.rb +0 -9
  135. data/test/db/migrate/007_create_posts.rb +0 -13
  136. data/test/db/migrate/008_create_gadgets.rb +0 -11
  137. data/test/fixtures/authors.yml +0 -9
  138. data/test/fixtures/books.yml +0 -13
  139. data/test/fixtures/categories.yml +0 -7
  140. data/test/fixtures/db_definitions/mysql.sql +0 -41
  141. data/test/fixtures/electronics.yml +0 -49
  142. data/test/fixtures/movies.yml +0 -9
  143. data/test/fixtures/postings.yml +0 -10
  144. data/test/functional/acts_as_solr_test.rb +0 -413
  145. data/test/functional/association_indexing_test.rb +0 -37
  146. data/test/functional/faceted_search_test.rb +0 -163
  147. data/test/functional/multi_solr_search_test.rb +0 -51
  148. data/test/models/author.rb +0 -10
  149. data/test/models/book.rb +0 -10
  150. data/test/models/category.rb +0 -8
  151. data/test/models/electronic.rb +0 -21
  152. data/test/models/gadget.rb +0 -9
  153. data/test/models/movie.rb +0 -17
  154. data/test/models/novel.rb +0 -2
  155. data/test/models/post.rb +0 -3
  156. data/test/models/posting.rb +0 -11
  157. data/test/test_helper.rb +0 -51
  158. data/test/unit/acts_methods_shoulda.rb +0 -70
  159. data/test/unit/class_methods_shoulda.rb +0 -88
  160. data/test/unit/common_methods_shoulda.rb +0 -112
  161. data/test/unit/instance_methods_shoulda.rb +0 -326
  162. data/test/unit/lazy_document_shoulda.rb +0 -35
  163. data/test/unit/parser_instance.rb +0 -19
  164. data/test/unit/parser_methods_shoulda.rb +0 -278
  165. data/test/unit/solr_instance.rb +0 -46
  166. data/test/unit/test_helper.rb +0 -14
  167. data/websolr-rails.gemspec +0 -243
@@ -1,12 +0,0 @@
1
- class CreateAuthors < ActiveRecord::Migration
2
- def self.up
3
- create_table :authors, :force => true do |t|
4
- t.column :name, :string
5
- t.column :biography, :text
6
- end
7
- end
8
-
9
- def self.down
10
- drop_table :authors
11
- end
12
- end
@@ -1,9 +0,0 @@
1
- class CreatePostings < ActiveRecord::Migration
2
- def self.up
3
- execute "CREATE TABLE postings(`guid` varchar(20) NOT NULL PRIMARY KEY, `name` varchar(200), `description` text)"
4
- end
5
-
6
- def self.down
7
- drop_table :postings
8
- end
9
- end
@@ -1,13 +0,0 @@
1
- class CreatePosts < ActiveRecord::Migration
2
- def self.up
3
- create_table :posts, :force => true do |t|
4
- t.column :name, :string
5
- t.column :reply_counter, :integer
6
- t.column :posted_at, :datetime
7
- end
8
- end
9
-
10
- def self.down
11
- drop_table :posts
12
- end
13
- end
@@ -1,11 +0,0 @@
1
- class CreateGadgets < ActiveRecord::Migration
2
- def self.up
3
- create_table :gadgets, :force => true do |t|
4
- t.column :name, :string
5
- end
6
- end
7
-
8
- def self.down
9
- drop_table :gadgets
10
- end
11
- end
@@ -1,9 +0,0 @@
1
- tom_clancy:
2
- id: 1
3
- name: Tom Clancy
4
- biography: Tom Clancy (born 1947) writes novels of adventure and espionage in the international military-industrial complex that have earned him enormous popularity in the 1980s as a creator of the "techno-thriller" genre.
5
-
6
- stephen_king:
7
- id: 2
8
- name: Stephen King
9
- biography: Stephen King (born 1947) is a prolific and immensely popular author of horror fiction. In his works, King blends elements of the traditional gothic tale with those of the modern psychological thriller, detective, and science fiction genres.
@@ -1,13 +0,0 @@
1
- splinter_cell:
2
- id: 1
3
- category_id: 1
4
- name: Splinter Cell
5
- author: Tom Clancy
6
- published_on: <%= Date.today - 1.year %>
7
-
8
- ruby:
9
- id: 2
10
- category_id: 2
11
- name: Ruby for Dummies
12
- author: Peter McPeterson
13
- published_on: <%= Date.today - 2.years %>
@@ -1,7 +0,0 @@
1
- thriller:
2
- id: 1
3
- name: Thriller/Novels
4
-
5
- technical:
6
- id: 2
7
- name: Technical Books
@@ -1,41 +0,0 @@
1
- DROP DATABASE IF EXISTS `actsassolr_tests`;
2
- CREATE DATABASE IF NOT EXISTS `actsassolr_tests`;
3
- USE `actsassolr_tests`
4
-
5
- CREATE TABLE `books` (
6
- `id` int(11) NOT NULL auto_increment,
7
- `category_id` int(11),
8
- `name` varchar(200) default NULL,
9
- `author` varchar(200) default NULL,
10
- PRIMARY KEY (`id`)
11
- );
12
-
13
- CREATE TABLE `movies` (
14
- `id` int(11) NOT NULL auto_increment,
15
- `name` varchar(200) default NULL,
16
- `description` varchar(255) default NULL,
17
- PRIMARY KEY (`id`)
18
- );
19
-
20
- CREATE TABLE `categories` (
21
- `id` int(11) NOT NULL auto_increment,
22
- `name` varchar(200) default NULL,
23
- PRIMARY KEY (`id`)
24
- );
25
-
26
- CREATE TABLE `electronics` (
27
- `id` int(11) NOT NULL auto_increment,
28
- `name` varchar(200) default NULL,
29
- `manufacturer` varchar(255) default NULL,
30
- `features` varchar(255) default NULL,
31
- `category` varchar(255) default NULL,
32
- `price` varchar(20) default NULL,
33
- PRIMARY KEY (`id`)
34
- );
35
-
36
- CREATE TABLE `authors` (
37
- `id` int(11) NOT NULL auto_increment,
38
- `name` varchar(200) default NULL,
39
- `biography` text default NULL,
40
- PRIMARY KEY (`id`)
41
- );
@@ -1,49 +0,0 @@
1
- ipod_video:
2
- id: 1
3
- name: Apple 60 GB Memory iPod with Video Playback Black
4
- manufacturer: Apple Computer Inc.
5
- features: iTunes, Podcasts, Audiobooks
6
- category: Electronics
7
- price: 599.00
8
- created_at: <%= Date.today - 1.year %>
9
- updated_at: <%= Date.today - 1.month %>
10
-
11
- dell_monitor:
12
- id: 2
13
- name: Dell Widescreen UltraSharp 3007WFP
14
- manufacturer: Dell, Inc
15
- features: 30" TFT active matrix LCD, 2560 x 1600, .25mm dot pitch, 700:1 contrast
16
- category: Electronics
17
- price: 750.00
18
- created_at: <%= Date.today - 1.year %>
19
- updated_at: <%= Date.today - 1.month %>
20
-
21
- samsung_hd:
22
- id: 3
23
- name: Samsung SpinPoint P120 SP2514N - hard drive - 250 GB of Memory Storage - ATA-133
24
- manufacturer: Samsung Electronics Co. Ltd.
25
- features: 7200RPM, 8MB cache, IDE Ultra ATA-133
26
- category: Hard Drive
27
- price: 319.00
28
- created_at: <%= Date.today - 2.years %>
29
- updated_at: <%= Date.today - 2.months %>
30
-
31
- corsair_ram:
32
- id: 4
33
- name: CORSAIR XMS 2GB (2 x 1GB) 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) Dual Channel Kit System Memory - Retail
34
- manufacturer: Corsair Microsystems Inc.
35
- features: CAS latency 2, 2-3-3-6 timing, 2.75v, unbuffered, heat-spreader
36
- category: Memory
37
- price: 155.00
38
- created_at: <%= Date.today - 6.years %>
39
- updated_at: <%= Date.today - 3.months %>
40
-
41
- a_data_ram:
42
- id: 5
43
- name: A-DATA V-Series 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - OEM
44
- manufacturer: A-DATA Technology Inc.
45
- features: CAS latency 3, 2.7v
46
- category: Memory
47
- price: 65.79
48
- created_at: <%= Date.today - 9.years %>
49
- updated_at: <%= Date.today - 4.months %>
@@ -1,9 +0,0 @@
1
- napoleon_dynamite:
2
- id: 1
3
- name: Napoleon Dynamite
4
- description: Cool movie about a goofy guy
5
-
6
- office_space:
7
- id: 2
8
- name: Office Space
9
- description: Hypnotized dude loves fishing but not working
@@ -1,10 +0,0 @@
1
- first:
2
- guid: ABC-123
3
- name: Posting ABC
4
- description: First posting testing primary key as string
5
-
6
- second:
7
- guid: DEF-456
8
- name: Posting DEF
9
- description: Second posting testing primary key as string
10
-
@@ -1,413 +0,0 @@
1
- # encoding: utf-8
2
- require "#{File.dirname(File.expand_path(__FILE__))}/../test_helper"
3
-
4
- class ActsAsSolrTest < Test::Unit::TestCase
5
-
6
- fixtures :books, :movies, :electronics, :postings, :authors
7
-
8
- # Inserting new data into Solr and making sure it's getting indexed
9
- def test_insert_new_data
10
- assert_equal 2, Book.count_by_solr('ruby OR splinter OR bob')
11
- b = Book.create(:name => "Fuze in action", :author => "Bob Bobber", :category_id => 1)
12
- assert b.valid?
13
- assert_equal 3, Book.count_by_solr('ruby OR splinter OR bob')
14
- end
15
-
16
- # Check the type column stored in the index isn't stemmed by SOLR. If it is stemmed,
17
- # then both Post and Posting will be stored as type:Post, so a query for Posts will
18
- # return Postings and vice versa
19
-
20
- def test_insert_new_data_doesnt_stem_type
21
- assert_equal 0, Post.count_by_solr('aardvark')
22
- p = Posting.new :name => 'aardvark', :description => "An interesting animal"
23
- p.guid = '12AB'
24
- p.save!
25
- assert_equal 0, Post.count_by_solr('aardvark')
26
- end
27
-
28
- def test_type_determined_from_database_if_not_explicitly_set
29
- assert Post.configuration[:solr_fields][:posted_at][:type] == :date
30
- end
31
-
32
- def test_search_includes_subclasses
33
- Novel.create! :name => 'Wuthering Heights', :author => 'Emily Bronte'
34
- Book.create! :name => 'Jane Eyre', :author => 'Charlotte Bronte'
35
- assert_equal 1, Novel.find_by_solr('Bronte').total_hits
36
- assert_equal 2, Book.find_by_solr('Bronte').total_hits
37
- end
38
-
39
- # Testing basic solr search:
40
- # Model.find_by_solr 'term'
41
- # Note that you're able to mix free-search with fields and boolean operators
42
- def test_find_by_solr_ruby
43
- ['ruby', 'dummy', 'name:ruby', 'name:dummy', 'name:ruby AND author:peter',
44
- 'author:peter AND ruby', 'peter dummy'].each do |term|
45
- records = Book.find_by_solr term
46
- assert_equal 1, records.total
47
- assert_equal "Peter McPeterson", records.docs.first.author
48
- assert_equal "Ruby for Dummies", records.docs.first.name
49
- assert_equal ({"id" => 2,
50
- "category_id" => 2,
51
- "name" => "Ruby for Dummies",
52
- "author" => "Peter McPeterson", "published_on" => (Date.today - 2.years), "type" => nil}), records.docs.first.attributes
53
- end
54
- end
55
-
56
- # Testing basic solr search:
57
- # Model.find_by_solr 'term'
58
- # Note that you're able to mix free-search with fields and boolean operators
59
- def test_find_by_solr_splinter
60
- ['splinter', 'name:splinter', 'name:splinter AND author:clancy',
61
- 'author:clancy AND splinter', 'cell tom'].each do |term|
62
- records = Book.find_by_solr term
63
- assert_equal 1, records.total
64
- assert_equal "Splinter Cell", records.docs.first.name
65
- assert_equal "Tom Clancy", records.docs.first.author
66
- assert_equal ({"id" => 1, "category_id" => 1, "name" => "Splinter Cell",
67
- "author" => "Tom Clancy", "published_on" => (Date.today - 1.year), "type" => nil}), records.docs.first.attributes
68
- end
69
- end
70
-
71
- # Testing basic solr search:
72
- # Model.find_by_solr 'term'
73
- # Note that you're able to mix free-search with fields and boolean operators
74
- def test_find_by_solr_ruby_or_splinter
75
- ['ruby OR splinter', 'ruby OR author:tom', 'name:cell OR author:peter', 'dummy OR cell'].each do |term|
76
- records = Book.find_by_solr term
77
- assert_equal 2, records.total
78
- end
79
- end
80
-
81
- # Testing search in indexed field methods:
82
- #
83
- # class Movie < ActiveRecord::Base
84
- # acts_as_solr :fields => [:name, :description, :current_time]
85
- #
86
- # def current_time
87
- # Time.now.to_s
88
- # end
89
- #
90
- # end
91
- #
92
- # The method current_time above gets indexed as being part of the
93
- # Movie model and it's available for search as well
94
- def test_find_with_dynamic_fields
95
- date = Time.now.strftime('%b %d %Y')
96
- ["dynamite AND #{date}", "description:goofy AND #{date}", "goofy napoleon #{date}",
97
- "goofiness #{date}"].each do |term|
98
- records = Movie.find_by_solr term
99
- assert_equal 1, records.total
100
- assert_equal ({"id" => 1, "name" => "Napoleon Dynamite",
101
- "description" => "Cool movie about a goofy guy"}), records.docs.first.attributes
102
- end
103
- end
104
-
105
- # Testing basic solr search that returns just the ids instead of the objects:
106
- # Model.find_id_by_solr 'term'
107
- # Note that you're able to mix free-search with fields and boolean operators
108
- def test_find_id_by_solr_ruby
109
- ['ruby', 'dummy', 'name:ruby', 'name:dummy', 'name:ruby AND author:peter',
110
- 'author:peter AND ruby'].each do |term|
111
- records = Book.find_id_by_solr term
112
- assert_equal 1, records.docs.size
113
- assert_equal [2], records.docs
114
- end
115
- end
116
-
117
- # Testing basic solr search that returns just the ids instead of the objects:
118
- # Model.find_id_by_solr 'term'
119
- # Note that you're able to mix free-search with fields and boolean operators
120
- def test_find_id_by_solr_splinter
121
- ['splinter', 'name:splinter', 'name:splinter AND author:clancy',
122
- 'author:clancy AND splinter'].each do |term|
123
- records = Book.find_id_by_solr term
124
- assert_equal 1, records.docs.size
125
- assert_equal [1], records.docs
126
- end
127
- end
128
-
129
- # Testing basic solr search that returns just the ids instead of the objects:
130
- # Model.find_id_by_solr 'term'
131
- # Note that you're able to mix free-search with fields and boolean operators
132
- def test_find_id_by_solr_ruby_or_splinter
133
- ['ruby OR splinter', 'ruby OR author:tom', 'name:cell OR author:peter',
134
- 'dummy OR cell'].each do |term|
135
- records = Book.find_id_by_solr term
136
- assert_equal 2, records.docs.size
137
- assert_equal [1,2], records.docs
138
- end
139
- end
140
-
141
- # Testing basic solr search that returns the total number of records found:
142
- # Model.find_count_by_solr 'term'
143
- # Note that you're able to mix free-search with fields and boolean operators
144
- def test_count_by_solr
145
- ['ruby', 'dummy', 'name:ruby', 'name:dummy', 'name:ruby AND author:peter',
146
- 'author:peter AND ruby'].each do |term|
147
- assert_equal 1, Book.count_by_solr(term), "there should only be 1 result for search: #{term}"
148
- end
149
- end
150
-
151
- # Testing basic solr search that returns the total number of records found:
152
- # Model.find_count_by_solr 'term'
153
- # Note that you're able to mix free-search with fields and boolean operators
154
- def test_count_by_solr_splinter
155
- ['splinter', 'name:splinter', 'name:splinter AND author:clancy',
156
- 'author:clancy AND splinter', 'author:clancy cell'].each do |term|
157
- assert_equal 1, Book.count_by_solr(term)
158
- end
159
- end
160
-
161
- # Testing basic solr search that returns the total number of records found:
162
- # Model.find_count_by_solr 'term'
163
- # Note that you're able to mix free-search with fields and boolean operators
164
- def test_count_by_solr_ruby_or_splinter
165
- ['ruby OR splinter', 'ruby OR author:tom', 'name:cell OR author:peter', 'dummy OR cell'].each do |term|
166
- assert_equal 2, Book.count_by_solr(term)
167
- end
168
- end
169
-
170
- # Testing basic solr search with additional options:
171
- # Model.find_count_by_solr 'term', :limit => 10, :offset => 0
172
- def test_find_with_options
173
- [1,2].each do |count|
174
- records = Book.find_by_solr 'ruby OR splinter', :limit => count
175
- assert_equal count, records.docs.size
176
- end
177
- end
178
-
179
- # Testing self.rebuild_solr_index
180
- # - It makes sure the index is rebuilt after a data has been lost
181
- def test_rebuild_solr_index
182
- assert_equal 1, Book.count_by_solr('splinter')
183
-
184
- Book.find(:first).solr_destroy
185
- assert_equal 0, Book.count_by_solr('splinter')
186
-
187
- Book.rebuild_solr_index
188
- assert_equal 1, Book.count_by_solr('splinter')
189
- end
190
-
191
- # Testing instance methods:
192
- # - solr_save
193
- # - solr_destroy
194
- def test_solr_save_and_solr_destroy
195
- assert_equal 1, Book.count_by_solr('splinter')
196
-
197
- Book.find(:first).solr_destroy
198
- assert_equal 0, Book.count_by_solr('splinter')
199
-
200
- Book.find(:first).solr_save
201
- assert_equal 1, Book.count_by_solr('splinter')
202
- end
203
-
204
- # Testing the order of results
205
- def test_find_returns_records_in_order
206
- records = Book.find_by_solr 'ruby^5 OR splinter'
207
- # we boosted ruby so ruby should come first
208
-
209
- assert_equal 2, records.total
210
- assert_equal 'Ruby for Dummies', records.docs.first.name
211
- assert_equal 'Splinter Cell', records.docs.last.name
212
- end
213
-
214
- # Testing solr search with optional :order argument
215
- def _test_with_order_option
216
- records = Movie.find_by_solr 'office^5 OR goofiness'
217
- assert_equal 'Hypnotized dude loves fishing but not working', records.docs.first.description
218
- assert_equal 'Cool movie about a goofy guy', records.docs.last.description
219
-
220
- records = Movie.find_by_solr 'office^5 OR goofiness', :order => 'description asc'
221
- assert_equal 'Cool movie about a goofy guy', records.docs.first.description
222
- assert_equal 'Hypnotized dude loves fishing but not working', records.docs.last.description
223
- end
224
-
225
- # Testing search with omitted :field_types should
226
- # return the same result set as if when we use it
227
- def test_omit_field_types_in_search
228
- records = Electronic.find_by_solr "price:[200 TO 599.99]"
229
- assert_match(/599/, records.docs.first.price)
230
- assert_match(/319/, records.docs.last.price)
231
-
232
- records = Electronic.find_by_solr "price:[200 TO 599.99]", :order => 'price asc'
233
- assert_match(/319/, records.docs.first.price)
234
- assert_match(/599/, records.docs.last.price)
235
-
236
- end
237
-
238
- # Test to make sure the result returned when no matches
239
- # are found has the same structure when there are results
240
- def test_returns_no_matches
241
- records = Book.find_by_solr 'rubyist'
242
- assert_equal [], records.docs
243
- assert_equal 0, records.total
244
-
245
- records = Book.find_id_by_solr 'rubyist'
246
- assert_equal [], records.docs
247
- assert_equal 0, records.total
248
-
249
- records = Book.find_by_solr 'rubyist', :facets => {}
250
- assert_equal [], records.docs
251
- assert_equal 0, records.total
252
- assert_equal({"facet_fields"=>[]}, records.facets)
253
- end
254
-
255
-
256
- # Testing the :exclude_fields option when set in the
257
- # model to make sure it doesn't get indexed
258
- def test_exclude_fields_option
259
- records = Electronic.find_by_solr 'audiobooks OR latency'
260
- assert records.docs.empty?
261
- assert_equal 0, records.total
262
-
263
- assert_nothing_raised{
264
- records = Electronic.find_by_solr 'features:audiobooks'
265
- assert records.docs.empty?
266
- assert_equal 0, records.total
267
- }
268
- end
269
-
270
- # Testing the :auto_commit option set to false in the model
271
- # should not send the commit command to Solr
272
- def test_auto_commit_turned_off
273
- assert_equal 0, Author.count_by_solr('raymond chandler')
274
-
275
- original_count = Author.count
276
- Author.create(:name => 'Raymond Chandler', :biography => 'Writes noirish detective stories')
277
-
278
- assert_equal original_count + 1, Author.count
279
- assert_equal 0, Author.count_by_solr('raymond chandler')
280
- end
281
-
282
- # Testing models that use a different key as the primary key
283
- def test_search_on_model_with_string_id_field
284
- records = Posting.find_by_solr 'first^5 OR second'
285
- assert_equal 2, records.total
286
- assert_equal 'ABC-123', records.docs.first.guid
287
- assert_equal 'DEF-456', records.docs.last.guid
288
- end
289
-
290
- # Making sure the result set is ordered correctly even on
291
- # models that use a different key as the primary key
292
- def test_records_in_order_on_model_with_string_id_field
293
- records = Posting.find_by_solr 'first OR second^5'
294
- assert_equal 2, records.total
295
- assert_equal 'DEF-456', records.docs.first.guid
296
- assert_equal 'ABC-123', records.docs.last.guid
297
- end
298
-
299
- # Making sure the records are added when passing a batch size
300
- # to rebuild_solr_index
301
- def test_using_rebuild_solr_index_with_batch
302
- assert_equal 2, Movie.count_by_solr('office OR napoleon')
303
- Movie.find(:all).each(&:solr_destroy)
304
- assert_equal 0, Movie.count_by_solr('office OR napoleon')
305
-
306
- Movie.rebuild_solr_index 100
307
- assert_equal 2, Movie.count_by_solr('office OR napoleon')
308
- end
309
-
310
- # Making sure find_by_solr with scores actually return the scores
311
- # for each individual record
312
- def test_find_by_solr_with_score
313
- books = Book.find_by_solr 'ruby^10 OR splinter', :scores => true
314
- assert_equal 2, books.total
315
- assert_equal 0.41763234, books.max_score
316
-
317
- books.records.each { |book| assert_not_nil book.solr_score }
318
- assert_equal 0.41763234, books.docs.first.solr_score
319
- assert_equal 0.14354616, books.docs.last.solr_score
320
- end
321
-
322
- # Making sure nothing breaks when html entities are inside
323
- # the content to be indexed; and on the search as well.
324
- def test_index_and_search_with_html_entities
325
- description = "
326
- inverted exclamation mark &iexcl; &#161;
327
- ¤ currency &curren; &#164;
328
- ¢ cent &cent; &#162;
329
- £ pound &pound; &#163;
330
- ¥ yen &yen; &#165;
331
- ¦ broken vertical bar &brvbar; &#166;
332
- § section &sect; &#167;
333
- ¨ spacing diaeresis &uml; &#168;
334
- © copyright &copy; &#169;
335
- ª feminine ordinal indicator &ordf; &#170;
336
- « angle quotation mark (left) &laquo; &#171;
337
- ¬ negation &not; &#172;
338
- ­ soft hyphen &shy; &#173;
339
- ® registered trademark &reg; &#174;
340
- ™ trademark &trade; &#8482;
341
- ¯ spacing macron &macr; &#175;
342
- ° degree &deg; &#176;
343
- ± plus-or-minus &plusmn; &#177;
344
- ² superscript 2 &sup2; &#178;
345
- ³ superscript 3 &sup3; &#179;
346
- ´ spacing acute &acute; &#180;
347
- µ micro &micro; &#181;
348
- ¶ paragraph &para; &#182;
349
- · middle dot &middot; &#183;
350
- ¸ spacing cedilla &cedil; &#184;
351
- ¹ superscript 1 &sup1; &#185;
352
- º masculine ordinal indicator &ordm; &#186;
353
- » angle quotation mark (right) &raquo; &#187;
354
- ¼ fraction 1/4 &frac14; &#188;
355
- ½ fraction 1/2 &frac12; &#189;
356
- ¾ fraction 3/4 &frac34; &#190;
357
- ¿ inverted question mark &iquest; &#191;
358
- × multiplication &times; &#215;
359
- ÷ division &divide; &#247
360
- &hearts; &diams; &clubs; &spades;"
361
-
362
- author = Author.create(:name => "Test in Action&trade; - Copyright &copy; Bob", :biography => description)
363
- assert author.valid?
364
- author.solr_commit
365
-
366
- author = Author.find_by_solr 'trademark &copy &#190 &iexcl &#163'
367
- assert_equal 1, author.total
368
- end
369
-
370
- def test_operator_search_option
371
- assert_nothing_raised {
372
- books = Movie.find_by_solr "office napoleon", :operator => :or
373
- assert_equal 2, books.total
374
-
375
- books = Movie.find_by_solr "office napoleon", :operator => :and
376
- assert_equal 0, books.total
377
- }
378
-
379
- assert_raise RuntimeError do
380
- Movie.find_by_solr "office napoleon", :operator => :bad
381
- end
382
- end
383
-
384
- # Making sure find_by_solr with scores actually return the scores
385
- # for each individual record and orders them accordingly
386
- def test_find_by_solr_order_by_score
387
- books = Book.find_by_solr 'ruby^10 OR splinter', {:scores => true, :order => 'score asc' }
388
- assert (books.docs.collect(&:solr_score).compact.size == books.docs.size), "Each book should have a score"
389
- assert_equal 0.41763234, books.docs.last.solr_score
390
-
391
- books = Book.find_by_solr 'ruby^10 OR splinter', {:scores => true, :order => 'score desc' }
392
- assert_equal 0.41763234, books.docs.first.solr_score
393
- assert_equal 0.14354616, books.docs.last.solr_score
394
- end
395
-
396
- # Search based on fields with the :date format
397
- def test_indexed_date_field_format
398
- movies = Movie.find_by_solr 'time_on_xml:[NOW-1DAY TO NOW]'
399
- assert_equal 2, movies.total
400
- end
401
-
402
- def test_query_time_is_returned
403
- results = Book.find_by_solr('ruby')
404
- assert_not_nil(results.query_time)
405
- assert_equal(results.query_time.class,Fixnum)
406
- end
407
-
408
- def test_should_not_index_the_record_when_offline_proc_returns_true
409
- Gadget.search_disabled = true
410
- gadget = Gadget.create(:name => "flipvideo mino")
411
- assert_equal 0, Gadget.find_id_by_solr('flipvideo').total
412
- end
413
- end