xapit 0.2.7 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. data/{CHANGELOG → CHANGELOG.rdoc} +7 -2
  2. data/Gemfile +19 -0
  3. data/LICENSE +4 -4
  4. data/README.rdoc +61 -108
  5. data/Rakefile +11 -10
  6. data/features/facets.feature +93 -82
  7. data/features/finding.feature +196 -138
  8. data/features/indexing.feature +35 -37
  9. data/features/remote_server.feature +10 -0
  10. data/features/step_definitions/xapit_steps.rb +53 -25
  11. data/features/suggestions.feature +20 -14
  12. data/features/support/env.rb +13 -6
  13. data/features/support/xapit_helpers.rb +8 -9
  14. data/lib/generators/xapit/install_generator.rb +14 -0
  15. data/lib/generators/xapit/templates/xapit.ru +6 -0
  16. data/lib/generators/xapit/templates/xapit.yml +11 -0
  17. data/lib/xapit.rb +106 -64
  18. data/lib/xapit/client/collection.rb +150 -0
  19. data/lib/xapit/client/facet.rb +11 -0
  20. data/lib/xapit/client/facet_option.rb +29 -0
  21. data/lib/xapit/client/index_builder.rb +67 -0
  22. data/lib/xapit/client/membership.rb +46 -0
  23. data/lib/xapit/client/model_adapters/abstract_model_adapter.rb +30 -0
  24. data/lib/xapit/client/model_adapters/active_record_adapter.rb +27 -0
  25. data/lib/xapit/client/model_adapters/default_model_adapter.rb +7 -0
  26. data/lib/xapit/client/railtie.rb +18 -0
  27. data/lib/xapit/client/remote_database.rb +21 -0
  28. data/lib/xapit/client/tasks.rb +18 -0
  29. data/lib/xapit/server/app.rb +27 -0
  30. data/lib/xapit/server/database.rb +47 -0
  31. data/lib/xapit/server/indexer.rb +138 -0
  32. data/lib/xapit/server/query.rb +240 -0
  33. data/spec/fixtures/blankdb/flintlock +0 -0
  34. data/spec/fixtures/blankdb/iamchert +1 -0
  35. data/spec/fixtures/blankdb/postlist.DB +0 -0
  36. data/spec/fixtures/blankdb/postlist.baseA +0 -0
  37. data/spec/fixtures/blankdb/record.DB +0 -0
  38. data/spec/fixtures/blankdb/record.baseA +0 -0
  39. data/spec/fixtures/blankdb/termlist.DB +0 -0
  40. data/spec/fixtures/blankdb/termlist.baseA +0 -0
  41. data/spec/fixtures/xapit.ru +13 -0
  42. data/spec/fixtures/xapit.yml +4 -0
  43. data/spec/spec_helper.rb +8 -9
  44. data/spec/support/spec_macros.rb +6 -0
  45. data/spec/{xapit_member.rb → support/xapit_member.rb} +14 -16
  46. data/spec/xapit/client/collection_spec.rb +63 -0
  47. data/spec/xapit/client/facet_option_spec.rb +26 -0
  48. data/spec/xapit/client/facet_spec.rb +13 -0
  49. data/spec/xapit/client/index_builder_spec.rb +66 -0
  50. data/spec/xapit/client/membership_spec.rb +43 -0
  51. data/spec/xapit/client/model_adapters/active_record_adapter_spec.rb +62 -0
  52. data/spec/xapit/client/model_adapters/default_model_adapter_spec.rb +7 -0
  53. data/spec/xapit/client/remote_database_spec.rb +19 -0
  54. data/spec/xapit/server/app_spec.rb +22 -0
  55. data/spec/xapit/server/database_spec.rb +37 -0
  56. data/spec/xapit/server/indexer_spec.rb +82 -0
  57. data/spec/xapit/server/query_spec.rb +43 -0
  58. data/spec/xapit/xapit_spec.rb +28 -0
  59. metadata +124 -93
  60. data/Manifest +0 -60
  61. data/features/sorting.feature +0 -29
  62. data/init.rb +0 -1
  63. data/install.rb +0 -8
  64. data/lib/xapit/adapters/abstract_adapter.rb +0 -47
  65. data/lib/xapit/adapters/active_record_adapter.rb +0 -20
  66. data/lib/xapit/adapters/data_mapper_adapter.rb +0 -10
  67. data/lib/xapit/collection.rb +0 -187
  68. data/lib/xapit/config.rb +0 -84
  69. data/lib/xapit/facet.rb +0 -67
  70. data/lib/xapit/facet_blueprint.rb +0 -59
  71. data/lib/xapit/facet_option.rb +0 -56
  72. data/lib/xapit/index_blueprint.rb +0 -147
  73. data/lib/xapit/indexers/abstract_indexer.rb +0 -116
  74. data/lib/xapit/indexers/classic_indexer.rb +0 -29
  75. data/lib/xapit/indexers/simple_indexer.rb +0 -38
  76. data/lib/xapit/membership.rb +0 -137
  77. data/lib/xapit/query.rb +0 -89
  78. data/lib/xapit/query_parsers/abstract_query_parser.rb +0 -174
  79. data/lib/xapit/query_parsers/classic_query_parser.rb +0 -29
  80. data/lib/xapit/query_parsers/simple_query_parser.rb +0 -75
  81. data/lib/xapit/rake_tasks.rb +0 -13
  82. data/rails_generators/xapit/USAGE +0 -13
  83. data/rails_generators/xapit/templates/setup_xapit.rb +0 -1
  84. data/rails_generators/xapit/templates/xapit.rake +0 -4
  85. data/rails_generators/xapit/xapit_generator.rb +0 -20
  86. data/spec/xapit/adapters/active_record_adapter_spec.rb +0 -31
  87. data/spec/xapit/adapters/data_mapper_adapter_spec.rb +0 -10
  88. data/spec/xapit/collection_spec.rb +0 -176
  89. data/spec/xapit/config_spec.rb +0 -62
  90. data/spec/xapit/facet_blueprint_spec.rb +0 -29
  91. data/spec/xapit/facet_option_spec.rb +0 -80
  92. data/spec/xapit/facet_spec.rb +0 -73
  93. data/spec/xapit/index_blueprint_spec.rb +0 -112
  94. data/spec/xapit/indexers/abstract_indexer_spec.rb +0 -111
  95. data/spec/xapit/indexers/classic_indexer_spec.rb +0 -35
  96. data/spec/xapit/indexers/simple_indexer_spec.rb +0 -69
  97. data/spec/xapit/membership_spec.rb +0 -55
  98. data/spec/xapit/query_parsers/abstract_query_parser_spec.rb +0 -60
  99. data/spec/xapit/query_parsers/classic_query_parser_spec.rb +0 -20
  100. data/spec/xapit/query_parsers/simple_query_parser_spec.rb +0 -86
  101. data/spec/xapit/query_spec.rb +0 -60
  102. data/tasks/spec.rb +0 -9
  103. data/tasks/xapit.rake +0 -1
  104. data/uninstall.rb +0 -5
  105. data/xapit.gemspec +0 -30
