greglu-solr-ruby 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES.yml +50 -0
- data/LICENSE.txt +201 -0
- data/README +56 -0
- data/Rakefile +190 -0
- data/examples/delicious_library/dl_importer.rb +60 -0
- data/examples/delicious_library/sample_export.txt +164 -0
- data/examples/marc/marc_importer.rb +106 -0
- data/examples/tang/tang_importer.rb +58 -0
- data/lib/solr.rb +21 -0
- data/lib/solr/connection.rb +179 -0
- data/lib/solr/document.rb +73 -0
- data/lib/solr/exception.rb +13 -0
- data/lib/solr/field.rb +39 -0
- data/lib/solr/importer.rb +19 -0
- data/lib/solr/importer/array_mapper.rb +26 -0
- data/lib/solr/importer/delimited_file_source.rb +38 -0
- data/lib/solr/importer/hpricot_mapper.rb +27 -0
- data/lib/solr/importer/mapper.rb +51 -0
- data/lib/solr/importer/solr_source.rb +43 -0
- data/lib/solr/importer/xpath_mapper.rb +35 -0
- data/lib/solr/indexer.rb +52 -0
- data/lib/solr/request.rb +26 -0
- data/lib/solr/request/add_document.rb +63 -0
- data/lib/solr/request/base.rb +36 -0
- data/lib/solr/request/commit.rb +31 -0
- data/lib/solr/request/delete.rb +50 -0
- data/lib/solr/request/dismax.rb +46 -0
- data/lib/solr/request/index_info.rb +22 -0
- data/lib/solr/request/modify_document.rb +51 -0
- data/lib/solr/request/optimize.rb +21 -0
- data/lib/solr/request/ping.rb +36 -0
- data/lib/solr/request/select.rb +56 -0
- data/lib/solr/request/spellcheck.rb +30 -0
- data/lib/solr/request/standard.rb +374 -0
- data/lib/solr/request/update.rb +23 -0
- data/lib/solr/response.rb +27 -0
- data/lib/solr/response/add_document.rb +17 -0
- data/lib/solr/response/base.rb +42 -0
- data/lib/solr/response/commit.rb +17 -0
- data/lib/solr/response/delete.rb +13 -0
- data/lib/solr/response/dismax.rb +20 -0
- data/lib/solr/response/index_info.rb +26 -0
- data/lib/solr/response/modify_document.rb +17 -0
- data/lib/solr/response/optimize.rb +14 -0
- data/lib/solr/response/ping.rb +28 -0
- data/lib/solr/response/ruby.rb +42 -0
- data/lib/solr/response/select.rb +17 -0
- data/lib/solr/response/spellcheck.rb +20 -0
- data/lib/solr/response/standard.rb +60 -0
- data/lib/solr/response/xml.rb +42 -0
- data/lib/solr/solrtasks.rb +27 -0
- data/lib/solr/util.rb +32 -0
- data/lib/solr/xml.rb +47 -0
- data/script/setup.rb +14 -0
- data/script/solrshell +18 -0
- data/solr-ruby.gemspec +26 -0
- data/solr/conf/admin-extra.html +31 -0
- data/solr/conf/protwords.txt +21 -0
- data/solr/conf/schema.xml +221 -0
- data/solr/conf/scripts.conf +24 -0
- data/solr/conf/solrconfig.xml +394 -0
- data/solr/conf/stopwords.txt +58 -0
- data/solr/conf/synonyms.txt +31 -0
- data/solr/conf/xslt/example.xsl +132 -0
- data/test/conf/admin-extra.html +31 -0
- data/test/conf/protwords.txt +21 -0
- data/test/conf/schema.xml +237 -0
- data/test/conf/scripts.conf +24 -0
- data/test/conf/solrconfig.xml +376 -0
- data/test/conf/stopwords.txt +58 -0
- data/test/conf/synonyms.txt +31 -0
- data/test/functional/server_test.rb +218 -0
- data/test/functional/test_solr_server.rb +104 -0
- data/test/unit/add_document_test.rb +40 -0
- data/test/unit/array_mapper_test.rb +37 -0
- data/test/unit/changes_yaml_test.rb +21 -0
- data/test/unit/commit_test.rb +41 -0
- data/test/unit/connection_test.rb +55 -0
- data/test/unit/data_mapper_test.rb +75 -0
- data/test/unit/delete_test.rb +56 -0
- data/test/unit/delimited_file_source_test.rb +29 -0
- data/test/unit/dismax_request_test.rb +26 -0
- data/test/unit/document_test.rb +69 -0
- data/test/unit/field_test.rb +48 -0
- data/test/unit/hpricot_mapper_test.rb +44 -0
- data/test/unit/hpricot_test_file.xml +26 -0
- data/test/unit/indexer_test.rb +57 -0
- data/test/unit/modify_document_test.rb +24 -0
- data/test/unit/ping_test.rb +51 -0
- data/test/unit/request_test.rb +61 -0
- data/test/unit/response_test.rb +43 -0
- data/test/unit/select_test.rb +25 -0
- data/test/unit/solr_mock_base.rb +40 -0
- data/test/unit/spellcheck_response_test.rb +26 -0
- data/test/unit/spellchecker_request_test.rb +27 -0
- data/test/unit/standard_request_test.rb +324 -0
- data/test/unit/standard_response_test.rb +174 -0
- data/test/unit/suite.rb +16 -0
- data/test/unit/tab_delimited.txt +2 -0
- data/test/unit/util_test.rb +24 -0
- data/test/unit/xpath_mapper_test.rb +38 -0
- data/test/unit/xpath_test_file.xml +25 -0
- metadata +173 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
2
|
+
# (the "License"); you may not use this file except in compliance with
|
|
3
|
+
# the License. You may obtain a copy of the License at
|
|
4
|
+
#
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
#
|
|
7
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
8
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
9
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10
|
+
# See the License for the specific language governing permissions and
|
|
11
|
+
# limitations under the License.
|
|
12
|
+
|
|
13
|
+
require 'solr_mock_base'
|
|
14
|
+
|
|
15
|
+
class CommitTest < SolrMockBaseTestCase
|
|
16
|
+
|
|
17
|
+
def test_commit
|
|
18
|
+
xml = '<?xml version="1.0" encoding="UTF-8"?><response><lst name="responseHeader"><int name="status">0</int><int name="QTime">2</int></lst></response>'
|
|
19
|
+
conn = Solr::Connection.new('http://localhost:9999/solr')
|
|
20
|
+
set_post_return(xml)
|
|
21
|
+
response = conn.send(Solr::Request::Commit.new)
|
|
22
|
+
assert_kind_of Solr::Response::Commit, response
|
|
23
|
+
assert_equal true, response.ok?
|
|
24
|
+
|
|
25
|
+
# test shorthand
|
|
26
|
+
assert_equal true, conn.commit
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# def test_invalid_commit
|
|
30
|
+
# xml = '<?xml version="1.0" encoding="UTF-8"?><response><lst name="responseHeader"><int name="status">1</int><int name="QTime">2</int></lst></response>'
|
|
31
|
+
# conn = Solr::Connection.new('http://localhost:9999/solr')
|
|
32
|
+
# set_post_return(xml)
|
|
33
|
+
# response = conn.send(Solr::Request::Commit.new)
|
|
34
|
+
# assert_kind_of Solr::Response::Commit, response
|
|
35
|
+
# assert_equal false, response.ok?
|
|
36
|
+
#
|
|
37
|
+
# # test shorthand
|
|
38
|
+
# assert_equal false, conn.commit
|
|
39
|
+
# end
|
|
40
|
+
|
|
41
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
2
|
+
# (the "License"); you may not use this file except in compliance with
|
|
3
|
+
# the License. You may obtain a copy of the License at
|
|
4
|
+
#
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
#
|
|
7
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
8
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
9
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10
|
+
# See the License for the specific language governing permissions and
|
|
11
|
+
# limitations under the License.
|
|
12
|
+
|
|
13
|
+
require 'test/unit'
|
|
14
|
+
require 'solr'
|
|
15
|
+
require 'solr_mock_base'
|
|
16
|
+
|
|
17
|
+
class ConnectionTest < SolrMockBaseTestCase
|
|
18
|
+
def test_mock
|
|
19
|
+
connection = Connection.new("http://localhost:9999")
|
|
20
|
+
set_post_return("foo")
|
|
21
|
+
assert_equal "foo", connection.post(Solr::Request::AddDocument.new)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_bad_url
|
|
25
|
+
assert_raise(RuntimeError) do
|
|
26
|
+
Connection.new("ftp://localhost:9999")
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_connection_initialize
|
|
31
|
+
connection = Solr::Connection.new("http://localhost:8983/solr")
|
|
32
|
+
assert_equal 'localhost', connection.url.host
|
|
33
|
+
assert_equal 8983, connection.url.port
|
|
34
|
+
assert_equal '/solr', connection.url.path
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_non_standard_context
|
|
38
|
+
connection = Solr::Connection.new("http://localhost:8983/index")
|
|
39
|
+
assert_equal '/index', connection.url.path
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_xml_response
|
|
43
|
+
connection = Connection.new("http://localhost:9999")
|
|
44
|
+
set_post_return "<bogus/>"
|
|
45
|
+
response = connection.send(Solr::Request::Ping.new)
|
|
46
|
+
assert_equal "<bogus/>", response.raw_response
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def test_ruby_response
|
|
50
|
+
connection = Connection.new("http://localhost:9999")
|
|
51
|
+
set_post_return "{'responseHeader' => {}, 'response' => {}}"
|
|
52
|
+
response = connection.send(Solr::Request::Standard.new(:query => 'foo'))
|
|
53
|
+
assert_equal({'responseHeader' => {}, 'response' => {}}, response.data)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
2
|
+
# (the "License"); you may not use this file except in compliance with
|
|
3
|
+
# the License. You may obtain a copy of the License at
|
|
4
|
+
#
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
#
|
|
7
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
8
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
9
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10
|
+
# See the License for the specific language governing permissions and
|
|
11
|
+
# limitations under the License.
|
|
12
|
+
|
|
13
|
+
require 'solr'
|
|
14
|
+
require 'test/unit'
|
|
15
|
+
|
|
16
|
+
class DataMapperTest < Test::Unit::TestCase
|
|
17
|
+
|
|
18
|
+
def test_static_mapping
|
|
19
|
+
mapping = {:static => "value",
|
|
20
|
+
:static_array => ["value1", "value2"]}
|
|
21
|
+
|
|
22
|
+
mapper = Solr::Importer::Mapper.new(mapping)
|
|
23
|
+
mapped_data = mapper.map({})
|
|
24
|
+
|
|
25
|
+
assert_equal "value", mapped_data[:static]
|
|
26
|
+
assert_equal ["value1", "value2"], mapped_data[:static_array]
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_simple_mapping
|
|
30
|
+
orig_data = {:orig_field => "value",
|
|
31
|
+
:multi1 => "val1", :multi2 => "val2"}
|
|
32
|
+
mapping = {:solr_field => :orig_field,
|
|
33
|
+
:mapped_array => [:multi1, :multi2], }
|
|
34
|
+
|
|
35
|
+
mapper = Solr::Importer::Mapper.new(mapping)
|
|
36
|
+
mapped_data = mapper.map(orig_data)
|
|
37
|
+
|
|
38
|
+
assert_equal "value", mapped_data[:solr_field]
|
|
39
|
+
assert_equal ["val1", "val2"], mapped_data[:mapped_array]
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_proc
|
|
43
|
+
orig_data = {:orig_field => "value"}
|
|
44
|
+
mapping = {:solr_field => Proc.new {|record| ">#{record[:orig_field]}<"}}
|
|
45
|
+
|
|
46
|
+
mapper = Solr::Importer::Mapper.new(mapping)
|
|
47
|
+
mapped_data = mapper.map(orig_data)
|
|
48
|
+
|
|
49
|
+
assert_equal ">value<", mapped_data[:solr_field]
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def test_overridden_field
|
|
53
|
+
mapping = {:solr_field => [:orig_field1, :orig_field2]}
|
|
54
|
+
orig_data = {:orig_field1 => "value1", :orig_field2 => "value2", }
|
|
55
|
+
|
|
56
|
+
mapper = Solr::Importer::Mapper.new(mapping)
|
|
57
|
+
def mapper.field_data(orig_data, field_name)
|
|
58
|
+
["~#{super(orig_data, field_name)}~"] # array tests that the value is flattened
|
|
59
|
+
end
|
|
60
|
+
mapped_data = mapper.map(orig_data)
|
|
61
|
+
|
|
62
|
+
assert_equal ["~value1~", "~value2~"], mapped_data[:solr_field]
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def test_unknown_mapping
|
|
66
|
+
mapping = {:solr_field => /foo/} # regexp currently not a valid mapping type
|
|
67
|
+
|
|
68
|
+
mapper = Solr::Importer::Mapper.new(mapping)
|
|
69
|
+
|
|
70
|
+
assert_raise(RuntimeError) do
|
|
71
|
+
mapped_data = mapper.map({})
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
2
|
+
# (the "License"); you may not use this file except in compliance with
|
|
3
|
+
# the License. You may obtain a copy of the License at
|
|
4
|
+
#
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
#
|
|
7
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
8
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
9
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10
|
+
# See the License for the specific language governing permissions and
|
|
11
|
+
# limitations under the License.
|
|
12
|
+
|
|
13
|
+
require 'solr_mock_base'
|
|
14
|
+
|
|
15
|
+
class DeleteTest < SolrMockBaseTestCase
|
|
16
|
+
|
|
17
|
+
def test_delete_request
|
|
18
|
+
request = Solr::Request::Delete.new(:id => '123')
|
|
19
|
+
assert_match(/<delete>[\s]*<id>123<\/id>[\s]*<\/delete>/m, request.to_s)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_delete_by_query_request
|
|
23
|
+
request = Solr::Request::Delete.new(:query => 'name:summers')
|
|
24
|
+
assert_match(/<delete>[\s]*<query>name:summers<\/query>[\s]*<\/delete>/m, request.to_s)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_delete_response
|
|
28
|
+
conn = Solr::Connection.new 'http://localhost:9999/solr'
|
|
29
|
+
set_post_return('<?xml version="1.0" encoding="UTF-8"?><response><lst name="responseHeader"><int name="status">0</int><int name="QTime">2</int></lst></response>')
|
|
30
|
+
response = conn.send(Solr::Request::Delete.new(:id => 123))
|
|
31
|
+
assert_equal true, response.ok?
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_bad_delete_request
|
|
35
|
+
assert_raise(Solr::Exception) do
|
|
36
|
+
Solr::Request::Delete.new(:bogus => :param)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
assert_raise(Solr::Exception) do
|
|
40
|
+
Solr::Request::Delete.new(:id => 529, :query => "id:529")
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def test_bad_delete_response
|
|
45
|
+
conn = Solr::Connection.new 'http://localhost:9999/solr'
|
|
46
|
+
set_post_return('<result status="400">uhoh</result>')
|
|
47
|
+
response = conn.send(Solr::Request::Delete.new(:id => 123))
|
|
48
|
+
assert_equal false, response.ok?
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_delete_by_i18n_query_request
|
|
52
|
+
request = Solr::Request::Delete.new(:query => 'ëäïöü')
|
|
53
|
+
assert_match(/<delete>[\s]*<query>ëäïöü<\/query>[\s]*<\/delete>/m, request.to_s)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
2
|
+
# (the "License"); you may not use this file except in compliance with
|
|
3
|
+
# the License. You may obtain a copy of the License at
|
|
4
|
+
#
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
#
|
|
7
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
8
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
9
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10
|
+
# See the License for the specific language governing permissions and
|
|
11
|
+
# limitations under the License.
|
|
12
|
+
|
|
13
|
+
require 'solr'
|
|
14
|
+
require 'test/unit'
|
|
15
|
+
|
|
16
|
+
class DelimitedFileSourceTest < Test::Unit::TestCase
|
|
17
|
+
|
|
18
|
+
def test_load
|
|
19
|
+
filename = File.expand_path(File.dirname(__FILE__)) + "/tab_delimited.txt"
|
|
20
|
+
|
|
21
|
+
source = Solr::Importer::DelimitedFileSource.new(filename,/\t/)
|
|
22
|
+
assert_equal source.to_a.size, 1
|
|
23
|
+
|
|
24
|
+
source.each do |data|
|
|
25
|
+
assert_equal data[:asin], '0865681740'
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
2
|
+
# (the "License"); you may not use this file except in compliance with
|
|
3
|
+
# the License. You may obtain a copy of the License at
|
|
4
|
+
#
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
#
|
|
7
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
8
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
9
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10
|
+
# See the License for the specific language governing permissions and
|
|
11
|
+
# limitations under the License.
|
|
12
|
+
|
|
13
|
+
require 'test/unit'
|
|
14
|
+
require 'solr'
|
|
15
|
+
|
|
16
|
+
class DismaxRequestTest < Test::Unit::TestCase
|
|
17
|
+
|
|
18
|
+
def test_basic_query
|
|
19
|
+
request = Solr::Request::Dismax.new(:query => 'query', :phrase_slop => '1000', :sort => [{:deedle => :descending}])
|
|
20
|
+
assert_match(/q=query/, request.to_s)
|
|
21
|
+
assert_match(/qt=dismax/, request.to_s)
|
|
22
|
+
assert_match(/ps=1000/, request.to_s)
|
|
23
|
+
assert_match(/sort=deedle%20desc/, request.to_s)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
2
|
+
# (the "License"); you may not use this file except in compliance with
|
|
3
|
+
# the License. You may obtain a copy of the License at
|
|
4
|
+
#
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
#
|
|
7
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
8
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
9
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10
|
+
# See the License for the specific language governing permissions and
|
|
11
|
+
# limitations under the License.
|
|
12
|
+
|
|
13
|
+
require 'test/unit'
|
|
14
|
+
require 'solr'
|
|
15
|
+
|
|
16
|
+
class DocumentTest < Test::Unit::TestCase
|
|
17
|
+
|
|
18
|
+
def test_xml
|
|
19
|
+
doc = Solr::Document.new
|
|
20
|
+
doc << Solr::Field.new(:creator => 'Erik Hatcher')
|
|
21
|
+
assert_kind_of Solr::XML::Element, doc.to_xml
|
|
22
|
+
assert_match(/<doc>[\s]*<field name=['"]creator['"]>Erik Hatcher<\/field>[\s]*<\/doc>/m, doc.to_xml.to_s)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_repeatable
|
|
26
|
+
doc = Solr::Document.new
|
|
27
|
+
doc << Solr::Field.new(:creator => 'Erik Hatcher')
|
|
28
|
+
doc << Solr::Field.new(:creator => 'Otis Gospodnetic')
|
|
29
|
+
assert_kind_of Solr::XML::Element, doc.to_xml
|
|
30
|
+
assert_match(/<doc>[\s]*<field name=['"]creator['"]>Erik Hatcher<\/field>[\s]*<field name=['"]creator['"]>Otis Gospodnetic<\/field>[\s]*<\/doc>/m, doc.to_xml.to_s)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_repeatable_in_hash
|
|
34
|
+
doc = Solr::Document.new({:creator => ['Erik Hatcher', 'Otis Gospodnetic']})
|
|
35
|
+
assert_match(/<doc>[\s]*<field name=['"]creator['"]>Erik Hatcher<\/field>[\s]*<field name=['"]creator['"]>Otis Gospodnetic<\/field>[\s]*<\/doc>/m, doc.to_xml.to_s)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def test_bad_doc
|
|
39
|
+
doc = Solr::Document.new
|
|
40
|
+
assert_raise(RuntimeError) do
|
|
41
|
+
doc << "invalid"
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_hash_shorthand
|
|
46
|
+
doc = Solr::Document.new :creator => 'Erik Hatcher', :title => 'Lucene in Action'
|
|
47
|
+
assert_equal 'Erik Hatcher', doc[:creator]
|
|
48
|
+
assert_equal 'Lucene in Action', doc[:title]
|
|
49
|
+
assert_equal nil, doc[:foo]
|
|
50
|
+
|
|
51
|
+
doc = Solr::Document.new
|
|
52
|
+
doc << {:creator => 'Erik Hatcher', :title => 'Lucene in Action'}
|
|
53
|
+
doc[:subject] = 'Search'
|
|
54
|
+
assert_equal 'Erik Hatcher', doc[:creator]
|
|
55
|
+
assert_equal 'Lucene in Action', doc[:title]
|
|
56
|
+
assert_equal 'Search', doc[:subject]
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def test_boost
|
|
60
|
+
doc = Solr::Document.new :name => "McGrump"
|
|
61
|
+
doc.boost = 300.28
|
|
62
|
+
assert_match(/<doc boost=['"]300.28['"]>[\s]*<field name=['"]name['"]>McGrump<\/field>[\s]*<\/doc>/, doc.to_xml.to_s)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def test_string_values
|
|
66
|
+
doc = Solr::Document.new :name => "multi\nline"
|
|
67
|
+
assert_match(/<doc>[\s]*<field name=['"]name['"]>multi\nline<\/field>[\s]*<\/doc>/, doc.to_xml.to_s)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
2
|
+
# (the "License"); you may not use this file except in compliance with
|
|
3
|
+
# the License. You may obtain a copy of the License at
|
|
4
|
+
#
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
#
|
|
7
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
8
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
9
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10
|
+
# See the License for the specific language governing permissions and
|
|
11
|
+
# limitations under the License.
|
|
12
|
+
|
|
13
|
+
require 'test/unit'
|
|
14
|
+
require 'solr'
|
|
15
|
+
|
|
16
|
+
class FieldTest < Test::Unit::TestCase
|
|
17
|
+
|
|
18
|
+
def test_xml
|
|
19
|
+
field = Solr::Field.new :creator => 'Erik Hatcher'
|
|
20
|
+
assert_kind_of Solr::XML::Element, field.to_xml
|
|
21
|
+
assert_match(/<field name=["']creator["']>Erik Hatcher<\/field>/, field.to_xml.to_s)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_escaped_xml
|
|
25
|
+
field = Solr::Field.new :creator => 'Erik Hatcher & His Amazing Leaping Ability'
|
|
26
|
+
assert_kind_of Solr::XML::Element, field.to_xml
|
|
27
|
+
assert_match(/<field name=["']creator["']>Erik Hatcher & His Amazing Leaping Ability<\/field>/, field.to_xml.to_s)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_xml_date
|
|
31
|
+
field = Solr::Field.new :time => Time.now
|
|
32
|
+
assert_kind_of Solr::XML::Element, field.to_xml
|
|
33
|
+
assert_match(/<field name=["']time["']>[\d]{4}-[\d]{2}-[\d]{2}T[\d]{2}:[\d]{2}:[\d]{2}Z<\/field>/, field.to_xml.to_s)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_i18n_xml
|
|
37
|
+
field = Solr::Field.new :i18nstring => 'Äêâîôû Öëäïöü'
|
|
38
|
+
assert_kind_of Solr::XML::Element, field.to_xml
|
|
39
|
+
assert_match(/<field name=["']i18nstring["']>Äêâîôû Öëäïöü<\/field>/m, field.to_xml.to_s)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_boost_values
|
|
43
|
+
field = Solr::Field.new(:blah => "squee", :boost => 3.0)
|
|
44
|
+
assert_kind_of Solr::XML::Element, field.to_xml
|
|
45
|
+
assert_match(/<field name=["']blah["'] boost=["']3.0["']>squee<\/field>/, field.to_xml.to_s)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
2
|
+
# (the "License"); you may not use this file except in compliance with
|
|
3
|
+
# the License. You may obtain a copy of the License at
|
|
4
|
+
#
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
#
|
|
7
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
8
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
9
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10
|
+
# See the License for the specific language governing permissions and
|
|
11
|
+
# limitations under the License.
|
|
12
|
+
|
|
13
|
+
begin
|
|
14
|
+
require 'solr'
|
|
15
|
+
require 'test/unit'
|
|
16
|
+
require 'hpricot'
|
|
17
|
+
|
|
18
|
+
class HpricotMapperTest < Test::Unit::TestCase
|
|
19
|
+
|
|
20
|
+
def setup
|
|
21
|
+
@doc = open(File.expand_path(File.dirname(__FILE__)) + "/hpricot_test_file.xml"){|f| Hpricot.XML(f)}
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_simple_hpricot_path
|
|
25
|
+
mapping = {:field1 => :'child[@attribute="attribute1"]',
|
|
26
|
+
:field2 => :'child[@attribute="attribute2"]',
|
|
27
|
+
:field3 => :'child[@attribute="attribute3"]',
|
|
28
|
+
:field4 => :'child[@attribute="attribute3"] grandchild',
|
|
29
|
+
:field5 => :'child'}
|
|
30
|
+
|
|
31
|
+
mapper = Solr::Importer::HpricotMapper.new(mapping)
|
|
32
|
+
mapped_data = mapper.map(@doc)
|
|
33
|
+
|
|
34
|
+
assert_equal ['text1'], mapped_data[:field1]
|
|
35
|
+
assert_equal ['text2'], mapped_data[:field2]
|
|
36
|
+
assert_equal ['text3<grandchild>grandchild 3 text</grandchild>'], mapped_data[:field3]
|
|
37
|
+
assert_equal ['grandchild 3 text'], mapped_data[:field4]
|
|
38
|
+
assert_equal ['text1', 'text2', 'text3<grandchild>grandchild 3 text</grandchild>'], mapped_data[:field5]
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
rescue LoadError => e
|
|
43
|
+
puts "HpricotMapperTest not run because #{e}"
|
|
44
|
+
end
|