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,26 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
/**
|
|
3
|
+
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
4
|
+
* contributor license agreements. See the NOTICE file distributed with
|
|
5
|
+
* this work for additional information regarding copyright ownership.
|
|
6
|
+
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
7
|
+
* (the "License"); you may not use this file except in compliance with
|
|
8
|
+
* the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
-->
|
|
20
|
+
<root>
|
|
21
|
+
<parent>
|
|
22
|
+
<child attribute="attribute1">text1</child>
|
|
23
|
+
<child attribute="attribute2">text2</child>
|
|
24
|
+
<child attribute="attribute3">text3<grandchild>grandchild 3 text</grandchild></child>
|
|
25
|
+
</parent>
|
|
26
|
+
</root>
|
|
@@ -0,0 +1,57 @@
|
|
|
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 Solr::Indexer
|
|
17
|
+
attr_reader :added
|
|
18
|
+
def add_docs(doc)
|
|
19
|
+
@added ||= []
|
|
20
|
+
@added << doc
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
class IndexerTest < Test::Unit::TestCase
|
|
25
|
+
def test_mapping_or_mapping
|
|
26
|
+
mapping = {:field => "foo"}
|
|
27
|
+
indexer = Solr::Indexer.new([1,2,3], mapping, :debug => true)
|
|
28
|
+
indexer.index
|
|
29
|
+
assert_equal 3, indexer.added.size
|
|
30
|
+
|
|
31
|
+
indexer = Solr::Indexer.new([1,2,3,4], Solr::Importer::Mapper.new(mapping), :debug => true)
|
|
32
|
+
indexer.index
|
|
33
|
+
assert_equal 4, indexer.added.size
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_batch
|
|
37
|
+
mapping = {:field => "foo"}
|
|
38
|
+
indexer = Solr::Indexer.new([1,2,3], mapping, :debug => true, :buffer_docs => 2)
|
|
39
|
+
indexer.index
|
|
40
|
+
assert_equal 2, indexer.added.size
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# source = DataSource.new
|
|
47
|
+
#
|
|
48
|
+
# mapping = {
|
|
49
|
+
# :id => :isbn,
|
|
50
|
+
# :name => :author,
|
|
51
|
+
# :source => "BOOKS",
|
|
52
|
+
# :year => Proc.new {|record| record.date[0,4] },
|
|
53
|
+
# }
|
|
54
|
+
#
|
|
55
|
+
# Solr::Indexer.index(source, mapper) do |orig_data, solr_document|
|
|
56
|
+
# solr_document[:timestamp] = Time.now
|
|
57
|
+
# end
|
|
@@ -0,0 +1,24 @@
|
|
|
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 ModifyDocumentTest < Test::Unit::TestCase
|
|
17
|
+
|
|
18
|
+
def test_update_formatting
|
|
19
|
+
request = Solr::Request::ModifyDocument.new(:id => 10, :overwrite => {:name => ['val1', 'val2'], :copyfield => nil})
|
|
20
|
+
assert_equal :xml, request.response_format
|
|
21
|
+
assert_match /copyfield\:OVERWRITE/, request.handler
|
|
22
|
+
assert_match /name\:OVERWRITE/, request.handler
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
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 PingTest < SolrMockBaseTestCase
|
|
16
|
+
|
|
17
|
+
def test_ping_response
|
|
18
|
+
xml =
|
|
19
|
+
<<PING_RESPONSE
|
|
20
|
+
|
|
21
|
+
<?xml-stylesheet type="text/xsl" href="ping.xsl"?>
|
|
22
|
+
|
|
23
|
+
<solr>
|
|
24
|
+
<ping>
|
|
25
|
+
|
|
26
|
+
</ping>
|
|
27
|
+
</solr>
|
|
28
|
+
PING_RESPONSE
|
|
29
|
+
conn = Solr::Connection.new('http://localhost:9999')
|
|
30
|
+
set_post_return(xml)
|
|
31
|
+
response = conn.send(Solr::Request::Ping.new)
|
|
32
|
+
assert_kind_of Solr::Response::Ping, response
|
|
33
|
+
assert_equal true, response.ok?
|
|
34
|
+
|
|
35
|
+
# test shorthand
|
|
36
|
+
assert true, conn.ping
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_bad_ping_response
|
|
40
|
+
xml = "<foo>bar</foo>"
|
|
41
|
+
conn = Solr::Connection.new('http://localhost:9999')
|
|
42
|
+
set_post_return(xml)
|
|
43
|
+
response = conn.send(Solr::Request::Ping.new)
|
|
44
|
+
assert_kind_of Solr::Response::Ping, response
|
|
45
|
+
assert_equal false, response.ok?
|
|
46
|
+
|
|
47
|
+
# test shorthand
|
|
48
|
+
assert_equal false, conn.ping
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
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 BadRequest < Solr::Request::Base
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class RequestTest < Test::Unit::TestCase
|
|
20
|
+
|
|
21
|
+
def test_commit_request
|
|
22
|
+
request = Solr::Request::Commit.new
|
|
23
|
+
assert_equal :xml, request.response_format
|
|
24
|
+
assert_equal 'update', request.handler
|
|
25
|
+
assert_match(/<commit waitSearcher=["']true["'] waitFlush=["'']true["'']\/>/, request.to_s)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_add_doc_request
|
|
29
|
+
request = Solr::Request::AddDocument.new(:title => "title")
|
|
30
|
+
assert_match(/<add>[\s]*<doc>[\s]*<field name=["']title["']>title<\/field>[\s]*<\/doc>[\s]*<\/add>/m, request.to_s)
|
|
31
|
+
assert_equal :xml, request.response_format
|
|
32
|
+
assert_equal 'update', request.handler
|
|
33
|
+
|
|
34
|
+
assert_raise(RuntimeError) do
|
|
35
|
+
Solr::Request::AddDocument.new("invalid")
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_add_multidoc_request
|
|
40
|
+
request = Solr::Request::AddDocument.new([{:title => "title1"}, {:title => "title2"}])
|
|
41
|
+
assert_match(/<add>[\s]*<doc>[\s]*<field name=["']title["']>title1<\/field>[\s]*<\/doc>[\s]*<doc>[\s]*<field name=["']title["']>title2<\/field>[\s]*<\/doc>[\s]*<\/add>/m, request.to_s)
|
|
42
|
+
assert_equal :xml, request.response_format
|
|
43
|
+
assert_equal 'update', request.handler
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def test_ping_request
|
|
47
|
+
request = Solr::Request::Ping.new
|
|
48
|
+
assert_equal :xml, request.response_format
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_bad_request_class
|
|
52
|
+
assert_raise(RuntimeError) do
|
|
53
|
+
BadRequest.new.response_format
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
assert_raise(RuntimeError) do
|
|
57
|
+
BadRequest.new.handler
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
|
|
18
|
+
class ResponseTest < SolrMockBaseTestCase
|
|
19
|
+
|
|
20
|
+
def test_response_xml_error
|
|
21
|
+
begin
|
|
22
|
+
Solr::Response::Xml.new("<broken>invalid xml&")
|
|
23
|
+
flunk("failed to get Solr::Exception as expected")
|
|
24
|
+
rescue Exception => exception
|
|
25
|
+
assert_kind_of Solr::Exception, exception
|
|
26
|
+
assert_match 'invalid response xml', exception.to_s
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_invalid_ruby
|
|
31
|
+
assert_raise(Solr::Exception) do
|
|
32
|
+
Solr::Response::Ruby.new(' {...')
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# This is now an acceptable use of Select, for the default request handler with no parameters (other than &wt=ruby)
|
|
37
|
+
# def test_bogus_request_handling
|
|
38
|
+
# assert_raise(Solr::Exception) do
|
|
39
|
+
# Solr::Response::Base.make_response(Solr::Request::Select.new, "response data")
|
|
40
|
+
# end
|
|
41
|
+
# end
|
|
42
|
+
|
|
43
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
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 SelectTest < Test::Unit::TestCase
|
|
17
|
+
|
|
18
|
+
def test_basic_query
|
|
19
|
+
request = Solr::Request::Select.new('custom', :q => 'query')
|
|
20
|
+
assert_equal :ruby, request.response_format
|
|
21
|
+
assert_equal 'select', request.handler
|
|
22
|
+
assert_equal 'query', request.to_hash[:q]
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
# TODO: Maybe replace this with flexmock
|
|
17
|
+
class SolrMockBaseTestCase < Test::Unit::TestCase
|
|
18
|
+
include Solr
|
|
19
|
+
|
|
20
|
+
def setup
|
|
21
|
+
Connection.send(:alias_method, :orig_post, :post)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def teardown
|
|
25
|
+
Connection.send(:alias_method, :post, :orig_post)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def set_post_return(value)
|
|
29
|
+
Connection.class_eval %{
|
|
30
|
+
def post(request)
|
|
31
|
+
%q{#{value}}
|
|
32
|
+
end
|
|
33
|
+
}
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_dummy
|
|
37
|
+
# So Test::Unit is happy running this class
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
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 'solr_mock_base'
|
|
14
|
+
|
|
15
|
+
class SpellcheckResponseTest < SolrMockBaseTestCase
|
|
16
|
+
def test_basic
|
|
17
|
+
ruby_code = "{'responseHeader'=>{'status'=>0,'QTime'=>5},'suggestions'=>['whately','whatcha','whatever']}"
|
|
18
|
+
conn = Solr::Connection.new 'http://localhost:9999'
|
|
19
|
+
set_post_return(ruby_code)
|
|
20
|
+
response = conn.send(Solr::Request::Spellcheck.new(:query => 'whateva'))
|
|
21
|
+
assert_equal true, response.ok?
|
|
22
|
+
assert_equal 3, response.suggestions.size
|
|
23
|
+
assert_equal ['whately','whatcha','whatever'], response.suggestions
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
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 SpellcheckRequestTest < Test::Unit::TestCase
|
|
17
|
+
def test_spellcheck_request
|
|
18
|
+
request = Solr::Request::Spellcheck.new(:query => 'whateva', :suggestion_count => 5, :accuracy => 0.7, :only_more_popular => true)
|
|
19
|
+
assert_equal :ruby, request.response_format
|
|
20
|
+
assert_equal 'select', request.handler
|
|
21
|
+
hash = request.to_hash
|
|
22
|
+
assert_equal 'whateva', hash[:q]
|
|
23
|
+
assert_equal 5, hash[:suggestionCount]
|
|
24
|
+
assert_equal 0.7, hash[:accuracy]
|
|
25
|
+
assert_equal true, hash[:onlyMorePopular]
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,324 @@
|
|
|
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 StandardRequestTest < Test::Unit::TestCase
|
|
17
|
+
|
|
18
|
+
def test_basic_query
|
|
19
|
+
request = Solr::Request::Standard.new(:query => 'query')
|
|
20
|
+
assert_equal :ruby, request.response_format
|
|
21
|
+
assert_equal 'select', request.handler
|
|
22
|
+
assert_equal 'query', request.to_hash[:q]
|
|
23
|
+
assert_match /q=query/, request.to_s
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_bad_params
|
|
27
|
+
assert_raise(RuntimeError) do
|
|
28
|
+
Solr::Request::Standard.new(:foo => "invalid")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
assert_raise(RuntimeError) do
|
|
32
|
+
Solr::Request::Standard.new(:query => "valid", :foo => "invalid")
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
assert_raise(RuntimeError) do
|
|
36
|
+
Solr::Request::Standard.new(:query => "valid", :operator => :bogus)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_common_params
|
|
41
|
+
request = Solr::Request::Standard.new(:query => 'query', :start => 10, :rows => 50,
|
|
42
|
+
:filter_queries => ['fq1', 'fq2'], :field_list => ['id','title','score'], :operator => :and)
|
|
43
|
+
assert_equal 10, request.to_hash[:start]
|
|
44
|
+
assert_equal 50, request.to_hash[:rows]
|
|
45
|
+
assert_equal ['fq1','fq2'], request.to_hash[:fq]
|
|
46
|
+
assert_equal "id,title,score", request.to_hash[:fl]
|
|
47
|
+
assert_equal "AND", request.to_hash["q.op"]
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_missing_params
|
|
51
|
+
request = Solr::Request::Standard.new(:query => 'query', :debug_query => false, :facets => {:fields =>[:category_facet]})
|
|
52
|
+
assert_nil request.to_hash[:rows]
|
|
53
|
+
assert_no_match /rows/, request.to_s
|
|
54
|
+
assert_no_match /facet\.sort/, request.to_s
|
|
55
|
+
assert_match /debugQuery/, request.to_s
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def test_only_facet_query
|
|
59
|
+
request = Solr::Request::Standard.new(:query => 'query',
|
|
60
|
+
:facets => {
|
|
61
|
+
:queries => ["q1", "q2"],
|
|
62
|
+
}
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
hash = request.to_hash
|
|
66
|
+
assert_equal ["q1", "q2"], hash["facet.query"]
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def test_facet_params_all
|
|
70
|
+
request = Solr::Request::Standard.new(:query => 'query',
|
|
71
|
+
:facets => {
|
|
72
|
+
:fields => [:genre,
|
|
73
|
+
# field that overrides the global facet parameters
|
|
74
|
+
{:year => {:limit => 50, :mincount => 0, :missing => false, :sort => :term, :prefix=>"199", :offset => 7}}],
|
|
75
|
+
:queries => ["q1", "q2"],
|
|
76
|
+
:prefix => "cat",
|
|
77
|
+
:offset => 3, :limit => 5, :zeros => true, :mincount => 20, :sort => :count # global facet parameters
|
|
78
|
+
}
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
hash = request.to_hash
|
|
82
|
+
assert_equal true, hash[:facet]
|
|
83
|
+
assert_equal [:genre, :year], hash["facet.field"]
|
|
84
|
+
assert_equal ["q1", "q2"], hash["facet.query"]
|
|
85
|
+
assert_equal 5, hash["facet.limit"]
|
|
86
|
+
assert_equal 20, hash["facet.mincount"]
|
|
87
|
+
assert_equal true, hash["facet.sort"]
|
|
88
|
+
assert_equal "cat", hash["facet.prefix"]
|
|
89
|
+
assert_equal 50, hash["f.year.facet.limit"]
|
|
90
|
+
assert_equal 0, hash["f.year.facet.mincount"]
|
|
91
|
+
assert_equal false, hash["f.year.facet.sort"]
|
|
92
|
+
assert_equal "199", hash["f.year.facet.prefix"]
|
|
93
|
+
assert_equal 3, hash["facet.offset"]
|
|
94
|
+
assert_equal 7, hash["f.year.facet.offset"]
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def test_basic_sort
|
|
98
|
+
request = Solr::Request::Standard.new(:query => 'query', :sort => [{:title => :descending}, {:date => :ascending}])
|
|
99
|
+
assert_equal 'query', request.to_hash[:q]
|
|
100
|
+
assert_equal 'title desc,date asc', request.to_hash[:sort]
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def test_highlighting
|
|
104
|
+
request = Solr::Request::Standard.new(:query => 'query',
|
|
105
|
+
:highlighting => {
|
|
106
|
+
:field_list => ['title', 'author'],
|
|
107
|
+
:merge_contiguous => true,
|
|
108
|
+
:increment => 100,
|
|
109
|
+
:max_snippets => 3,
|
|
110
|
+
:require_field_match => true,
|
|
111
|
+
:prefix => "<blink>",
|
|
112
|
+
:suffix => "</blink>",
|
|
113
|
+
:fragment_size => 300,
|
|
114
|
+
:max_analyzed_chars => 102400,
|
|
115
|
+
:formatter => 'myFormatter',
|
|
116
|
+
:fragmenter => 'myFragmenter',
|
|
117
|
+
:use_phrase_highlighter => true
|
|
118
|
+
}
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
hash = request.to_hash
|
|
122
|
+
assert_equal true, hash[:hl]
|
|
123
|
+
assert_equal "title,author", hash["hl.fl"]
|
|
124
|
+
assert_equal true, hash["hl.mergeContiguous"]
|
|
125
|
+
assert_equal 100, hash["hl.increment"]
|
|
126
|
+
assert_equal 3, hash["hl.snippets"]
|
|
127
|
+
assert_equal true, hash["hl.requireFieldMatch"]
|
|
128
|
+
assert_equal "<blink>", hash["hl.simple.pre"]
|
|
129
|
+
assert_equal "</blink>", hash["hl.simple.post"]
|
|
130
|
+
assert_equal 300, hash["hl.fragsize"]
|
|
131
|
+
assert_equal 102400, hash["hl.maxAnalyzedChars"]
|
|
132
|
+
assert_equal "myFormatter", hash["hl.formatter"]
|
|
133
|
+
assert_equal "myFragmenter", hash["hl.fragmenter"]
|
|
134
|
+
assert_equal true, hash["hl.usePhraseHighlighter"]
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def test_highlighting2
|
|
138
|
+
request = Solr::Request::Standard.new(:query => 'query',
|
|
139
|
+
:highlighting => {
|
|
140
|
+
:field_list => ['title', 'author'],
|
|
141
|
+
:merge_contiguous => {
|
|
142
|
+
:default=>false, :fields=>{'author'=>true}
|
|
143
|
+
},
|
|
144
|
+
:increment => {
|
|
145
|
+
:default=>100, :fields=>{'author'=>200}
|
|
146
|
+
},
|
|
147
|
+
:max_snippets => {
|
|
148
|
+
:default=>2,:fields=>{'author'=>3}
|
|
149
|
+
},
|
|
150
|
+
:prefix => {
|
|
151
|
+
:default=>"<em>", :fields=>{'author'=>"<blink>"},
|
|
152
|
+
},
|
|
153
|
+
:suffix => {
|
|
154
|
+
:default=>"</em>", :fields=>{'author'=>"</blink>"},
|
|
155
|
+
},
|
|
156
|
+
:fragment_size => {
|
|
157
|
+
:default=>300,:fields=>{'author'=>200}
|
|
158
|
+
},
|
|
159
|
+
:max_analyzed_chars => {
|
|
160
|
+
:default=>102400,:fields=>{'author'=>51200}
|
|
161
|
+
},
|
|
162
|
+
:require_field_match => {
|
|
163
|
+
:default=>false, :fields=>{'author'=>true}
|
|
164
|
+
},
|
|
165
|
+
:formatter => {
|
|
166
|
+
:default=>'defaultFormatter', :fields=>{'title'=>'titleFormatter'}
|
|
167
|
+
},
|
|
168
|
+
:fragmenter => {
|
|
169
|
+
:default=>'defaultFragmenter',:fields=>{'title'=>'titleFragmenter'}
|
|
170
|
+
},
|
|
171
|
+
}
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
hash = request.to_hash
|
|
175
|
+
assert_equal true, hash[:hl]
|
|
176
|
+
assert_equal "title,author", hash["hl.fl"]
|
|
177
|
+
assert_equal false, hash["hl.mergeContiguous"]
|
|
178
|
+
assert_equal true, hash["f.author.hl.mergeContiguous"]
|
|
179
|
+
assert_equal 100, hash["hl.increment"]
|
|
180
|
+
assert_equal 200, hash["f.author.hl.increment"]
|
|
181
|
+
assert_equal 2, hash["hl.snippets"]
|
|
182
|
+
assert_equal 3, hash["f.author.hl.snippets"]
|
|
183
|
+
assert_equal "<em>", hash["hl.simple.pre"]
|
|
184
|
+
assert_equal "<blink>", hash["f.author.hl.simple.pre"]
|
|
185
|
+
assert_equal "</em>", hash["hl.simple.post"]
|
|
186
|
+
assert_equal "</blink>", hash["f.author.hl.simple.post"]
|
|
187
|
+
assert_equal 300, hash["hl.fragsize"]
|
|
188
|
+
assert_equal 200, hash["f.author.hl.fragsize"]
|
|
189
|
+
assert_equal 102400, hash["hl.maxAnalyzedChars"]
|
|
190
|
+
assert_equal 51200, hash["f.author.hl.maxAnalyzedChars"]
|
|
191
|
+
assert_equal false, hash["hl.requireFieldMatch"]
|
|
192
|
+
assert_equal true, hash["f.author.hl.requireFieldMatch"]
|
|
193
|
+
assert_equal 'defaultFormatter', hash["hl.formatter"]
|
|
194
|
+
assert_equal 'titleFormatter', hash["f.title.hl.formatter"]
|
|
195
|
+
assert_equal 'defaultFragmenter', hash["hl.fragmenter"]
|
|
196
|
+
assert_equal 'titleFragmenter', hash["f.title.hl.fragmenter"]
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
def test_highlighting_regex
|
|
200
|
+
request = Solr::Request::Standard.new(:query => 'query',
|
|
201
|
+
:highlighting => {
|
|
202
|
+
:field_list => ['title', 'author'],
|
|
203
|
+
:regex => {
|
|
204
|
+
:slop => 0.8,
|
|
205
|
+
:pattern => '\w',
|
|
206
|
+
:max_analyzed_chars => 10000
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
hash = request.to_hash
|
|
212
|
+
assert_equal true, hash[:hl]
|
|
213
|
+
assert_equal "title,author", hash["hl.fl"]
|
|
214
|
+
assert_equal 0.8, hash["hl.regex.slop"]
|
|
215
|
+
assert_equal '\w', hash["hl.regex.pattern"]
|
|
216
|
+
assert_equal 10000, hash["hl.regex.maxAnalyzedChars"]
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
def test_highlighting_regex2
|
|
220
|
+
request = Solr::Request::Standard.new(:query => 'query',
|
|
221
|
+
:highlighting => {
|
|
222
|
+
:field_list => ['title', 'author'],
|
|
223
|
+
:regex => {
|
|
224
|
+
:slop => { :default=>0.5, :fields=>{'author'=>0.8} },
|
|
225
|
+
:pattern => { :default=>'\w', :fields=>{'author'=>'\n'} },
|
|
226
|
+
:max_analyzed_chars => { :default=>10000, :fields=>{'author'=>20000} }
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
hash = request.to_hash
|
|
232
|
+
assert_equal true, hash[:hl]
|
|
233
|
+
assert_equal "title,author", hash["hl.fl"]
|
|
234
|
+
assert_equal 0.5, hash["hl.regex.slop"]
|
|
235
|
+
assert_equal 0.8, hash["f.author.hl.regex.slop"]
|
|
236
|
+
assert_equal '\w', hash["hl.regex.pattern"]
|
|
237
|
+
assert_equal '\n', hash["f.author.hl.regex.pattern"]
|
|
238
|
+
assert_equal 10000, hash["hl.regex.maxAnalyzedChars"]
|
|
239
|
+
assert_equal 20000, hash["f.author.hl.regex.maxAnalyzedChars"]
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
def test_highlighting_alternate_field
|
|
243
|
+
request = Solr::Request::Standard.new(:query => 'query',
|
|
244
|
+
:highlighting => {
|
|
245
|
+
:field_list => ['title', 'author'],
|
|
246
|
+
:alternate_field => 'title',
|
|
247
|
+
:max_alternate_field_length => 30
|
|
248
|
+
}
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
hash = request.to_hash
|
|
252
|
+
assert_equal true, hash[:hl]
|
|
253
|
+
assert_equal "title,author", hash["hl.fl"]
|
|
254
|
+
assert_equal "title", hash["hl.alternateField"]
|
|
255
|
+
assert_equal 30, hash["hl.maxAlternateFieldLength"]
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
def test_highlighting_alternate_field2
|
|
259
|
+
request = Solr::Request::Standard.new(:query => 'query',
|
|
260
|
+
:highlighting => {
|
|
261
|
+
:field_list => ['title', 'author'],
|
|
262
|
+
:alternate_field => {
|
|
263
|
+
:default=>'default', :fields=>{'title'=>'title', 'author'=>'author'}
|
|
264
|
+
},
|
|
265
|
+
:max_alternate_field_length => {
|
|
266
|
+
:default=>10, :fields=>{'title'=>30, 'author'=>20}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
)
|
|
270
|
+
|
|
271
|
+
hash = request.to_hash
|
|
272
|
+
assert_equal true, hash[:hl]
|
|
273
|
+
assert_equal "title,author", hash["hl.fl"]
|
|
274
|
+
assert_equal "default", hash["hl.alternateField"]
|
|
275
|
+
assert_equal "title", hash["f.title.hl.alternateField"]
|
|
276
|
+
assert_equal "author", hash["f.author.hl.alternateField"]
|
|
277
|
+
assert_equal 10, hash["hl.maxAlternateFieldLength"]
|
|
278
|
+
assert_equal 30, hash["f.title.hl.maxAlternateFieldLength"]
|
|
279
|
+
assert_equal 20, hash["f.author.hl.maxAlternateFieldLength"]
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
def test_highlighting_alternate_field_old_style
|
|
283
|
+
request = Solr::Request::Standard.new(:query => 'query',
|
|
284
|
+
:highlighting => {
|
|
285
|
+
:field_list => ['title', 'author'],
|
|
286
|
+
:alternate_fields => {'title'=>'title', 'author'=>'author'},
|
|
287
|
+
:max_alternate_field_length => {'title'=>30, 'author'=>20}
|
|
288
|
+
}
|
|
289
|
+
)
|
|
290
|
+
|
|
291
|
+
hash = request.to_hash
|
|
292
|
+
assert_equal true, hash[:hl]
|
|
293
|
+
assert_equal "title,author", hash["hl.fl"]
|
|
294
|
+
assert_equal "title", hash["f.title.hl.alternateField"]
|
|
295
|
+
assert_equal "author", hash["f.author.hl.alternateField"]
|
|
296
|
+
assert_equal 30, hash["f.title.hl.maxAlternateFieldLength"]
|
|
297
|
+
assert_equal 20, hash["f.author.hl.maxAlternateFieldLength"]
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
def test_mlt
|
|
301
|
+
request = Solr::Request::Standard.new(:query => 'query',
|
|
302
|
+
:mlt => {
|
|
303
|
+
:count => 5, :field_list => ['field1', 'field2'],
|
|
304
|
+
:min_term_freq => 3, :min_doc_freq => 10,
|
|
305
|
+
:min_word_length => 4, :max_word_length => 17,
|
|
306
|
+
:max_query_terms => 20, :max_tokens_parsed => 100,
|
|
307
|
+
:boost => true
|
|
308
|
+
}
|
|
309
|
+
)
|
|
310
|
+
|
|
311
|
+
hash = request.to_hash
|
|
312
|
+
assert_equal true, hash[:mlt]
|
|
313
|
+
assert_equal 5, hash["mlt.count"]
|
|
314
|
+
assert_equal 'field1,field2', hash["mlt.fl"]
|
|
315
|
+
assert_equal 3, hash["mlt.mintf"]
|
|
316
|
+
assert_equal 10, hash["mlt.mindf"]
|
|
317
|
+
assert_equal 4, hash["mlt.minwl"]
|
|
318
|
+
assert_equal 17, hash["mlt.maxwl"]
|
|
319
|
+
assert_equal 20, hash["mlt.maxqt"]
|
|
320
|
+
assert_equal 100, hash["mlt.maxntp"]
|
|
321
|
+
assert_equal true, hash["mlt.boost"]
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
end
|