activesearch 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -30,7 +30,7 @@ The second parameter must be a conditions hash.**
30
30
 
31
31
  the :store option allows you to store that value in the index but it won't be used for search.
32
32
  You can also add :if or :unless conditions in the same way you would do with ActiveModel callbacks.
33
- If you need dynamic options, pass a symbol instead:
33
+ If you need virtual options, pass a symbol instead:
34
34
 
35
35
  search_by :options_for_search
36
36
 
@@ -17,7 +17,9 @@ module ActiveSearch
17
17
  end
18
18
 
19
19
  def to_indexable
20
- self.attributes.merge(_type: self.elastic_type)
20
+ elastic_properties.keys.inject({_type: self.elastic_type}) do |memo,field|
21
+ memo.merge(field => self.send(field))
22
+ end
21
23
  end
22
24
 
23
25
  protected
@@ -49,7 +51,7 @@ module ActiveSearch
49
51
  end
50
52
 
51
53
  def elastic_properties
52
- props = {}
54
+ props = {id: {type: 'string'}}
53
55
 
54
56
  search_fields.each_with_object(props) do |field,hash|
55
57
  hash[field] = {type: 'string'}
@@ -19,7 +19,12 @@ module ActiveSearch
19
19
  if options && options[:store]
20
20
  self._stored = {}
21
21
  options[:store].each do |f|
22
- self._stored[f] = original[f] if original[f].present?
22
+
23
+ if original.fields[f.to_s] && original.fields[f.to_s].localized?
24
+ self._stored[f] = original.send("#{f}_translations")
25
+ else
26
+ self._stored[f] = original.send(f) if original.send(f).present?
27
+ end
23
28
  end
24
29
  end
25
30
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveSearch
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
data/spec/base_spec.rb CHANGED
@@ -44,7 +44,7 @@ describe ActiveSearch::Base do
44
44
  end
45
45
  end
46
46
 
47
- context "search_by with dynamic parameters" do
47
+ context "search_by with virtual parameters" do
48
48
  before do
49
49
  @klass.class_eval do
50
50
  def options_for_search
data/spec/engines_spec.rb CHANGED
@@ -30,10 +30,11 @@ Dir[File.join(File.dirname(__FILE__), 'models', '*.rb')].map { |f| File.basename
30
30
  end
31
31
 
32
32
  it "should find the expected documents" do
33
- results = ActiveSearch.search("findable").map { |doc| doc.to_hash.select { |k,v| %w[title junk].include?(k.to_s) } }
33
+ results = ActiveSearch.search("findable").map { |doc| doc.to_hash.select { |k,v| %w[title junk virtual].include?(k.to_s) } }
34
34
  results.sort_by { |result| result["title"] }.should == [
35
35
  {
36
- "title" => "Another findable title"
36
+ "title" => "Another findable title",
37
+ "virtual" => "virtual"
37
38
  },
38
39
  {
39
40
  "title" => "Findable Findable",
@@ -29,5 +29,9 @@ class AnotherElasticSearchModel < ActiveMimic
29
29
  include ElasticSearchRefresh
30
30
 
31
31
  attribute :title, type: String
32
- search_by [:title, store: [:title]]
32
+ search_by [:title, store: [:title, :virtual]]
33
+
34
+ def virtual
35
+ "virtual"
36
+ end
33
37
  end
@@ -22,7 +22,11 @@ class AnotherMongoidModel
22
22
  search_by :options_for_search
23
23
 
24
24
  def options_for_search
25
- [:title, :text, store: [:title]]
25
+ [:title, :text, store: [:title, :virtual]]
26
+ end
27
+
28
+ def virtual
29
+ "virtual"
26
30
  end
27
31
  end
28
32
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activesearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: