algoliasearch-rails 1.5.2 → 1.6.1
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.
- checksums.yaml +4 -4
- data/ChangeLog +5 -0
- data/README.md +67 -1
- data/VERSION +1 -1
- data/algoliasearch-rails.gemspec +4 -3
- data/lib/algoliasearch-rails.rb +28 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8feeca38d2aa84b13c89e975e579b7456808a757
|
4
|
+
data.tar.gz: 049c7c330a2983dc20bfdbc4f37ade5bb99b990c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb011991d9d67bd2f928f6f87b95b8c4e0a187659c5a235fe2aee09e1ba17606720c609dcfaef7911de6cf9d4cebb0bb4d24417df7cd42b81b595519345bb859
|
7
|
+
data.tar.gz: 5f1580a4c50586325fabeb28d8099344d643d2bcf46fdcb5a2dd9a27852b169bb3f628fe60d54959400832d6448814baa15bcdacb326f26a31e20de67dbe4d39
|
data/ChangeLog
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
|
3
|
+
2013-12-05 1.6.1
|
4
|
+
|
5
|
+
* ```add_attribute``` can now be used to add extra attributes in addition to the existing ones
|
6
|
+
* Use the ```geoloc``` and ```tags``` methods to generate the associated ```_tags``` and ```_geoloc``` attributes
|
7
|
+
|
3
8
|
2013-12-05 1.5.2
|
4
9
|
|
5
10
|
* object's attributes must be fetched unscoped to ensure associations will not be impacted by the conditions
|
data/README.md
CHANGED
@@ -17,6 +17,8 @@ Table of Content
|
|
17
17
|
1. [Quick Start](#quick-start)
|
18
18
|
1. [Options](#options)
|
19
19
|
1. [Indexing](#indexing)
|
20
|
+
1. [Tags](#tags)
|
21
|
+
1. [Geo-search](#geo-search)
|
20
22
|
1. [Search settings](#search-settings)
|
21
23
|
1. [Typeahead UI](#typeahead-ui)
|
22
24
|
1. [Note on testing](#note-on-testing)
|
@@ -70,7 +72,7 @@ class Contact < ActiveRecord::Base
|
|
70
72
|
end
|
71
73
|
```
|
72
74
|
|
73
|
-
You can either specify the attributes to send (here we
|
75
|
+
You can either specify the attributes to send (here we restricted to <code>:first_name, :last_name, :email</code>) or not (in that case, all attributes are sent).
|
74
76
|
|
75
77
|
```ruby
|
76
78
|
class Product < ActiveRecord::Base
|
@@ -82,6 +84,23 @@ class Product < ActiveRecord::Base
|
|
82
84
|
end
|
83
85
|
```
|
84
86
|
|
87
|
+
You can also use the <code>add_attribute</code> method, to send all model attributes + extra ones:
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
class Product < ActiveRecord::Base
|
91
|
+
include AlgoliaSearch
|
92
|
+
|
93
|
+
algoliasearch do
|
94
|
+
# all attributes + extra_attr will be sent
|
95
|
+
add_attribute :extra_attr
|
96
|
+
end
|
97
|
+
|
98
|
+
def extra_attr
|
99
|
+
"extra_val"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
```
|
103
|
+
|
85
104
|
```ruby
|
86
105
|
p Contact.search("jon doe")
|
87
106
|
```
|
@@ -204,6 +223,53 @@ To clear an index, use the <code>clear_index!</code> class method:
|
|
204
223
|
Contact.clear_index!
|
205
224
|
```
|
206
225
|
|
226
|
+
Tags
|
227
|
+
-----
|
228
|
+
|
229
|
+
Use the <code>tags</code> method to add tags to your record:
|
230
|
+
|
231
|
+
```ruby
|
232
|
+
class Contact < ActiveRecord::Base
|
233
|
+
include AlgoliaSearch
|
234
|
+
|
235
|
+
algoliasearch do
|
236
|
+
tags ['trusted']
|
237
|
+
end
|
238
|
+
end
|
239
|
+
```
|
240
|
+
|
241
|
+
or using dynamical values:
|
242
|
+
|
243
|
+
```ruby
|
244
|
+
class Contact < ActiveRecord::Base
|
245
|
+
include AlgoliaSearch
|
246
|
+
|
247
|
+
algoliasearch do
|
248
|
+
tags do
|
249
|
+
[first_name.blank? || last_name.blank? ? 'partial' : 'full', has_valid_email? ? 'valid_email' : 'invalid_email']
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
```
|
254
|
+
|
255
|
+
At query time, specify <code>{ tagFilters: 'tagvalue' }</code> or <code>{ tagFilters: ['tagvalue1', 'tagvalue2'] }</code> as search parameters to restrict the result set to specific tags.
|
256
|
+
|
257
|
+
Geo-Search
|
258
|
+
-----------
|
259
|
+
|
260
|
+
Use the <code>geoloc</code> method to localize your record:
|
261
|
+
|
262
|
+
```ruby
|
263
|
+
class Contact < ActiveRecord::Base
|
264
|
+
include AlgoliaSearch
|
265
|
+
|
266
|
+
algoliasearch do
|
267
|
+
tags ['trusted']
|
268
|
+
end
|
269
|
+
end
|
270
|
+
```
|
271
|
+
|
272
|
+
At query time, specify <code>{ aroundLatLng: "37.33, -121.89", aroundRadius: 50000 }</code> as search parameters to restrict the result set to 50KM around San Jose.
|
207
273
|
|
208
274
|
Search settings
|
209
275
|
----------
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.6.1
|
data/algoliasearch-rails.gemspec
CHANGED
@@ -2,14 +2,15 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: algoliasearch-rails 1.6.1 ruby lib
|
5
6
|
|
6
7
|
Gem::Specification.new do |s|
|
7
8
|
s.name = "algoliasearch-rails"
|
8
|
-
s.version = "1.
|
9
|
+
s.version = "1.6.1"
|
9
10
|
|
10
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
12
|
s.authors = ["Algolia"]
|
12
|
-
s.date = "2013-12-
|
13
|
+
s.date = "2013-12-12"
|
13
14
|
s.description = "AlgoliaSearch integration to your favorite ORM"
|
14
15
|
s.email = "contact@algolia.com"
|
15
16
|
s.extra_rdoc_files = [
|
@@ -47,7 +48,7 @@ Gem::Specification.new do |s|
|
|
47
48
|
s.homepage = "http://github.com/algolia/algoliasearch-rails"
|
48
49
|
s.licenses = ["MIT"]
|
49
50
|
s.require_paths = ["lib"]
|
50
|
-
s.rubygems_version = "2.
|
51
|
+
s.rubygems_version = "2.1.11"
|
51
52
|
s.summary = "AlgoliaSearch integration to your favorite ORM"
|
52
53
|
|
53
54
|
if s.respond_to? :specification_version then
|
data/lib/algoliasearch-rails.rb
CHANGED
@@ -64,14 +64,39 @@ module AlgoliaSearch
|
|
64
64
|
raise ArgumentError.new('Cannot pass multiple attribute names if block given') if block_given? and names.length > 1
|
65
65
|
@attributes ||= {}
|
66
66
|
names.each do |name|
|
67
|
-
@attributes[name] = block_given? ? Proc.new { |o| o.instance_eval(&block) } : Proc.new { |o| o.send(name) }
|
67
|
+
@attributes[name.to_s] = block_given? ? Proc.new { |o| o.instance_eval(&block) } : Proc.new { |o| o.send(name) }
|
68
68
|
end
|
69
69
|
end
|
70
|
+
alias :attributes :attribute
|
71
|
+
|
72
|
+
def add_attribute(*names, &block)
|
73
|
+
raise ArgumentError.new('Cannot pass multiple attribute names if block given') if block_given? and names.length > 1
|
74
|
+
@additional_attributes ||= {}
|
75
|
+
names.each do |name|
|
76
|
+
@additional_attributes[name.to_s] = block_given? ? Proc.new { |o| o.instance_eval(&block) } : Proc.new { |o| o.send(name) }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
alias :add_attributes :add_attribute
|
70
80
|
|
71
81
|
def get_attributes(object)
|
72
82
|
object.class.unscoped do
|
73
|
-
|
74
|
-
|
83
|
+
res = @attributes.nil? || @attributes.length == 0 ? object.attributes :
|
84
|
+
Hash[@attributes.map { |name, value| [name.to_s, value.call(object) ] }]
|
85
|
+
@additional_attributes.each { |name, value| res[name.to_s] = value.call(object) } if @additional_attributes
|
86
|
+
res
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def geoloc(lat_attr, lng_attr)
|
91
|
+
add_attribute :_geoloc do |o|
|
92
|
+
{ lat: o.send(lat_attr).to_f, lng: o.send(lng_attr).to_f }
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def tags(*args, &block)
|
97
|
+
add_attribute :_tags do |o|
|
98
|
+
v = block_given? ? o.instance_eval(&block) : args
|
99
|
+
v.is_a?(Array) ? v : [v]
|
75
100
|
end
|
76
101
|
end
|
77
102
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: algoliasearch-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Algolia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -148,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
148
|
version: '0'
|
149
149
|
requirements: []
|
150
150
|
rubyforge_project:
|
151
|
-
rubygems_version: 2.
|
151
|
+
rubygems_version: 2.1.11
|
152
152
|
signing_key:
|
153
153
|
specification_version: 4
|
154
154
|
summary: AlgoliaSearch integration to your favorite ORM
|