@@ -1,138 +1,196 @@
1
- Background:
2
- Given an empty database at "tmp/xapiandatabase"
3
-
4
- Scenario: Query Matching No Records
5
- Given indexed records named "John, Jane"
6
- When I query for "Sam"
7
- Then I should find 0 records
8
-
9
- Scenario: Query Matching One Record
10
- Given indexed records named "John, Jane"
11
- When I query for "John"
12
- Then I should find record named "John"
13
-
14
- Scenario: Query Matching Two Records
15
- Given indexed records named "John Smith, Jane Smith, John Smithsonian"
16
- When I query for "Smith"
17
- Then I should find records named "John Smith, Jane Smith"
18
-
19
- Scenario: Query Field Matching
20
- Given the following indexed records
21
- | name | age |
22
- | John | 23 |
23
- | Jane | 17 |
24
- | Jack | 17 |
25
- When I query "age" matching "17"
26
- Then I should find records named "Jane, Jack"
27
-
28
- Scenario: Query for Page 1
29
- Given 3 indexed records
30
- When I query page 1 at 2 per page
31
- Then I should find 2 records
32
-
33
- Scenario: Query for Page 2
34
- Given 3 indexed records
35
- When I query page 2 at 2 per page
36
- Then I should find 1 record
37
- And I should have 3 records total
38
-
39
- Scenario: Query for All Records Class Agnostic
40
- Given indexed records named "John, Jane"
41
- When I query for "John" on Xapit
42
- Then I should find 1 record
43
-
44
- Scenario: Query Matching Or Query
45
- Given indexed records named "John, Jane, Jacob"
46
- When I query for "Jane OR John"
47
- Then I should find records named "John, Jane"
48
-
49
- Scenario: Query Matching Not Query
50
- Given indexed records named "John Smith, John Johnson"
51
- When I query for "John NOT Smith"
52
- Then I should find records named "John Johnson"
53
-
54
- Scenario: Unicode characters in search
55
- Given indexed records named "über cool, uber hot"
56
- When I query for "über"
57
- Then I should find records named "über cool"
58
-
59
- Scenario: Query Field Not Matching
60
- Given the following indexed records
61
- | name | age |
62
- | John | 23 |
63
- | Jane | 17 |
64
- | Jack | 17 |
65
- When I query "age" not matching "17"
66
- Then I should find records named "John"
67
-
68
- Scenario: Query Range of Integer
69
- Given the following indexed records
70
- | name | age |
71
- | John | 8 |
72
- | Jane | 13 |
73
- | Jack | 24 |
74
- When I query "age" between 8 and 15
75
- Then I should find records named "John, Jane"
76
-
77
- Scenario: Query Partial Match on Condition
78
- Given the following indexed records
79
- | name | sirname |
80
- | John | Jacobson |
81
- | Jane | Niel |
82
- | Jack | Striker |
83
- When I query "name" matching "Ja*"
84
- Then I should find records named "Jane, Jack"
85
-
86
- Scenario: Query no partial match on conditions with one letter
87
- Given the following indexed records
88
- | name | sirname |
89
- | John | Jacobson |
90
- | Jane | Niel |
91
- | Jack | Striker |
92
- When I query "name" matching " J*"
93
- Then I should find 0 records
94
-
95
- Scenario: Query partial match in keywords
96
- Given the following indexed records
97
- | name | sirname |
98
- | John | Jacobson |
99
- | Bill | Niel |
100
- | Jack | Striker |
101
- When I query for "Ja*"
102
- Then I should find records named "John, Jack"
103
-
104
- Scenario: Query no partial match in keywords with one letter
105
- Given the following indexed records
106
- | name | sirname |
107
- | John | Jacobson |
108
- | Bill | Niel |
109
- | Jack | J |
110
- When I query for " J*"
111
- Then I should find records named "Jack"
112
-
113
- Scenario: Query for separate OR conditions
114
- Given the following indexed records
115
- | name | age |
116
- | John | 23 |
117
- | Jane | 17 |
118
- | Jack | 18 |
119
- When I query "age" matching "17" or "name" matching "Jack"
120
- Then I should find records named "Jane, Jack"
121
-
122
- Scenario: Query for condition in keywords string
123
- Given the following indexed records
124
- | name | age |
125
- | John | 23 |
126
- | Jane | 17 |
127
- | Jack | 17 |
128
- When I query for "age:17"
129
- Then I should find records named "Jane, Jack"
130
-
131
- Scenario: Query for separate OR conditions and keywords
132
- Given the following indexed records
133
- | name | age |
134
- | John | 23 |
135
- | Jane | 17 |
136
- | Jack | 18 |
137
- When I query for "John" or "age" matching "18" ordered by "name"
138
- Then I should find records named "Jack, John"
1
+ Feature: Finding
2
+
3
+ Scenario: Query Matching No Records
4
+ Given indexed records named "John, Jane"
5
+ When I query for "Sam"
6
+ Then I should find 0 records
7
+
8
+ Scenario: Query Matching One Record
9
+ Given indexed records named "John, Jane"
10
+ When I query for "John"
11
+ Then I should find record named "John"
12
+
13
+ Scenario: Query Matching Two Records
14
+ Given indexed records named "John Smith, Jane Smith, John Smithsonian"
15
+ When I query for "Smith"
16
+ Then I should find records named "John Smith, Jane Smith"
17
+
18
+ Scenario: Query for All Records Class Agnostic
19
+ Given indexed records named "John, Jane"
20
+ When I query for "John" on Xapit
21
+ Then I should find 1 record
22
+
23
+ Scenario: Query Field Matching
24
+ Given the following indexed records
25
+ | name | age |
26
+ | John | 23 |
27
+ | Jane | 17 |
28
+ | Jack | 17 |
29
+ When I query "age" matching "17"
30
+ Then I should find records named "Jane, Jack"
31
+
32
+ Scenario: Query Text and Field Matching
33
+ Given the following indexed records
34
+ | name | age |
35
+ | Jane | 23 |
36
+ | Jane | 17 |
37
+ | Jack | 17 |
38
+ When I query for "Jane" and "age" matching "17"
39
+ Then I should find records named "Jane"
40
+
41
+ Scenario: Query Field Not Matching
42
+ Given the following indexed records
43
+ | name | age |
44
+ | John | 23 |
45
+ | Jane | 17 |
46
+ | Jack | 17 |
47
+ When I query "age" not matching "17"
48
+ Then I should find records named "John"
49
+
50
+ Scenario: Query for separate OR conditions
51
+ Given the following indexed records
52
+ | name | age |
53
+ | John | 23 |
54
+ | Jane | 17 |
55
+ | Jack | 18 |
56
+ When I query "age" matching "17" or "name" matching "Jack"
57
+ Then I should find records named "Jane, Jack"
58
+
59
+ Scenario: Query Matching Or Query
60
+ Given indexed records named "John, Jane, Jacob"
61
+ When I query for "Jane OR John"
62
+ Then I should find records named "John, Jane"
63
+
64
+ Scenario: Query Matching Not Query
65
+ Given indexed records named "John Smith, John Johnson"
66
+ When I query for "John NOT Smith"
67
+ Then I should find records named "John Johnson"
68
+
69
+ Scenario: Unicode characters in search
70
+ Given indexed records named "über cool, uber hot"
71
+ When I query for "über"
72
+ Then I should find records named "über cool"
73
+
74
+ Scenario: Query for All Records Sorted by Name
75
+ Given indexed records named "Zebra, Apple, Banana"
76
+ When I query "" sorted by name
77
+ Then I should find records named "Apple, Banana, Zebra"
78
+
79
+ Scenario: Query for All Records Sorted by Age then Name
80
+ Given the following indexed records
81
+ | name | age |
82
+ | Banana | 23 |
83
+ | Zebra | 17 |
84
+ | Apple | 17 |
85
+ When I query "" sorted by age, name
86
+ Then I should find records named "Apple, Zebra, Banana"
87
+
88
+ Scenario: Query for All Records Sorted by Name Descending
89
+ Given indexed records named "Zebra, Apple, Banana"
90
+ When I query "" sorted by name descending
91
+ Then I should find records named "Zebra, Banana, Apple"
92
+
93
+ Scenario: Query for Records Sorted Numerically
94
+ Given the following indexed records
95
+ | name | age |
96
+ | Banana | 9 |
97
+ | Zebra | 10 |
98
+ When I query "" sorted by age, name
99
+ Then I should find records named "Banana, Zebra"
100
+
101
+ Scenario: Query for Page 1
102
+ Given 3 indexed records
103
+ When I query page 1 at 2 per page
104
+ Then I should find 2 records
105
+
106
+ Scenario: Query for Page 2
107
+ Given 3 indexed records
108
+ When I query page 2 at 2 per page
109
+ Then I should find 1 record
110
+ And I should have 3 records total
111
+
112
+ Scenario: Query Range of Integer
113
+ Given the following indexed records
114
+ | name | age |
115
+ | John | 8 |
116
+ | Jane | 13 |
117
+ | Jack | 24 |
118
+ When I query "age" between 8 and 15
119
+ Then I should find records named "John, Jane"
120
+
121
+ Scenario: Query for condition in keywords string
122
+ Given the following indexed records
123
+ | name | age |
124
+ | John | 23 |
125
+ | Jane | 17 |
126
+ | Jack | 17 |
127
+ When I query for "age:17"
128
+ Then I should find records named "Jane, Jack"
129
+
130
+ Scenario: Query for separate OR conditions and keywords
131
+ Given the following indexed records
132
+ | name | age |
133
+ | John | 23 |
134
+ | Jane | 17 |
135
+ | Jack | 18 |
136
+ When I query for "John" or "age" matching "18" ordered by "name"
137
+ Then I should find records named "Jack, John"
138
+
139
+
140
+ Scenario: Query partial match in keywords
141
+ Given the following indexed records
142
+ | name | sirname |
143
+ | John | Jacobson |
144
+ | Bill | Niel |
145
+ | Jack | Striker |
146
+ When I query for "Ja*"
147
+ Then I should find records named "John, Jack"
148
+
149
+ Scenario: Query no partial match in keywords with one letter
150
+ Given the following indexed records
151
+ | name | sirname |
152
+ | John | Jacobson |
153
+ | Bill | Niel |
154
+ | Jack | J |
155
+ When I query for "J*"
156
+ Then I should find records named "Jack"
157
+
158
+ Scenario: Query no stemming
159
+ Given indexed records named "runs, sat, sits"
160
+ And no stemming
161
+ When I query for "run"
162
+ Then I should find 0 records
163
+
164
+ Scenario: Query with stemming by default
165
+ Given indexed records named "runs, sat, sits"
166
+ When I query for "run"
167
+ Then I should find records named "runs"
168
+
169
+ Scenario: Query ignore punctuation in keyword
170
+ Given the following indexed records
171
+ | name | sirname |
172
+ | Jack | John-son's |
173
+ | Bill | Johnsons |
174
+ | Jane | Johnson |
175
+ When I query for "Johnsons"
176
+ Then I should find records named "Jack, Bill"
177
+ When I query for "Jo-hn'sons"
178
+ Then I should find records named "Jack, Bill"
179
+
180
+ # Scenario: Query Partial Match on Condition
181
+ # Given the following indexed records
182
+ # | name | sirname |
183
+ # | John | Jacobson |
184
+ # | Jane | Niel |
185
+ # | Jack | Striker |
186
+ # When I query "name" matching "Ja*"
187
+ # Then I should find records named "Jane, Jack"
188
+ #
189
+ # Scenario: Query no partial match on conditions with one letter
190
+ # Given the following indexed records
191
+ # | name | sirname |
192
+ # | John | Jacobson |
193
+ # | Jane | Niel |
194
+ # | Jack | Striker |
195
+ # When I query "name" matching " J*"
196
+ # Then I should find 0 records
@@ -1,41 +1,39 @@
1
- Scenario: Save xapian database on index
2
- Given no file exists at "tmp/xapiandb"
3
- And I configured the database to be saved at "tmp/xapiandb"
4
- And 3 records
5
- When I index the database
6
- Then I should find a directory at "tmp/xapiandb"
1
+ Feature: Indexing
7
2
 
