activesearch 0.1.1 → 0.1.2
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 +8 -8
- data/config/mongoid.yml +6 -0
- data/lib/activesearch/algolia/client.rb +1 -1
- data/lib/activesearch/algolia.rb +7 -2
- data/lib/activesearch/mongoid/model.rb +2 -1
- data/lib/activesearch/version.rb +1 -1
- data/spec/algolia_spec.rb +26 -0
- data/spec/mongoid_spec.rb +17 -3
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NDUxNjIzNjY2NmQxYjIzYmQ4NzA0NjRmYThjNThmY2ZhNjk4N2VlNw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZjZmZDhkODU0NzI4MDU0ZjU5YWUzODcyMGFlZDhlNGMyNDk1NjRhMw==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTA2OTEwMzMxYWE2ZTI4MTg3MzcyNTE2MmE4ZGU1ZDc4YjZjMmU2MjBjOTJm
|
10
|
+
ODc2MTNiNmUzZjhkM2E2ZTNlOGQ0OGYzOWJhYTdiNTUxMTYzNzA1N2JmZjcz
|
11
|
+
YTc3YTM5Nzc1OWYxYzU1YzZmZGUyYTliZmE1NDllY2YxNDYzZGY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MzM2NGFkNWZhZmZmMjY1MDNmZjJmMzI4MzBhNTI0OGJlMWRhOTg0YmJlNDRh
|
14
|
+
MjI3OWFiYzIxYjU2NTM4OWRlMTFlZGFmYjkyNzYwYzAzMjdkM2FhN2U5Zjg4
|
15
|
+
NjFlYTBmZTFjNjJkMDRiYTA4MDFjYTkxOTI3YWQzZWVmZjQ5MjU=
|
data/config/mongoid.yml
ADDED
@@ -7,7 +7,7 @@ module ActiveSearch
|
|
7
7
|
include HTTParty
|
8
8
|
|
9
9
|
def self.configure(api_key, app_id, index = "activesearch")
|
10
|
-
base_uri "https
|
10
|
+
base_uri "https://#{app_id}.algolia.io/1/indexes/#{index}"
|
11
11
|
headers({
|
12
12
|
"X-Algolia-API-Key" => api_key,
|
13
13
|
"X-Algolia-Application-Id" => app_id,
|
data/lib/activesearch/algolia.rb
CHANGED
@@ -5,8 +5,10 @@ require "activesearch/proxy"
|
|
5
5
|
module ActiveSearch
|
6
6
|
def self.search(text, conditions = {})
|
7
7
|
Proxy.new(text, conditions) do |text, conditions|
|
8
|
-
|
9
|
-
|
8
|
+
options = {}
|
9
|
+
tags = conditions_to_tags(conditions)
|
10
|
+
options.merge!(tags: tags) if tags != ""
|
11
|
+
Algolia::Client.new.query(text, options)["hits"].map! do |hit|
|
10
12
|
if hit["_tags"]
|
11
13
|
hit["_tags"].each do |tag|
|
12
14
|
k, v = tag.split(':')
|
@@ -34,6 +36,9 @@ module ActiveSearch
|
|
34
36
|
protected
|
35
37
|
def reindex
|
36
38
|
algolia_client.save(indexable_id, self.to_indexable)
|
39
|
+
rescue
|
40
|
+
self.touch
|
41
|
+
false
|
37
42
|
end
|
38
43
|
|
39
44
|
def deindex
|
@@ -31,12 +31,13 @@ module ActiveSearch
|
|
31
31
|
|
32
32
|
if original.fields[f.to_s].localized?
|
33
33
|
memo += original.send("#{f}_translations").map do |locale,translation|
|
34
|
+
next if translation.nil?
|
34
35
|
translation.downcase.split.map { |word| "#{locale}:#{word}"}
|
35
36
|
end.flatten
|
36
37
|
else
|
37
38
|
if original[f]
|
38
39
|
memo += if original[f].is_a?(Array)
|
39
|
-
original[f].map
|
40
|
+
original[f].map { |value| value.nil? ? nil : value.downcase }
|
40
41
|
else
|
41
42
|
original[f].downcase.split
|
42
43
|
end
|
data/lib/activesearch/version.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
3
|
+
require 'activesearch/algolia'
|
4
|
+
require_relative 'models/algolia'
|
5
|
+
|
6
|
+
YAML.load_file(File.dirname(__FILE__) + '/../config/algolia.yml').tap do |config|
|
7
|
+
ActiveSearch::Algolia::Client.configure(config["api_key"], config["app_id"])
|
8
|
+
end
|
9
|
+
|
10
|
+
describe ActiveSearch::Algolia do
|
11
|
+
before do
|
12
|
+
ActiveSearch::Algolia::Client.new.delete_index
|
13
|
+
end
|
14
|
+
|
15
|
+
context "errors on save" do
|
16
|
+
before do
|
17
|
+
@instance = AlgoliaModel.new(title: "Example")
|
18
|
+
@instance.should_receive(:touch).once
|
19
|
+
ActiveSearch::Algolia::Client.any_instance.stub(:save).and_raise(Errno::ECONNRESET)
|
20
|
+
end
|
21
|
+
|
22
|
+
subject { -> { @instance.save } }
|
23
|
+
|
24
|
+
it { should_not raise_error }
|
25
|
+
end
|
26
|
+
end
|
data/spec/mongoid_spec.rb
CHANGED
@@ -3,20 +3,22 @@ require File.join(File.dirname(__FILE__), 'spec_helper')
|
|
3
3
|
require 'mongoid'
|
4
4
|
require 'activesearch/mongoid'
|
5
5
|
|
6
|
-
Mongoid.
|
6
|
+
Mongoid.load!("config/mongoid.yml", :test)
|
7
7
|
|
8
8
|
class LocalizedMongoidModel
|
9
9
|
include Mongoid::Document
|
10
10
|
include ActiveSearch::Mongoid
|
11
11
|
|
12
12
|
field :title, localize: true
|
13
|
-
|
13
|
+
field :not_localized
|
14
|
+
field :array, type: Array
|
15
|
+
search_by [:title, :not_localized, :array, store: [:title]]
|
14
16
|
end
|
15
17
|
|
16
18
|
|
17
19
|
describe ActiveSearch::Mongoid do
|
18
20
|
before do
|
19
|
-
Mongoid.
|
21
|
+
Mongoid.purge!
|
20
22
|
I18n.locale = :en
|
21
23
|
@localized = LocalizedMongoidModel.create!(title: "<strong>English</strong> English")
|
22
24
|
I18n.with_locale(:es) do
|
@@ -35,4 +37,16 @@ describe ActiveSearch::Mongoid do
|
|
35
37
|
it "should store localized keywords with tags stripped" do
|
36
38
|
ActiveSearch::Mongoid::Model.where(_original_type: "LocalizedMongoidModel", _original_id: @localized.id).first._keywords.should == ["en:english", "es:español"]
|
37
39
|
end
|
40
|
+
|
41
|
+
it "handles empty translations" do
|
42
|
+
lambda { LocalizedMongoidModel.create!(title: nil, not_localized: "example") }.should_not raise_error
|
43
|
+
end
|
44
|
+
|
45
|
+
it "handles empty fields" do
|
46
|
+
lambda { LocalizedMongoidModel.create!(title: "Example", not_localized: nil) }.should_not raise_error
|
47
|
+
end
|
48
|
+
|
49
|
+
it "handles nil values in arrays" do
|
50
|
+
lambda { LocalizedMongoidModel.create!(title: "Example", not_localized: "example", array: [nil]) }.should_not raise_error
|
51
|
+
end
|
38
52
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activesearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Alvarez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -149,6 +149,7 @@ files:
|
|
149
149
|
- README.md
|
150
150
|
- Rakefile
|
151
151
|
- activesearch.gemspec
|
152
|
+
- config/mongoid.yml
|
152
153
|
- config/sample.algolia.yml
|
153
154
|
- lib/activesearch.rb
|
154
155
|
- lib/activesearch/algolia.rb
|
@@ -160,6 +161,7 @@ files:
|
|
160
161
|
- lib/activesearch/proxy.rb
|
161
162
|
- lib/activesearch/result.rb
|
162
163
|
- lib/activesearch/version.rb
|
164
|
+
- spec/algolia_spec.rb
|
163
165
|
- spec/base_spec.rb
|
164
166
|
- spec/config/mongoid.yml
|
165
167
|
- spec/engines_spec.rb
|
@@ -187,12 +189,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
187
189
|
version: '0'
|
188
190
|
requirements: []
|
189
191
|
rubyforge_project:
|
190
|
-
rubygems_version: 2.0.
|
192
|
+
rubygems_version: 2.0.5
|
191
193
|
signing_key:
|
192
194
|
specification_version: 4
|
193
195
|
summary: ActiveSearch lets you plug in a ruby module in any class that will allow
|
194
196
|
you to do full text searches.
|
195
197
|
test_files:
|
198
|
+
- spec/algolia_spec.rb
|
196
199
|
- spec/base_spec.rb
|
197
200
|
- spec/config/mongoid.yml
|
198
201
|
- spec/engines_spec.rb
|