rsolr 0.10.1 → 0.11.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/CHANGES.txt +6 -1
- data/README.rdoc +0 -21
- data/lib/rsolr/client.rb +1 -23
- data/lib/rsolr.rb +1 -7
- data/lib/xout.rb +38 -16
- data/rsolr.gemspec +3 -3
- metadata +2 -3
- data/lib/rsolr/pagination.rb +0 -59
data/CHANGES.txt
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
0.11.0 - November 17, 2009
|
2
|
+
Removed pagination feature yet again... keeping it in RSolr::Ext until a better API can be thought up.
|
3
|
+
Updated Xout with fixed version - thanks to Mat Brown
|
4
|
+
- bug in escaping consecutive special characters
|
5
|
+
- moved regexp patterns out of loop, into "static" variables instead
|
6
|
+
|
1
7
|
0.10.1 - November 13, 2009
|
2
8
|
Same changes as 0.10.0 -- but fixing version number problems
|
3
9
|
|
@@ -18,7 +24,6 @@
|
|
18
24
|
solr.paginate 1, 10, '/music', :q=>''
|
19
25
|
- handler paths can also be set by method names:
|
20
26
|
solr.paginate_music 1, 10
|
21
|
-
Added required java libs to RSolr gem
|
22
27
|
Removed :dist_dir option from Direct connection options -- you gotta load your own java libs. See examples/direct.rb
|
23
28
|
Updated specs
|
24
29
|
|
data/README.rdoc
CHANGED
@@ -74,27 +74,6 @@ A shortcut for the above example:
|
|
74
74
|
response = solr.documents :q=>'test'
|
75
75
|
|
76
76
|
|
77
|
-
===Doc Pagination
|
78
|
-
RSolr is compatible with WillPaginate. To use pagination, call the "paginate" method:
|
79
|
-
response = solr.paginate current_page, per_page, :q=>'*:*'
|
80
|
-
|
81
|
-
You can also set a handler path:
|
82
|
-
response = solr.paginate current_page, per_page, '/music', :q=>'*:*'
|
83
|
-
|
84
|
-
Handler paths can also be set using a paginate_* method call like so:
|
85
|
-
response = solr.paginate_music current_page, per_page, :q=>'testing'
|
86
|
-
|
87
|
-
====Pagination Responses
|
88
|
-
The response['docs'] array from a paginate method has the following methods:
|
89
|
-
start, per_page, total, current_page, total_pages, previous_page, next_page, has_next?, has_previous?
|
90
|
-
|
91
|
-
For example:
|
92
|
-
result = solr.paginate 1, 2, :q=>'*:*'
|
93
|
-
result['response']['docs'].has_next?
|
94
|
-
|
95
|
-
To use with WillPaginate:
|
96
|
-
<%= will_paginate result['response']['docs'] %>
|
97
|
-
|
98
77
|
== Updating Solr
|
99
78
|
Updating can be done using native Ruby structures. Hashes are used for single documents and arrays are used for a collection of documents (hashes). These structures get turned into simple XML "messages". Raw XML strings can also be used.
|
100
79
|
|
data/lib/rsolr/client.rb
CHANGED
@@ -13,29 +13,7 @@ class RSolr::Client
|
|
13
13
|
# Send a request to a request handler using the method name.
|
14
14
|
# Also proxies to the #paginate method if the method starts with "paginate_"
|
15
15
|
def method_missing(method_name, *args, &blk)
|
16
|
-
|
17
|
-
if handler =~ /^paginate_/
|
18
|
-
handler = handler.sub(/^paginate_/, '')
|
19
|
-
page, per_page = args[0..1]
|
20
|
-
paginate(page, per_page, "/#{handler}", *args[2..-1], &blk)
|
21
|
-
else
|
22
|
-
request("/#{handler}", *args, &blk)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
# Accepts a page/per-page value for paginating docs
|
27
|
-
# Example:
|
28
|
-
# solr.paginate 1, 10, :q=>'blah'
|
29
|
-
def paginate page, per_page, *request_args
|
30
|
-
if request_args.size == 2
|
31
|
-
params = request_args.last
|
32
|
-
elsif request_args.last.is_a? Hash
|
33
|
-
params = request_args.last
|
34
|
-
else
|
35
|
-
params = request_args.push({}).last
|
36
|
-
end
|
37
|
-
params[:start], params[:rows] = RSolr::Pagination.page_and_per_page_to_start_and_rows page, per_page
|
38
|
-
self.request(*request_args).extend RSolr::Pagination
|
16
|
+
request("/#{method_name}", *args, &blk)
|
39
17
|
end
|
40
18
|
|
41
19
|
# sends data to the update handler
|
data/lib/rsolr.rb
CHANGED
@@ -8,17 +8,11 @@ require 'xout'
|
|
8
8
|
|
9
9
|
module RSolr
|
10
10
|
|
11
|
-
VERSION = '0.
|
11
|
+
VERSION = '0.11.1'
|
12
12
|
|
13
13
|
autoload :Message, 'rsolr/message'
|
14
14
|
autoload :Client, 'rsolr/client'
|
15
15
|
autoload :Connection, 'rsolr/connection'
|
16
|
-
autoload :Pagination, 'rsolr/pagination'
|
17
|
-
|
18
|
-
# returns path to this file directory
|
19
|
-
def self.dir
|
20
|
-
File.expand_path(File.dirname(__FILE__))
|
21
|
-
end
|
22
16
|
|
23
17
|
# Http connection. Example:
|
24
18
|
# RSolr.connect
|
data/lib/xout.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
class Xout
|
2
2
|
|
3
|
+
VERSION = '0.1.0'
|
4
|
+
|
3
5
|
attr_reader :name, :text, :attrs, :children
|
4
6
|
|
5
7
|
def initialize node_name, *args, &block
|
@@ -36,8 +38,6 @@ class Xout
|
|
36
38
|
'<?xml version="1.0" encoding="UTF-8"?>' + to_xml
|
37
39
|
end
|
38
40
|
|
39
|
-
protected
|
40
|
-
|
41
41
|
# builds an XML attribute string.
|
42
42
|
# escapes each attribute value by running it through #escape_attr
|
43
43
|
def create_attrs hash
|
@@ -45,21 +45,43 @@ class Xout
|
|
45
45
|
" #{r}" unless r.empty?
|
46
46
|
end
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
48
|
+
module Escapable
|
49
|
+
|
50
|
+
def text_mapping
|
51
|
+
@text_mapping ||= {'&'=>'&', '<'=>'<', '>'=>'>'}
|
52
|
+
end
|
53
|
+
|
54
|
+
def text_regexp
|
55
|
+
@text_regexp ||= /[#{text_mapping.keys.join}]/
|
56
|
+
end
|
57
|
+
|
58
|
+
def attr_mapping
|
59
|
+
@attr_mapping ||= {'&'=>'&', '<'=>'<', '>'=>'>', "'"=>''', '"'=>'"e;'}
|
60
|
+
end
|
61
|
+
|
62
|
+
def attr_regexp
|
63
|
+
@attr_regexp ||= /[#{attr_mapping.keys.join}]/
|
64
|
+
end
|
65
|
+
|
66
|
+
# minimal escaping for attribute values
|
67
|
+
def escape_attr input
|
68
|
+
escape input, attr_regexp, attr_mapping
|
69
|
+
end
|
70
|
+
|
71
|
+
# minimal escaping for text
|
72
|
+
def escape_text input
|
73
|
+
escape input, text_regexp, text_mapping
|
74
|
+
end
|
75
|
+
|
76
|
+
# accepts a string input and a hash mapping of characters => replacement values:
|
77
|
+
# Example:
|
78
|
+
# escape 'My <string>cat</strong>', '<'=>'>', '>'=>'<'
|
79
|
+
def escape input, regexp, map
|
80
|
+
input.gsub(regexp) { | char | map[char] || char }
|
81
|
+
end
|
82
|
+
|
56
83
|
end
|
57
84
|
|
58
|
-
|
59
|
-
# Example:
|
60
|
-
# escape 'My <string>cat</strong>', '<'=>'>', '>'=>'<'
|
61
|
-
def escape input, map
|
62
|
-
input.gsub(/[#{map.keys.join}]+/) { | char | map[char] || char }
|
63
|
-
end
|
85
|
+
include Escapable
|
64
86
|
|
65
87
|
end
|
data/rsolr.gemspec
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
|
+
|
2
3
|
s.name = "rsolr"
|
3
|
-
s.version = "0.
|
4
|
-
s.date = "2009-11-
|
4
|
+
s.version = "0.11.0"
|
5
|
+
s.date = "2009-11-17"
|
5
6
|
s.summary = "A Ruby client for Apache Solr"
|
6
7
|
s.email = "goodieboy@gmail.com"
|
7
8
|
s.homepage = "http://github.com/mwmitchell/rsolr"
|
@@ -16,7 +17,6 @@ Gem::Specification.new do |s|
|
|
16
17
|
"lib/rsolr/connection/net_http.rb",
|
17
18
|
"lib/rsolr/connection.rb",
|
18
19
|
"lib/rsolr/message.rb",
|
19
|
-
"lib/rsolr/pagination.rb",
|
20
20
|
"lib/rsolr.rb",
|
21
21
|
"lib/xout.rb",
|
22
22
|
"LICENSE",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rsolr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Mitchell
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-17 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -30,7 +30,6 @@ files:
|
|
30
30
|
- lib/rsolr/connection/net_http.rb
|
31
31
|
- lib/rsolr/connection.rb
|
32
32
|
- lib/rsolr/message.rb
|
33
|
-
- lib/rsolr/pagination.rb
|
34
33
|
- lib/rsolr.rb
|
35
34
|
- lib/xout.rb
|
36
35
|
- LICENSE
|
data/lib/rsolr/pagination.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
module RSolr::Pagination
|
2
|
-
|
3
|
-
def self.extended solr_response
|
4
|
-
d = solr_response['response']['docs']
|
5
|
-
d.extend Paginator
|
6
|
-
d.per_page = solr_response['responseHeader']['params']['rows'].to_s.to_i
|
7
|
-
d.start = solr_response['response']['start'].to_s.to_i
|
8
|
-
d.total = solr_response['response']['numFound'].to_s.to_i
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.page_and_per_page_to_start_and_rows page, per_page
|
12
|
-
rows = per_page.to_s.to_i
|
13
|
-
page = page.to_s.to_i-1
|
14
|
-
page = page < 1 ? 0 : page
|
15
|
-
start = page * rows
|
16
|
-
[start, rows]
|
17
|
-
end
|
18
|
-
|
19
|
-
module Paginator
|
20
|
-
|
21
|
-
attr_accessor :start, :per_page, :total
|
22
|
-
|
23
|
-
# Returns the current page calculated from 'rows' and 'start'
|
24
|
-
# WillPaginate hook
|
25
|
-
def current_page
|
26
|
-
return 1 if start < 1
|
27
|
-
per_page_normalized = per_page < 1 ? 1 : per_page
|
28
|
-
@current_page ||= (start / per_page_normalized).ceil + 1
|
29
|
-
end
|
30
|
-
|
31
|
-
# Calcuates the total pages from 'numFound' and 'rows'
|
32
|
-
# WillPaginate hook
|
33
|
-
def total_pages
|
34
|
-
@total_pages ||= per_page > 0 ? (total / per_page.to_f).ceil : 1
|
35
|
-
end
|
36
|
-
|
37
|
-
# returns the previous page number or 1
|
38
|
-
# WillPaginate hook
|
39
|
-
def previous_page
|
40
|
-
@previous_page ||= (current_page > 1) ? current_page - 1 : 1
|
41
|
-
end
|
42
|
-
|
43
|
-
# returns the next page number or the last
|
44
|
-
# WillPaginate hook
|
45
|
-
def next_page
|
46
|
-
@next_page ||= (current_page == total_pages) ? total_pages : current_page+1
|
47
|
-
end
|
48
|
-
|
49
|
-
def has_next?
|
50
|
-
current_page < total_pages
|
51
|
-
end
|
52
|
-
|
53
|
-
def has_previous?
|
54
|
-
current_page > 1
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|