8
- Scenario: Fetch all records which are indexed
9
- Given an empty database at "tmp/xapiandb"
10
- And records named "John, Jane, Joe"
11
- When I index the database
12
- And I query for ""
13
- Then I should find records named "John, Jane, Joe"
3
+ Scenario: Save xapian database on index
4
+ Given no file exists at "tmp/testdb"
5
+ And an empty database at "tmp/testdb"
6
+ And 3 records
7
+ When I index the database
8
+ Then I should find a directory at "tmp/testdb"
14
9
 
15
- Scenario: Split indexed text fields differently
16
- Given an empty database at "tmp/xapiandb"
17
- And records named "JohnXSmith, JaneXSmith, JoeXBlack"
18
- When I index the database splitting name by "X"
19
- And I query for "Smith"
20
- Then I should find records named "JohnXSmith, JaneXSmith"
10
+ Scenario: Fetch all records which are indexed
11
+ And records named "John, Jane, Joe"
12
+ When I index the database
13
+ And I query for ""
14
+ Then I should find records named "John, Jane, Joe"
21
15
 
22
- Scenario: Index Multiple Field Values Separately
23
- Given an empty database at "tmp/xapiandatabase"
24
- And the following indexed records
25
- | name | age |
26
- | John | 17, 16 |
27
- | Jack | 17 |
28
- | Jane | 16 |
29
- When I query "age" matching "16"
30
- Then I should find records named "Jane, John"
16
+ Scenario: Index Multiple Field Values Separately
17
+ And the following indexed records
18
+ | name | age |
19
+ | John | 17, 16 |
20
+ | Jack | 17 |
21
+ | Jane | 16 |
22
+ When I query "age" matching "16"
23
+ Then I should find records named "Jane, John"
31
24
 
