lunr 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,11 @@
1
+ === 2.0.2 / 2010-09-02
2
+
3
+ * Fix Rakefile typo.
4
+ * Add ModelClass.first search helper.
5
+ * Require Ruby >= 1.8.7.
6
+ * Tighten Sunspot dep to = 1.1.0.
7
+ * Improve the README a bit.
8
+
1
9
  === 2.0.1 / 2010-09-02
2
10
 
3
11
  * Clean up model and search.
data/Isolate CHANGED
@@ -1,6 +1,6 @@
1
1
  options :system => false
2
2
 
3
- gem "sunspot", "~> 1.1.0"
3
+ gem "sunspot", "1.1.0"
4
4
 
5
5
  env :development do
6
6
  gem "ZenTest", "4.4.0"
data/README.rdoc CHANGED
@@ -14,7 +14,7 @@ If you have complex indexes with a stored fields and need to search /
14
14
  access those fields without access to the original data store, Lunr
15
15
  might be what you're looking for.
16
16
 
17
- == Examples
17
+ == A Lunr Model
18
18
 
19
19
  require "lunr"
20
20
 
@@ -47,10 +47,100 @@ might be what you're looking for.
47
47
  end
48
48
  end
49
49
 
50
+ === Including the Module
51
+
52
+ All model class must <code>include Lunr::Model</code>.
53
+
54
+ === Define the Search Index
55
+
56
+ Time to tell Solr what this class searches, and which fields are
57
+ properties. The DSL in here is exactly the same as Sunspot's, with the
58
+ addition of a <code>property</code> method. Calling
59
+ <code>property</code> tells Lunr that you expect access to this field,
60
+ generates an <code>attr_reader</code> and passes it along to Sunspot's
61
+ DSL as <code>:stored => true</code>.
62
+
63
+ searches "Track" do
64
+ property :album, :text
65
+ property :artist, :text
66
+ property :title, :text
67
+
68
+ time :accepted_at
69
+ boolean :hot
70
+ string :state
71
+ end
72
+
73
+ The <code>searches</code> method also takes an optional type name,
74
+ which can be used to map Lunr model types to differing search
75
+ results. In this case, <code>My::SimpleTrack</code> will search
76
+ documents with an original type of <code>Track</code>.
77
+
78
+ List every criteria you might want to search by, but omit any of
79
+ Sunspot's DSL that involves indexing.
80
+
81
+ === Default Scope
82
+
83
+ Call <code>scope</code> with no name to set default filtering,
84
+ ordering, and pagination properties.
85
+
86
+ scope do |q|
87
+ q.order_by :hot, :desc
88
+ q.order_by :accepted_at, :desc
89
+
90
+ q.with :state, "accepted"
91
+ end
92
+
93
+ === Named Scopes
94
+
95
+ You can define any number of named scopes to make searching
96
+ simpler. They're made availble as static methods on the model class,
97
+ and they're chainable when searching. See the "Searching" section
98
+ below.
99
+
100
+ scope :hot do
101
+ with :hot, true
102
+ end
103
+
104
+ Scope blocks without parameters are <code>instance_eval</code>ed in
105
+ the Sunspot query DSL's context. If your scope takes parameters, the
106
+ first param must be the Sunspot query object.
107
+
108
+ scope :state do |q, state|
109
+ q.with :state, state
110
+ end
111
+
112
+ == Searching
113
+
114
+ My::SimpleTrack.search
115
+ My::SimpleTrack.all # same thing
116
+
117
+ All searches return a <code>Lunr::Search</code> object, and searches
118
+ can be narrowed using the Sunspot query DSL or named scopes. Searches
119
+ aren't run until an <code>Enumerable</code>, arraylike, or pagination
120
+ method is called on the search object. For convenience,
121
+ <code>Lunr::Search</code> quacks like
122
+ <code>WillPaginate::Collection</code>.
123
+
124
+ search = My::SimpleTrack.hot.scope { |q| q.fulltext "hello" }
125
+ p :page => search.page, :total => search.total
126
+
127
+ search.each do |track|
128
+ puts "#{track.title} by #{track.artist} on #{track.album}."
129
+ end
130
+
50
131
  == Installation
51
132
 
52
133
  $ gem install lunr
53
134
 
135
+ == Development
136
+
137
+ Version number notwithstanding, Lunr is under pretty heavy
138
+ development. It's missing a lot of tests, and will be in flux a
139
+ bit. Contributions and suggestions are very welcome.
140
+
141
+ Install the <code>isolate</code> gem and run <code>rake</code>. All
142
+ dev dependencies will be installed automatically.
143
+
54
144
  == License
55
145
 
56
146
  Copyright 2010 John Barnette (code@jbarnette.com)
data/Rakefile CHANGED
@@ -11,6 +11,8 @@ Hoe.plugin :doofus, :git, :isolate
11
11
  Hoe.spec "lunr" do
12
12
  developer "John Barnette", "code@jbarnette.com"
13
13
 
14
+ require_ruby_version ">= 1.8.7"
15
+
14
16
  self.extra_rdoc_files = Dir["*.rdoc"]
15
17
  self.history_file = "CHANGELOG.rdoc"
16
18
  self.readme_file = "README.rdoc"
data/lib/lunr.rb CHANGED
@@ -6,7 +6,7 @@ module Lunr
6
6
 
7
7
  # Duh.
8
8
 
9
- VERSION = "2.0.1"
9
+ VERSION = "2.0.2"
10
10
 
11
11
  end
12
12
 
@@ -8,6 +8,10 @@ module Lunr
8
8
  end
9
9
 
10
10
  module Klass
11
+ def first &block
12
+ search(&block).first
13
+ end
14
+
11
15
  def properties
12
16
  @properties ||= {}
13
17
  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: 13
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
- - 1
10
- version: 2.0.1
9
+ - 2
10
+ version: 2.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - John Barnette
@@ -24,7 +24,7 @@ dependencies:
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ~>
27
+ - - "="
28
28
  - !ruby/object:Gem::Version
29
29
  hash: 19
30
30
  segments:
@@ -213,10 +213,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
213
213
  requirements:
214
214
  - - ">="
215
215
  - !ruby/object:Gem::Version
216
- hash: 3
216
+ hash: 57
217
217
  segments:
218
- - 0
219
- version: "0"
218
+ - 1
219
+ - 8
220
+ - 7
221
+ version: 1.8.7
220
222
  required_rubygems_version: !ruby/object:Gem::Requirement
221
223
  none: false
222
224
  requirements: