lunr 2.0.3 → 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +4 -0
- data/README.rdoc +2 -2
- data/lib/lunr.rb +1 -1
- data/lib/lunr/model.rb +8 -8
- data/lib/lunr/model/klass.rb +16 -13
- metadata +3 -3
data/CHANGELOG.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -47,7 +47,7 @@ to the original data store, Lunr might be what you're looking for.
|
|
47
47
|
|
48
48
|
=== Including the Module
|
49
49
|
|
50
|
-
All model
|
50
|
+
All model classes must <code>include Lunr::Model</code>.
|
51
51
|
|
52
52
|
=== Define the Search Index
|
53
53
|
|
@@ -109,7 +109,7 @@ first param must be the Sunspot query object.
|
|
109
109
|
|
110
110
|
== Searching
|
111
111
|
|
112
|
-
Use Sunspot's excellent search DSL for ad
|
112
|
+
Use Sunspot's excellent search DSL for ad hoc searches.
|
113
113
|
|
114
114
|
My::SimpleTrack.search
|
115
115
|
My::SimpleTrack.all # same thing
|
data/lib/lunr.rb
CHANGED
data/lib/lunr/model.rb
CHANGED
@@ -2,16 +2,16 @@ require "lunr/model/klass"
|
|
2
2
|
|
3
3
|
module Lunr
|
4
4
|
module Model
|
5
|
-
|
5
|
+
def initialize hash
|
6
|
+
@hash = hash
|
7
|
+
end
|
6
8
|
|
7
|
-
def
|
8
|
-
@
|
9
|
-
|
9
|
+
def id
|
10
|
+
@hash[:id]
|
11
|
+
end
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
end
|
13
|
+
def to_h
|
14
|
+
@hash
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
data/lib/lunr/model/klass.rb
CHANGED
@@ -9,23 +9,20 @@ module Lunr
|
|
9
9
|
|
10
10
|
module Klass
|
11
11
|
def create hit
|
12
|
-
|
13
|
-
instance.id = hit.primary_key
|
12
|
+
hash = { :id => hit.primary_key }
|
14
13
|
|
15
|
-
|
16
|
-
|
14
|
+
properties.each do |name, type|
|
15
|
+
value = hit.stored name
|
17
16
|
|
17
|
+
if Array === value && value.length == 1 && type == :text
|
18
18
|
# For text fields, which always appear to be multiple.
|
19
|
-
|
20
|
-
if Array === value && value.length == 1 && type == :text
|
21
|
-
value = value.first
|
22
|
-
end
|
23
|
-
|
24
|
-
instance.send "#{name}=", value
|
19
|
+
value = value.first
|
25
20
|
end
|
26
21
|
|
27
|
-
|
22
|
+
hash[name] = value
|
28
23
|
end
|
24
|
+
|
25
|
+
new(hash).freeze
|
29
26
|
end
|
30
27
|
|
31
28
|
def first &block
|
@@ -45,7 +42,9 @@ module Lunr
|
|
45
42
|
|
46
43
|
unless name == :all
|
47
44
|
class_eval <<-END, __FILE__, __LINE__ + 1
|
48
|
-
def self.#{name}
|
45
|
+
def self.#{name}
|
46
|
+
search.#{name}
|
47
|
+
end
|
49
48
|
END
|
50
49
|
end
|
51
50
|
end
|
@@ -61,7 +60,11 @@ module Lunr
|
|
61
60
|
Sunspot.setup self, &block
|
62
61
|
|
63
62
|
properties.each do |name, type|
|
64
|
-
|
63
|
+
class_eval <<-END, __FILE__, __LINE__ + 1
|
64
|
+
def #{name}
|
65
|
+
@hash[#{name.inspect}]
|
66
|
+
end
|
67
|
+
END
|
65
68
|
end
|
66
69
|
end
|
67
70
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lunr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 2.0.
|
9
|
+
- 4
|
10
|
+
version: 2.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- John Barnette
|