lunr 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +5 -0
- data/CHANGELOG.rdoc +3 -0
- data/Isolate +8 -0
- data/Manifest.txt +9 -0
- data/README.rdoc +67 -0
- data/Rakefile +13 -0
- data/lib/lunr/error.rb +4 -0
- data/lib/lunr.rb +57 -0
- data/test/test_lunr.rb +25 -0
- metadata +183 -0
data/.autotest
ADDED
data/CHANGELOG.rdoc
ADDED
data/Isolate
ADDED
data/Manifest.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
= Lunr
|
2
|
+
|
3
|
+
* http://github.com/jbarnette/lunr
|
4
|
+
|
5
|
+
== Description
|
6
|
+
|
7
|
+
A simple read-only interface to Solr, built on RSolr.
|
8
|
+
|
9
|
+
Lunr makes it easy to query and create objects from a Solr index
|
10
|
+
without requiring all the knowledge, code, and data that was used to
|
11
|
+
build the index in the first place.
|
12
|
+
|
13
|
+
If you have complex indexes with a stored fields and need to search /
|
14
|
+
access those fields without access to the original data store, Lunr
|
15
|
+
might be what you're looking for.
|
16
|
+
|
17
|
+
As seen in Sunspot and similar tools, if
|
18
|
+
<code>WillPaginate::Collection</code> is available it'll be wrapped
|
19
|
+
around the results of any search.
|
20
|
+
|
21
|
+
== Examples
|
22
|
+
|
23
|
+
require "lunr"
|
24
|
+
|
25
|
+
# set ENV["LUNR_URL"], or...
|
26
|
+
Lunr[:url] = "http://localhost:8983/solr"
|
27
|
+
|
28
|
+
# simplest possible, returns a hash
|
29
|
+
Lunr.search "foo"
|
30
|
+
|
31
|
+
# returns the result of the block for each entry
|
32
|
+
Lunr.search "foo" do |raw|
|
33
|
+
MyReadOnlyModelClass.new raw
|
34
|
+
end
|
35
|
+
|
36
|
+
# pagination is part of solr, select a page with :p
|
37
|
+
Lunr.search "foo", :p => params[:page]
|
38
|
+
|
39
|
+
# default per page is 25, but you can set ENV["LUNR_PP"] or...
|
40
|
+
Lunr.search "foo", :p => params[:page], :pp => 500
|
41
|
+
|
42
|
+
== Installation
|
43
|
+
|
44
|
+
$ gem install lunr
|
45
|
+
|
46
|
+
== License
|
47
|
+
|
48
|
+
Copyright 2010 John Barnette (code@jbarnette.com)
|
49
|
+
|
50
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
51
|
+
a copy of this software and associated documentation files (the
|
52
|
+
'Software'), to deal in the Software without restriction, including
|
53
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
54
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
55
|
+
permit persons to whom the Software is furnished to do so, subject to
|
56
|
+
the following conditions:
|
57
|
+
|
58
|
+
The above copyright notice and this permission notice shall be
|
59
|
+
included in all copies or substantial portions of the Software.
|
60
|
+
|
61
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
62
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
63
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
64
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
65
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
66
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
67
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "hoe"
|
2
|
+
|
3
|
+
Hoe.plugins.delete :rubyforge
|
4
|
+
Hoe.plugin :doofus, :git, :isolate
|
5
|
+
|
6
|
+
Hoe.spec "lunr" do
|
7
|
+
developer "John Barnette", "code@jbarnette.com"
|
8
|
+
|
9
|
+
self.extra_rdoc_files = Dir["*.rdoc"]
|
10
|
+
self.history_file = "CHANGELOG.rdoc"
|
11
|
+
self.readme_file = "README.rdoc"
|
12
|
+
self.testlib = :minitest
|
13
|
+
end
|
data/lib/lunr/error.rb
ADDED
data/lib/lunr.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require "configlet"
|
2
|
+
require "rsolr"
|
3
|
+
|
4
|
+
require "lunr/error"
|
5
|
+
|
6
|
+
module Lunr
|
7
|
+
extend Configlet
|
8
|
+
|
9
|
+
# Duh.
|
10
|
+
VERSION = "1.0.0"
|
11
|
+
|
12
|
+
config :lunr do
|
13
|
+
default :pp => "25"
|
14
|
+
default :url => "http://localhost:8983/solr"
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.search query, options = {}, &block
|
18
|
+
page = [1, Integer(options[:p])].max
|
19
|
+
per = Integer options[:pp] || self[:pp]
|
20
|
+
|
21
|
+
params = {
|
22
|
+
:q => query,
|
23
|
+
:rows => per,
|
24
|
+
:start => per * (page - 1),
|
25
|
+
}
|
26
|
+
|
27
|
+
begin
|
28
|
+
raw = solr.select params
|
29
|
+
rescue Errno::ECONNREFUSED => e
|
30
|
+
raise Lunr::Error, "Can't connect to #{self[:url]}: #{e}"
|
31
|
+
end
|
32
|
+
|
33
|
+
header = raw["responseHeader"]
|
34
|
+
response = raw["response"]
|
35
|
+
|
36
|
+
unless status = header["status"]
|
37
|
+
raise Lunr::Error, "Bad (and cryptic) response status: #{status}"
|
38
|
+
end
|
39
|
+
|
40
|
+
docs = response.delete "docs"
|
41
|
+
total = response.delete "numFound"
|
42
|
+
|
43
|
+
docs = block_given? ? docs.map(&block) : docs
|
44
|
+
|
45
|
+
if defined? WillPaginate::Collection
|
46
|
+
old = docs
|
47
|
+
docs = WillPaginate::Collection.new page, per, total
|
48
|
+
docs.replace old
|
49
|
+
end
|
50
|
+
|
51
|
+
docs
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.solr
|
55
|
+
@solr ||= RSolr.connect :url => self[:url]
|
56
|
+
end
|
57
|
+
end
|
data/test/test_lunr.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "minitest/autorun"
|
2
|
+
require "fakeweb"
|
3
|
+
require "lunr"
|
4
|
+
|
5
|
+
FakeWeb.allow_net_connect = false
|
6
|
+
|
7
|
+
class TestLunr < MiniTest::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
FakeWeb.clean_registry
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_self_search
|
13
|
+
stub "foo"
|
14
|
+
Lunr.search "foo"
|
15
|
+
end
|
16
|
+
|
17
|
+
def stub query, fixture = "simple"
|
18
|
+
FakeWeb.register_uri :get, url(query),
|
19
|
+
:body => File.read("test/fixtures/#{fixture}")
|
20
|
+
end
|
21
|
+
|
22
|
+
def url query
|
23
|
+
"#{Lunr[:url]}/select?wt=ruby&start=0&q=#{query}&rows=25"
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,183 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lunr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- John Barnette
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-08-25 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: configlet
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 9
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 3
|
33
|
+
version: "1.3"
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rsolr
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 19
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
- 12
|
48
|
+
version: "0.12"
|
49
|
+
type: :runtime
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: fakeweb
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ~>
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 9
|
60
|
+
segments:
|
61
|
+
- 1
|
62
|
+
- 3
|
63
|
+
version: "1.3"
|
64
|
+
type: :development
|
65
|
+
version_requirements: *id003
|
66
|
+
- !ruby/object:Gem::Dependency
|
67
|
+
name: minitest
|
68
|
+
prerelease: false
|
69
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ~>
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 1
|
75
|
+
segments:
|
76
|
+
- 1
|
77
|
+
- 7
|
78
|
+
version: "1.7"
|
79
|
+
type: :development
|
80
|
+
version_requirements: *id004
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: will_paginate
|
83
|
+
prerelease: false
|
84
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
hash: -1876988247
|
90
|
+
segments:
|
91
|
+
- 3
|
92
|
+
- 0
|
93
|
+
- pre2
|
94
|
+
version: 3.0.pre2
|
95
|
+
type: :development
|
96
|
+
version_requirements: *id005
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: hoe
|
99
|
+
prerelease: false
|
100
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
hash: 21
|
106
|
+
segments:
|
107
|
+
- 2
|
108
|
+
- 6
|
109
|
+
- 1
|
110
|
+
version: 2.6.1
|
111
|
+
type: :development
|
112
|
+
version_requirements: *id006
|
113
|
+
description: |-
|
114
|
+
A simple read-only interface to Solr, built on RSolr.
|
115
|
+
|
116
|
+
Lunr makes it easy to query and create objects from a Solr index
|
117
|
+
without requiring all the knowledge, code, and data that was used to
|
118
|
+
build the index in the first place.
|
119
|
+
|
120
|
+
If you have complex indexes with a stored fields and need to search /
|
121
|
+
access those fields without access to the original data store, Lunr
|
122
|
+
might be what you're looking for.
|
123
|
+
|
124
|
+
As seen in Sunspot and similar tools, if
|
125
|
+
<code>WillPaginate::Collection</code> is available it'll be wrapped
|
126
|
+
around the results of any search.
|
127
|
+
email:
|
128
|
+
- code@jbarnette.com
|
129
|
+
executables: []
|
130
|
+
|
131
|
+
extensions: []
|
132
|
+
|
133
|
+
extra_rdoc_files:
|
134
|
+
- Manifest.txt
|
135
|
+
- CHANGELOG.rdoc
|
136
|
+
- README.rdoc
|
137
|
+
files:
|
138
|
+
- .autotest
|
139
|
+
- CHANGELOG.rdoc
|
140
|
+
- Isolate
|
141
|
+
- Manifest.txt
|
142
|
+
- README.rdoc
|
143
|
+
- Rakefile
|
144
|
+
- lib/lunr.rb
|
145
|
+
- lib/lunr/error.rb
|
146
|
+
- test/test_lunr.rb
|
147
|
+
has_rdoc: true
|
148
|
+
homepage: http://github.com/jbarnette/lunr
|
149
|
+
licenses: []
|
150
|
+
|
151
|
+
post_install_message:
|
152
|
+
rdoc_options:
|
153
|
+
- --main
|
154
|
+
- README.rdoc
|
155
|
+
require_paths:
|
156
|
+
- lib
|
157
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
158
|
+
none: false
|
159
|
+
requirements:
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
hash: 3
|
163
|
+
segments:
|
164
|
+
- 0
|
165
|
+
version: "0"
|
166
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
|
+
none: false
|
168
|
+
requirements:
|
169
|
+
- - ">="
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
hash: 3
|
172
|
+
segments:
|
173
|
+
- 0
|
174
|
+
version: "0"
|
175
|
+
requirements: []
|
176
|
+
|
177
|
+
rubyforge_project: lunr
|
178
|
+
rubygems_version: 1.3.7
|
179
|
+
signing_key:
|
180
|
+
specification_version: 3
|
181
|
+
summary: A simple read-only interface to Solr, built on RSolr
|
182
|
+
test_files:
|
183
|
+
- test/test_lunr.rb
|