activesearch 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/activesearch/mongoid/model.rb +12 -2
- data/lib/activesearch/version.rb +1 -1
- data/spec/engines_spec.rb +6 -2
- data/spec/models/algolia.rb +2 -1
- data/spec/models/elastic_search.rb +2 -1
- data/spec/models/mongoid.rb +3 -1
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OWQyZDE0NTc4MTEyZWVlNmQ4ZmYyZDRlNWM3ZDE2N2Y2ZGQ0NDJmMg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OTFmMWY4NTdjZDYzZTZhZTgzYjA1OTc3ODcwMDQzZGZhMDI5MzU4Nw==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZDU1YjU3NjhjYjlmMTkyNTVhNzY0NzBjYjdiZmQwZTkyZjM0MjJiMzg2MmI3
|
10
|
+
NThjMWM2MzlmZTBjZTlmNTA4YmM1MGMxNzBiN2ZlZDRlMjBjMWZjZGZjZmEw
|
11
|
+
ZDI0OTNlNmU2MjlhMTZjNTIyYjM5MDU3Y2U1MzljNjRlNjJlOGE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OWIwYTFmOTUwMDE4ZWRmN2IxMWEwZmQ2MGZlZmZhZmNkMGMyMmY4ZjdhOGFi
|
14
|
+
ODBhYjcyNzMxZDlmNGM4MjUzOTdhMGZjZmMwZTM4MDJjNmFhYWI5NjVhNTYw
|
15
|
+
MWYwYjA4MTdmNDE3NmM4MWMzYTVkYTYyYzNjNDQ1YzU3OTFhMmU=
|
@@ -27,16 +27,26 @@ module ActiveSearch
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def refresh_keywords(original, fields)
|
30
|
-
self._keywords = fields.select { |f| original.fields[f.to_s]
|
30
|
+
self._keywords = fields.select { |f| original.fields[f.to_s] }.inject([]) do |memo,f|
|
31
31
|
|
32
32
|
if original.fields[f.to_s].localized?
|
33
33
|
memo += original.send("#{f}_translations").map do |locale,translation|
|
34
34
|
translation.downcase.split.map { |word| "#{locale}:#{word}"}
|
35
35
|
end.flatten
|
36
36
|
else
|
37
|
-
|
37
|
+
if original[f]
|
38
|
+
memo += if original[f].is_a?(Array)
|
39
|
+
original[f].map(&:downcase)
|
40
|
+
else
|
41
|
+
original[f].downcase.split
|
42
|
+
end
|
43
|
+
|
44
|
+
else
|
45
|
+
memo
|
46
|
+
end
|
38
47
|
end
|
39
48
|
end
|
49
|
+
|
40
50
|
self._keywords = self._keywords.map! { |k| ActiveSearch.strip_tags(k) }
|
41
51
|
self._keywords.uniq!
|
42
52
|
end
|
data/lib/activesearch/version.rb
CHANGED
data/spec/engines_spec.rb
CHANGED
@@ -33,6 +33,7 @@ Dir[File.join(File.dirname(__FILE__), 'models', '*.rb')].map { |f| File.basename
|
|
33
33
|
@junk = Object.const_get("#{engine}Model").create(title: "Junk", junk: "Not Findable junk", scope_id: 1)
|
34
34
|
@special = Object.const_get("#{engine}Model").create(title: "Not findable because it's special", special: true, scope_id: 1)
|
35
35
|
@foreign = Object.const_get("#{engine}Model").create(title: "Findable", scope_id: 2)
|
36
|
+
@tagged = Object.const_get("#{engine}Model").create(title: "Tagged document", tags: ['findable'], scope_id: 1)
|
36
37
|
end
|
37
38
|
|
38
39
|
it "should find the expected documents" do
|
@@ -49,18 +50,21 @@ Dir[File.join(File.dirname(__FILE__), 'models', '*.rb')].map { |f| File.basename
|
|
49
50
|
{
|
50
51
|
"title" => "Some title"
|
51
52
|
},
|
53
|
+
{
|
54
|
+
"title" => "Tagged document"
|
55
|
+
}
|
52
56
|
]
|
53
57
|
ActiveSearch.search("some text").first.to_hash["title"].should == "Some title"
|
54
58
|
ActiveSearch.search("junk").first.to_hash["title"].should == "Junk"
|
55
59
|
end
|
56
60
|
|
57
61
|
it "should find docs even with upcase searches" do
|
58
|
-
ActiveSearch.search("FINDABLE").count.should ==
|
62
|
+
ActiveSearch.search("FINDABLE").count.should == 5
|
59
63
|
end
|
60
64
|
|
61
65
|
it "should remove destroyed documents from index" do
|
62
66
|
@findable.destroy
|
63
|
-
ActiveSearch.search("findable").count.should ==
|
67
|
+
ActiveSearch.search("findable").count.should == 4
|
64
68
|
end
|
65
69
|
end
|
66
70
|
end
|
data/spec/models/algolia.rb
CHANGED
@@ -8,8 +8,9 @@ class AlgoliaModel < ActiveMimic
|
|
8
8
|
attribute :junk
|
9
9
|
attribute :special, default: false
|
10
10
|
attribute :scope_id, type: Integer
|
11
|
+
attribute :tags, type: Array
|
11
12
|
|
12
|
-
search_by [:title, :text, store: [:title, :junk, :scope_id]], if: lambda { !self.special }
|
13
|
+
search_by [:title, :text, :tags, store: [:title, :junk, :scope_id]], if: lambda { !self.special }
|
13
14
|
|
14
15
|
end
|
15
16
|
|
@@ -19,8 +19,9 @@ class ElasticSearchModel < ActiveMimic
|
|
19
19
|
attribute :text
|
20
20
|
attribute :junk
|
21
21
|
attribute :special, default: false
|
22
|
+
attribute :tags, type: Array
|
22
23
|
|
23
|
-
search_by [:title, :text, store: [:title, :junk]], if: lambda { !self.special }
|
24
|
+
search_by [:title, :text, :tags, store: [:title, :junk]], if: lambda { !self.special }
|
24
25
|
|
25
26
|
end
|
26
27
|
|
data/spec/models/mongoid.rb
CHANGED
@@ -14,7 +14,9 @@ class MongoidModel
|
|
14
14
|
field :junk, type: String
|
15
15
|
field :special, type: Boolean, default: false
|
16
16
|
field :scope_id, type: Integer
|
17
|
-
|
17
|
+
field :tags, type: Array
|
18
|
+
|
19
|
+
search_by [:title, :text, :tags, store: [:title, :junk, :scope_id]], unless: :special
|
18
20
|
end
|
19
21
|
|
20
22
|
class AnotherMongoidModel
|
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.1
|
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-05
|
11
|
+
date: 2013-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -201,4 +201,3 @@ test_files:
|
|
201
201
|
- spec/models/mongoid.rb
|
202
202
|
- spec/mongoid_spec.rb
|
203
203
|
- spec/spec_helper.rb
|
204
|
-
has_rdoc:
|