zigexn_solr-ruby 0.0.1
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.
- checksums.yaml +7 -0
- data/LICENSE.txt +201 -0
- data/README.md +41 -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/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/importer.rb +19 -0
- data/lib/solr/indexer.rb +52 -0
- data/lib/solr/request/add_document.rb +63 -0
- data/lib/solr/request/base.rb +36 -0
- data/lib/solr/request/commit.rb +30 -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 +376 -0
- data/lib/solr/request/update.rb +23 -0
- data/lib/solr/request.rb +26 -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/response.rb +27 -0
- data/lib/solr/solrtasks.rb +27 -0
- data/lib/solr/util.rb +32 -0
- data/lib/solr/xml.rb +47 -0
- data/lib/solr.rb +21 -0
- metadata +119 -0
@@ -0,0 +1,17 @@
|
|
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
|
+
class Solr::Response::Select < Solr::Response::Ruby
|
14
|
+
def initialize(ruby_code)
|
15
|
+
super
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,20 @@
|
|
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
|
+
class Solr::Response::Spellcheck < Solr::Response::Ruby
|
14
|
+
attr_reader :suggestions
|
15
|
+
|
16
|
+
def initialize(ruby_code)
|
17
|
+
super
|
18
|
+
@suggestions = @data['suggestions']
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,60 @@
|
|
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
|
+
class Solr::Response::Standard < Solr::Response::Ruby
|
14
|
+
FacetValue = Struct.new(:name, :value)
|
15
|
+
include Enumerable
|
16
|
+
|
17
|
+
def initialize(ruby_code)
|
18
|
+
super
|
19
|
+
@response = @data['response']
|
20
|
+
raise "response section missing" unless @response.kind_of? Hash
|
21
|
+
end
|
22
|
+
|
23
|
+
def total_hits
|
24
|
+
@response['numFound']
|
25
|
+
end
|
26
|
+
|
27
|
+
def start
|
28
|
+
@response['start']
|
29
|
+
end
|
30
|
+
|
31
|
+
def hits
|
32
|
+
@response['docs']
|
33
|
+
end
|
34
|
+
|
35
|
+
def max_score
|
36
|
+
@response['maxScore']
|
37
|
+
end
|
38
|
+
|
39
|
+
# TODO: consider the use of json.nl parameter
|
40
|
+
def field_facets(field)
|
41
|
+
facets = []
|
42
|
+
values = @data['facet_counts']['facet_fields'][field]
|
43
|
+
Solr::Util.paired_array_each(values) do |key, value|
|
44
|
+
facets << FacetValue.new(key, value)
|
45
|
+
end
|
46
|
+
|
47
|
+
facets
|
48
|
+
end
|
49
|
+
|
50
|
+
def highlighted(id, field)
|
51
|
+
@data['highlighting'][id.to_s][field.to_s] rescue nil
|
52
|
+
end
|
53
|
+
|
54
|
+
# supports enumeration of hits
|
55
|
+
# TODO revisit - should this iterate through *all* hits by re-requesting more?
|
56
|
+
def each
|
57
|
+
@response['docs'].each {|hit| yield hit}
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,42 @@
|
|
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 'rexml/document'
|
14
|
+
require 'solr/exception'
|
15
|
+
|
16
|
+
class Solr::Response::Xml < Solr::Response::Base
|
17
|
+
attr_reader :doc, :status_code, :status_message
|
18
|
+
|
19
|
+
def initialize(xml)
|
20
|
+
super
|
21
|
+
# parse the xml
|
22
|
+
@doc = REXML::Document.new(xml)
|
23
|
+
|
24
|
+
# look for the result code and string
|
25
|
+
# <?xml version="1.0" encoding="UTF-8"?>
|
26
|
+
# <response>
|
27
|
+
# <lst name="responseHeader"><int name="status">0</int><int name="QTime">2</int></lst>
|
28
|
+
# </response>
|
29
|
+
result = REXML::XPath.first(@doc, './response/lst[@name="responseHeader"]/int[@name="status"]')
|
30
|
+
if result
|
31
|
+
@status_code = result.text
|
32
|
+
@status_message = result.text # TODO: any need for a message?
|
33
|
+
end
|
34
|
+
rescue REXML::ParseException => e
|
35
|
+
raise Solr::Exception.new("invalid response xml: #{e}")
|
36
|
+
end
|
37
|
+
|
38
|
+
def ok?
|
39
|
+
return @status_code == '0'
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -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
|
+
module Solr; module Response; end; end
|
14
|
+
require 'solr/response/base'
|
15
|
+
require 'solr/response/xml'
|
16
|
+
require 'solr/response/ruby'
|
17
|
+
require 'solr/response/ping'
|
18
|
+
require 'solr/response/add_document'
|
19
|
+
require 'solr/response/modify_document'
|
20
|
+
require 'solr/response/standard'
|
21
|
+
require 'solr/response/spellcheck'
|
22
|
+
require 'solr/response/dismax'
|
23
|
+
require 'solr/response/commit'
|
24
|
+
require 'solr/response/delete'
|
25
|
+
require 'solr/response/index_info'
|
26
|
+
require 'solr/response/optimize'
|
27
|
+
require 'solr/response/select'
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# The ASF licenses this file to You under the Apache License, Version 2.0
|
3
|
+
# (the "License"); you may not use this file except in compliance with
|
4
|
+
# the License. You may obtain a copy of the License at
|
5
|
+
#
|
6
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
7
|
+
#
|
8
|
+
# Unless required by applicable law or agreed to in writing, software
|
9
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
10
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
11
|
+
# See the License for the specific language governing permissions and
|
12
|
+
# limitations under the License.
|
13
|
+
|
14
|
+
# TODO: fill out Solr tasks: start, stop, ping, optimize, etc.
|
15
|
+
|
16
|
+
require 'rake'
|
17
|
+
require 'rake/tasklib'
|
18
|
+
|
19
|
+
module Solr
|
20
|
+
namespace :solr do
|
21
|
+
desc "Start Solr"
|
22
|
+
task :start do
|
23
|
+
# TODO: actually start it up!
|
24
|
+
puts "Starting..."
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/solr/util.rb
ADDED
@@ -0,0 +1,32 @@
|
|
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
|
+
class Solr::Util
|
14
|
+
# paired_array_each([key1,value1,key2,value2]) yields twice:
|
15
|
+
# |key1,value1| and |key2,value2|
|
16
|
+
def self.paired_array_each(a, &block)
|
17
|
+
0.upto(a.size / 2 - 1) do |i|
|
18
|
+
n = i * 2
|
19
|
+
yield(a[n], a[n+1])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# paired_array_to_hash([key1,value1,key2,value2]) => {key1 => value1, key2, value2}
|
24
|
+
def self.paired_array_to_hash(a)
|
25
|
+
Hash[*a]
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.query_parser_escape(string)
|
29
|
+
# backslash prefix everything that isn't a word character
|
30
|
+
string.gsub(/(\W)/,'\\\\\1')
|
31
|
+
end
|
32
|
+
end
|
data/lib/solr/xml.rb
ADDED
@@ -0,0 +1,47 @@
|
|
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
|
+
module Solr::XML
|
14
|
+
end
|
15
|
+
|
16
|
+
begin
|
17
|
+
|
18
|
+
# If we can load rubygems and libxml-ruby...
|
19
|
+
require 'rubygems'
|
20
|
+
require 'xml/libxml'
|
21
|
+
|
22
|
+
# then make a few modifications to XML::Node so it can stand in for REXML::Element
|
23
|
+
class XML::Node
|
24
|
+
# element.add_element(another_element) should work
|
25
|
+
alias_method :add_element, :<<
|
26
|
+
|
27
|
+
# element.attributes['blah'] should work
|
28
|
+
def attributes
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
# element.text = "blah" should work
|
33
|
+
def text=(x)
|
34
|
+
self << x.to_s
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# And use XML::Node for our XML generation
|
39
|
+
Solr::XML::Element = XML::Node
|
40
|
+
|
41
|
+
rescue LoadError => e # If we can't load either rubygems or libxml-ruby
|
42
|
+
|
43
|
+
# Just use REXML.
|
44
|
+
require 'rexml/document'
|
45
|
+
Solr::XML::Element = REXML::Element
|
46
|
+
|
47
|
+
end
|
data/lib/solr.rb
ADDED
@@ -0,0 +1,21 @@
|
|
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
|
+
module Solr; end
|
14
|
+
require 'solr/exception'
|
15
|
+
require 'solr/request'
|
16
|
+
require 'solr/connection'
|
17
|
+
require 'solr/response'
|
18
|
+
require 'solr/util'
|
19
|
+
require 'solr/xml'
|
20
|
+
require 'solr/importer'
|
21
|
+
require 'solr/indexer'
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zigexn_solr-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- kalrover
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: ZIGExN's fork of the old Apache solr-ruby
|
42
|
+
email:
|
43
|
+
- kal@zigexn.co.jp
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- LICENSE.txt
|
49
|
+
- README.md
|
50
|
+
- lib/solr.rb
|
51
|
+
- lib/solr/connection.rb
|
52
|
+
- lib/solr/document.rb
|
53
|
+
- lib/solr/exception.rb
|
54
|
+
- lib/solr/field.rb
|
55
|
+
- lib/solr/importer.rb
|
56
|
+
- lib/solr/importer/array_mapper.rb
|
57
|
+
- lib/solr/importer/delimited_file_source.rb
|
58
|
+
- lib/solr/importer/hpricot_mapper.rb
|
59
|
+
- lib/solr/importer/mapper.rb
|
60
|
+
- lib/solr/importer/solr_source.rb
|
61
|
+
- lib/solr/importer/xpath_mapper.rb
|
62
|
+
- lib/solr/indexer.rb
|
63
|
+
- lib/solr/request.rb
|
64
|
+
- lib/solr/request/add_document.rb
|
65
|
+
- lib/solr/request/base.rb
|
66
|
+
- lib/solr/request/commit.rb
|
67
|
+
- lib/solr/request/delete.rb
|
68
|
+
- lib/solr/request/dismax.rb
|
69
|
+
- lib/solr/request/index_info.rb
|
70
|
+
- lib/solr/request/modify_document.rb
|
71
|
+
- lib/solr/request/optimize.rb
|
72
|
+
- lib/solr/request/ping.rb
|
73
|
+
- lib/solr/request/select.rb
|
74
|
+
- lib/solr/request/spellcheck.rb
|
75
|
+
- lib/solr/request/standard.rb
|
76
|
+
- lib/solr/request/update.rb
|
77
|
+
- lib/solr/response.rb
|
78
|
+
- lib/solr/response/add_document.rb
|
79
|
+
- lib/solr/response/base.rb
|
80
|
+
- lib/solr/response/commit.rb
|
81
|
+
- lib/solr/response/delete.rb
|
82
|
+
- lib/solr/response/dismax.rb
|
83
|
+
- lib/solr/response/index_info.rb
|
84
|
+
- lib/solr/response/modify_document.rb
|
85
|
+
- lib/solr/response/optimize.rb
|
86
|
+
- lib/solr/response/ping.rb
|
87
|
+
- lib/solr/response/ruby.rb
|
88
|
+
- lib/solr/response/select.rb
|
89
|
+
- lib/solr/response/spellcheck.rb
|
90
|
+
- lib/solr/response/standard.rb
|
91
|
+
- lib/solr/response/xml.rb
|
92
|
+
- lib/solr/solrtasks.rb
|
93
|
+
- lib/solr/util.rb
|
94
|
+
- lib/solr/xml.rb
|
95
|
+
homepage: https://github.com/ZIGExN/zigexn_solr-ruby
|
96
|
+
licenses:
|
97
|
+
- Apache License 2.0
|
98
|
+
metadata: {}
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 2.4.3
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: ZIGExN's fork of the old Apache solr-ruby
|
119
|
+
test_files: []
|