solrpanel 0.1.0
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/History.txt +4 -0
- data/Manifest +10 -0
- data/PostInstall.txt +3 -0
- data/README.rdoc +55 -0
- data/Rakefile +13 -0
- data/lib/solrpanel/result.rb +50 -0
- data/lib/solrpanel/solrpanel.rb +114 -0
- data/lib/solrpanel.rb +30 -0
- data/solrpanel.gemspec +36 -0
- data/tasks/rspec.rake +21 -0
- metadata +114 -0
data/History.txt
ADDED
data/Manifest
ADDED
data/PostInstall.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
= SolrPanel
|
2
|
+
|
3
|
+
* http://github.com/rlasch/solrpanel
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
SolrPanel is a lightweight package used to access Apache Solr, specifically the Solr Cell module.
|
8
|
+
|
9
|
+
== SYNOPSIS:
|
10
|
+
|
11
|
+
Adding Documents
|
12
|
+
|
13
|
+
|
14
|
+
Deleting Documents
|
15
|
+
|
16
|
+
|
17
|
+
Searching Documents
|
18
|
+
|
19
|
+
|
20
|
+
== REQUIREMENTS:
|
21
|
+
|
22
|
+
The following gems are required:
|
23
|
+
* httpclient
|
24
|
+
* nokogiri
|
25
|
+
|
26
|
+
== INSTALL:
|
27
|
+
|
28
|
+
This should come as no surpise:
|
29
|
+
|
30
|
+
sudo gem install solrpanel
|
31
|
+
|
32
|
+
== LICENSE:
|
33
|
+
|
34
|
+
(The MIT License)
|
35
|
+
|
36
|
+
Copyright (c) 2010 Robert Lasch and Ryan Stawarz
|
37
|
+
|
38
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
39
|
+
a copy of this software and associated documentation files (the
|
40
|
+
'Software'), to deal in the Software without restriction, including
|
41
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
42
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
43
|
+
permit persons to whom the Software is furnished to do so, subject to
|
44
|
+
the following conditions:
|
45
|
+
|
46
|
+
The above copyright notice and this permission notice shall be
|
47
|
+
included in all copies or substantial portions of the Software.
|
48
|
+
|
49
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
50
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
51
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
52
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
53
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
54
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
55
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'echoe'
|
2
|
+
|
3
|
+
Echoe.new('solrpanel', '0.1.0') do |p|
|
4
|
+
p.author = "Ryan Stawarz and Robert Lasch"
|
5
|
+
p.summary = "A client for connecting to Apache Solr Cell."
|
6
|
+
p.url = "http://github.com/rlasch/solrpanel"
|
7
|
+
p.docs_host = ""
|
8
|
+
p.ignore_pattern = ['tmp/*', 'script/*', 'spec/*']
|
9
|
+
p.runtime_dependencies = ["httpclient >=2.1.5.2", "nokogiri >=1.4.3.1"]
|
10
|
+
end
|
11
|
+
|
12
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
13
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# Copyright (c) 2010 Robert Lasch and Ryan Stawarz
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
#
|
21
|
+
module SolrPanel
|
22
|
+
|
23
|
+
# This is the result set
|
24
|
+
class Result
|
25
|
+
def initialize
|
26
|
+
@attrs = {}
|
27
|
+
end
|
28
|
+
|
29
|
+
def method_missing(id, *value)
|
30
|
+
str = id.id2name
|
31
|
+
if (value.length == 1)
|
32
|
+
if str =~ /^(.*)=$/
|
33
|
+
index = $1
|
34
|
+
@attrs[index.to_sym] = value[0]
|
35
|
+
else
|
36
|
+
raise "Missing method: #{str}"
|
37
|
+
end
|
38
|
+
elsif (value.length == 0)
|
39
|
+
if @attrs.include?(id)
|
40
|
+
return @attrs[id]
|
41
|
+
else
|
42
|
+
return nil
|
43
|
+
end
|
44
|
+
else
|
45
|
+
raise "Illegal number of arguments given (#{value.length})"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
# Copyright (c) 2010 Robert Lasch and Ryan Stawarz
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
#
|
21
|
+
|
22
|
+
|
23
|
+
# SolrPanel is a very simple, lightweight library for accessing Apache Solr.
|
24
|
+
module SolrPanel
|
25
|
+
VERSION = '0.0.1'
|
26
|
+
|
27
|
+
# Main client for the SolrPanel library.
|
28
|
+
class Ray
|
29
|
+
attr_accessor :base_url
|
30
|
+
attr_accessor :default_query_parameters
|
31
|
+
|
32
|
+
|
33
|
+
# , :f => "*,company_id"
|
34
|
+
def initialize(url = 'http://localhost:8983/solr/', params = {})
|
35
|
+
@base_url = url
|
36
|
+
@base_url = @base_url + '/' if (@base_url =~ /[^\/]+$/)
|
37
|
+
@default_query_parameters = params
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
# Search for the term found in the
|
42
|
+
def search(term, params = {})
|
43
|
+
client = HTTPClient.new
|
44
|
+
parameters = { :q => term }.merge(params)
|
45
|
+
puts @default_query_parameters.inspect
|
46
|
+
parameters = parameters.merge(@default_query_parameters)
|
47
|
+
response = client.post(url('select'), parameters)
|
48
|
+
|
49
|
+
parse(response)
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
def update(path, id, params = {})
|
54
|
+
response = nil
|
55
|
+
File.open(path) do |file|
|
56
|
+
body = { 'myfile' => file}
|
57
|
+
update_params = {'literal.id' => id }
|
58
|
+
update_params.merge!(params)
|
59
|
+
client = HTTPClient.new
|
60
|
+
response = client.request('POST', url('update/extract'), update_params, body)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
def delete(id)
|
66
|
+
response = nil
|
67
|
+
body = "<delete><id>#{id}</id></delete>"
|
68
|
+
client = HTTPClient.new
|
69
|
+
params = {'Content-Type' => 'text/xml'}
|
70
|
+
response = client.request('POST', url('update'), nil, body, params)
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
def commit()
|
75
|
+
response = nil
|
76
|
+
body = '<commit waitFlush="false" waitSearcher="false"/>'
|
77
|
+
client = HTTPClient.new
|
78
|
+
params = {'Content-Type' => 'text/xml'}
|
79
|
+
response = client.request('POST', url('update'), nil, body, params)
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
private
|
84
|
+
def url(str)
|
85
|
+
@base_url + str
|
86
|
+
end
|
87
|
+
|
88
|
+
def parse(response)
|
89
|
+
results = []
|
90
|
+
xml = Nokogiri::XML(response.body.content)
|
91
|
+
xml.xpath('//doc').each() do |doc|
|
92
|
+
r = SolrPanel::Result.new()
|
93
|
+
|
94
|
+
doc.traverse() do |element|
|
95
|
+
name = element['name'] if element['name']
|
96
|
+
if (name != 'arr')
|
97
|
+
value = element.content
|
98
|
+
end
|
99
|
+
|
100
|
+
if value && name
|
101
|
+
r.send(name + "=", value)
|
102
|
+
name = nil
|
103
|
+
value = nil
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
results << r
|
108
|
+
end
|
109
|
+
|
110
|
+
results
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
data/lib/solrpanel.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Copyright (c) 2010 Robert Lasch and Ryan Stawarz
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
#
|
21
|
+
require 'rubygems'
|
22
|
+
require 'httpclient'
|
23
|
+
require 'nokogiri'
|
24
|
+
require File.dirname(__FILE__) + '/solrpanel/result'
|
25
|
+
require File.dirname(__FILE__) + '/solrpanel/solrpanel'
|
26
|
+
|
27
|
+
# SolrPanel is a very simple, lightweight library for accessing Apache Solr.
|
28
|
+
module SolrPanel
|
29
|
+
VERSION = '0.0.1'
|
30
|
+
end
|
data/solrpanel.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{solrpanel}
|
5
|
+
s.version = "0.1.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Ryan Stawarz and Robert Lasch"]
|
9
|
+
s.date = %q{2010-10-10}
|
10
|
+
s.description = %q{A client for connecting to Apache Solr Cell.}
|
11
|
+
s.email = %q{}
|
12
|
+
s.extra_rdoc_files = ["README.rdoc", "lib/solrpanel.rb", "lib/solrpanel/result.rb", "lib/solrpanel/solrpanel.rb", "tasks/rspec.rake"]
|
13
|
+
s.files = ["History.txt", "PostInstall.txt", "README.rdoc", "Rakefile", "lib/solrpanel.rb", "lib/solrpanel/result.rb", "lib/solrpanel/solrpanel.rb", "solrpanel.gemspec", "tasks/rspec.rake", "Manifest"]
|
14
|
+
s.homepage = %q{http://github.com/rlasch/solrpanel}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Solrpanel", "--main", "README.rdoc"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{solrpanel}
|
18
|
+
s.rubygems_version = %q{1.3.7}
|
19
|
+
s.summary = %q{A client for connecting to Apache Solr Cell.}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
+
s.add_runtime_dependency(%q<httpclient>, [">= 2.1.5.2"])
|
27
|
+
s.add_runtime_dependency(%q<nokogiri>, [">= 1.4.3.1"])
|
28
|
+
else
|
29
|
+
s.add_dependency(%q<httpclient>, [">= 2.1.5.2"])
|
30
|
+
s.add_dependency(%q<nokogiri>, [">= 1.4.3.1"])
|
31
|
+
end
|
32
|
+
else
|
33
|
+
s.add_dependency(%q<httpclient>, [">= 2.1.5.2"])
|
34
|
+
s.add_dependency(%q<nokogiri>, [">= 1.4.3.1"])
|
35
|
+
end
|
36
|
+
end
|
data/tasks/rspec.rake
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
begin
|
2
|
+
require 'spec'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
5
|
+
require 'spec'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'spec/rake/spectask'
|
9
|
+
rescue LoadError
|
10
|
+
puts <<-EOS
|
11
|
+
To use rspec for testing you must install rspec gem:
|
12
|
+
gem install rspec
|
13
|
+
EOS
|
14
|
+
exit(0)
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Run the specs under spec/models"
|
18
|
+
Spec::Rake::SpecTask.new do |t|
|
19
|
+
t.spec_opts = ['--options', "spec/spec.opts"]
|
20
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: solrpanel
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Ryan Stawarz and Robert Lasch
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-10-10 00:00:00 -05:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: httpclient
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 2
|
30
|
+
- 1
|
31
|
+
- 5
|
32
|
+
- 2
|
33
|
+
version: 2.1.5.2
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: nokogiri
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
segments:
|
45
|
+
- 1
|
46
|
+
- 4
|
47
|
+
- 3
|
48
|
+
- 1
|
49
|
+
version: 1.4.3.1
|
50
|
+
type: :runtime
|
51
|
+
version_requirements: *id002
|
52
|
+
description: A client for connecting to Apache Solr Cell.
|
53
|
+
email: ""
|
54
|
+
executables: []
|
55
|
+
|
56
|
+
extensions: []
|
57
|
+
|
58
|
+
extra_rdoc_files:
|
59
|
+
- README.rdoc
|
60
|
+
- lib/solrpanel.rb
|
61
|
+
- lib/solrpanel/result.rb
|
62
|
+
- lib/solrpanel/solrpanel.rb
|
63
|
+
- tasks/rspec.rake
|
64
|
+
files:
|
65
|
+
- History.txt
|
66
|
+
- PostInstall.txt
|
67
|
+
- README.rdoc
|
68
|
+
- Rakefile
|
69
|
+
- lib/solrpanel.rb
|
70
|
+
- lib/solrpanel/result.rb
|
71
|
+
- lib/solrpanel/solrpanel.rb
|
72
|
+
- solrpanel.gemspec
|
73
|
+
- tasks/rspec.rake
|
74
|
+
- Manifest
|
75
|
+
has_rdoc: true
|
76
|
+
homepage: http://github.com/rlasch/solrpanel
|
77
|
+
licenses: []
|
78
|
+
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options:
|
81
|
+
- --line-numbers
|
82
|
+
- --inline-source
|
83
|
+
- --title
|
84
|
+
- Solrpanel
|
85
|
+
- --main
|
86
|
+
- README.rdoc
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
version: "0"
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
segments:
|
103
|
+
- 1
|
104
|
+
- 2
|
105
|
+
version: "1.2"
|
106
|
+
requirements: []
|
107
|
+
|
108
|
+
rubyforge_project: solrpanel
|
109
|
+
rubygems_version: 1.3.7
|
110
|
+
signing_key:
|
111
|
+
specification_version: 3
|
112
|
+
summary: A client for connecting to Apache Solr Cell.
|
113
|
+
test_files: []
|
114
|
+
|