32
- Scenario: Index Weighted Attributes
33
- Given an empty database at "tmp/xapiandatabase"
34
- And the following indexed records with "name" weighted by "10"
35
- | name | description |
36
- | foo | bar |
37
- | bar | foo |
38
- When I query for "bar"
39
- Then I should find records named "bar, foo"
40
- When I query for "foo"
41
- Then I should find records named "foo, bar"
25
+ Scenario: Index Weighted Attributes
26
+ And the following indexed records with "name" weighted by "10"
27
+ | name | description |
28
+ | foo | bar |
29
+ | bar | foo |
30
+ When I query for "bar"
31
+ Then I should find records named "bar, foo"
32
+ When I query for "foo"
33
+ Then I should find records named "foo, bar"
34
+
35
+ Scenario: Split indexed text fields differently
36
+ And records named "JohnXSmith, JaneXSmith, JoeXBlack"
37
+ When I index the database splitting name by "X"
38
+ And I query for "Smith"
39
+ Then I should find records named "JohnXSmith, JaneXSmith"
@@ -0,0 +1,10 @@
1
+ # Feature: Remote Server
2
+ #
3
+ # Background:
4
+ # Given a remote database
5
+ #
6
+ # Scenario: Basic index and search
7
+ # Given records named "John Smith, John Doe, Jane, Joe"
8
+ # When I index the database
9
+ # And I query for "John"
10
+ # Then I should find records named "John Smith, John Doe"
@@ -1,11 +1,27 @@
1
- Given /^I configured the database to be saved at "([^\"]*)"$/ do |path|
2
- Xapit.setup(:database_path => File.dirname(__FILE__) + "/../../#{path}")
1
+ Given /^an empty database at "([^\"]*)"$/ do |path|
2
+ path = File.expand_path("../../../#{path}", __FILE__)
3
+ template = File.expand_path("../../../spec/fixtures/blankdb", __FILE__)
4
+ FileUtils.rm_rf(path) if File.exist? path
5
+ FileUtils.cp_r(template, path)
6
+ Xapit.config[:database_path] = path
7
+ XapitMember.delete_all
8
+ GC.start
3
9
  end
4
10
 
5
- Given /^an empty database at "([^\"]*)"$/ do |path|
6
- Xapit.setup(:database_path => File.dirname(__FILE__) + "/../../#{path}")
7
- Xapit.remove_database
11
+ Given /^a remote database$/ do
12
+ $server = IO.popen("rackup spec/fixtures/xapit.ru -p 9797") if $server.nil?
13
+ Xapit.reset_config
14
+ Xapit.config[:server] = "http://localhost:9797"
8
15
  XapitMember.delete_all
16
+ sleep 5
17
+ end
18
+
19
+ Given /^no stemming$/ do
20
+ Xapit.config[:stemming] = nil
21
+ end
22
+
23
+ Given /^spelling is enabled$/ do
24
+ Xapit.config[:spelling] = true
9
25
  end
10
26
 
11
27
  Given /^(indexed )?records? named "([^\"]*)"$/ do |indexed, joined_names|
@@ -32,14 +48,18 @@ Given /^the following indexed records with "([^\"]*)" weighted by "([^\"]*)"$/ d
32
48
  end
33
49
 
34
50
  When /^I index the database$/ do
35
- Xapit.index_all
51
+ XapitMember.find_each do |member|
52
+ member.class.xapit_index_builder.add_document(member)
53
+ end
36
54
  end
37
55
 
38
56
  When /^I index the database splitting name by "([^\"]*)"$/ do |divider|
39
57
  XapitMember.xapit do |index|
40
58
  index.text(:name) { |name| name.split(divider) }
41
59
  end
42
- Xapit.index_all
60
+ XapitMember.find_each do |member|
61
+ member.class.xapit_index_builder.add_document(member)
62
+ end
43
63
  end
44
64
 
45
65
  When /^I query for "([^\"]*)"$/ do |query|
@@ -51,51 +71,58 @@ When /^I query for "([^\"]*)" on Xapit$/ do |query|
51
71
  end
52
72
 
53
73
  When /^I query "([^\"]*)" with facets "([^\"]*)"$/ do |keywords, facets|
54
- @records = XapitMember.search(keywords, :facets => facets)
74
+ @records = XapitMember.search(keywords).with_facets(facets)
55
75
  end
56
76
 
57
77
  Then /^I should find records? named "([^\"]*)"$/ do |joined_names|
58
- @records.map(&:name).join(", ").should == joined_names
78
+ @records.map(&:name).join(", ").should eq(joined_names)
59
79
  end
60
80
 
61
81
  Then /^I should find ([0-9]+) records?$/ do |num|
62
- @records.should have(num.to_i).records
82
+ @records.records.size.should eq(num.to_i)
63
83
  end
64
84
 
65
85
  Then /^I should have ([0-9]+) records? total$/ do |num|
66
- @records.total_entries.should == num.to_i
86
+ @records.total_entries.should eq(num.to_i)
67
87
  end
68
88
 
69
89
  When /^I query "([^\"]*)" matching "([^\"]*)"$/ do |field, value|
70
- @records = XapitMember.search(:conditions => { field.to_sym => value })
90
+ @records = XapitMember.search.where(field.to_sym => value)
91
+ end
92
+
93
+ When /^I query for "([^\"]*)" and "([^\"]*)" matching "([^\"]*)"$/ do |text, field, value|
94
+ @records = XapitMember.search(text).where(field.to_sym => value)
71
95
  end
72
96
 
73
97
  When /^I query "([^\"]*)" not matching "([^\"]*)"$/ do |field, value|
74
- @records = XapitMember.search(:not_conditions => { field.to_sym => value })
98
+ @records = XapitMember.search.not_where(field.to_sym => value)
75
99
  end
76
100
 
77
101
  When /^I query "([^\"]*)" matching "([^\"]*)" or "([^\"]*)" matching "([^\"]*)"$/ do |field1, value1, field2, value2|
78
- @records = XapitMember.search(:conditions => [{ field1.to_sym => value1 }, { field2.to_sym => value2 }])
102
+ @records = XapitMember.search.where(field1.to_sym => value1).or_where(field2.to_sym => value2)
79
103
  end
80
104
 
81
105
  When /^I query for "([^\"]*)" or "([^\"]*)" matching "([^\"]*)" ordered by "([^\"]*)"$/ do |keywords, field, value, order|
82
- @records = XapitMember.search(keywords, :order => order).or_search(:conditions => { field.to_sym => value })
106
+ @records = XapitMember.search(keywords).order(order).or_where(field.to_sym => value)
83
107
  end
84
108
 
85
109
  When /^I query "([^\"]*)" between (\d+) and (\d+)$/ do |field, beginning, ending|
86
- @records = XapitMember.search(:conditions => { field.to_sym => beginning.to_i..ending.to_i })
110
+ @records = XapitMember.search.where(field.to_sym => beginning.to_i..ending.to_i)
87
111
  end
88
112
 
89
113
  When /^I query page ([0-9]+) at ([0-9]+) per page$/ do |page, per_page|
90
- @records = XapitMember.search(:page => page, :per_page => per_page.to_i)
114
+ @records = XapitMember.search.page(page).per(per_page)
91
115
  end
92
116
 
93
117
  When /^I query facets "([^\"]*)"$/ do |facets|
94
- @records = XapitMember.search(:facets => facets)
118
+ @records = XapitMember.search.with_facets(facets)
95
119
  end
96
120
 
97
121
  When /^I query "([^\"]*)" sorted by (.*?)( descending)?$/ do |keywords, sort, descending|
98
- @records = XapitMember.search(:order => sort.split(', '), :descending => descending)
122
+ @records = XapitMember.search
123
+ sort.split(', ').each do |sort|
124
+ @records = @records.order(sort, (descending ? :desc : :asc))
125
+ end
99
126
  end
100
127
 
101
128
  When /^I query for similar records for "([^\"]*)"$/ do |keywords|
@@ -106,28 +133,29 @@ Then /^I should have the following facets$/ do |facets_table|
106
133
  result = []
107
134
  @records.facets.each do |facet|
108
135
  facet.options.each do |option|
109
- result << {
136
+ hash = {
110
137
  "facet" => facet.name,
111
138
  "option" => option.name,
112
139
  "count" => option.count.to_s
113
140
  }
141
+ hash["param"] = option.to_param if facets_table.headers.include? "param"
142
+ result << hash
114
143
  end
115
144
  end
116
- result.should == facets_table.hashes # this is somewhat fragile because it depends on order of hash result
145
+ result.map(&:inspect).sort.should eq(facets_table.hashes.map(&:inspect).sort)
117
146
  end
118
147
 
119
148
  Then /^I should have the following applied facets$/ do |facets_table|
120
149
  result = []
121
150
  @records.applied_facet_options.each do |option|
122
151
  result << {
123
- "facet" => option.facet.name,
152
+ "facet" => option.attribute.sub(/^(.)/) { |c| c.upcase }, # quick hack
124
153
  "option" => option.name
125
154
  }
126
155
  end
127
- result.should == facets_table.hashes # this is somewhat fragile because it depends on order of hash result
156
+ result.map(&:inspect).sort.should eq(facets_table.hashes.map(&:inspect).sort)
128
157
  end
129
158
 
130
159
  Then /^I should have "([^\"]*)" as a spelling suggestion$/ do |term|
131
- @records.spelling_suggestion.should == term
160
+ @records.spelling_suggestion.to_s.should eq(term)
132
161
  end
133
-