activesearch 0.0.11 → 0.0.12

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.
@@ -1,6 +1,15 @@
1
1
  require "active_support/core_ext/class/attribute"
2
2
 
3
3
  module ActiveSearch
4
+ def self.strip_tags(value)
5
+ case value
6
+ when String
7
+ value.gsub(/<\/?[^>]*>/, '')
8
+ when Hash
9
+ value.each { |k,v| value[k] = strip_tags(value[k]) }
10
+ end
11
+ end
12
+
4
13
  module Base
5
14
  def self.included(parent)
6
15
  parent.extend ClassMethods
@@ -17,7 +17,7 @@ module ActiveSearch
17
17
  def search
18
18
  @search ||= Tire.search('_all') do |search|
19
19
  search.query do |query|
20
- query.text("_all", @text)
20
+ query.match("_all", @text)
21
21
  end
22
22
  end
23
23
  end
@@ -18,7 +18,7 @@ module ActiveSearch
18
18
 
19
19
  def to_indexable
20
20
  elastic_properties.keys.inject({_type: self.elastic_type}) do |memo,field|
21
- memo.merge(field => self.send(field))
21
+ memo.merge!(field => self.send(field))
22
22
  end
23
23
  end
24
24
 
@@ -40,6 +40,7 @@ module ActiveSearch
40
40
  original[f] ? memo += original[f].downcase.split : memo
41
41
  end
42
42
  end
43
+ self._keywords = self._keywords.map! { |k| ActiveSearch.strip_tags(k) }
43
44
  self._keywords.uniq!
44
45
  end
45
46
 
@@ -1,3 +1,3 @@
1
1
  module ActiveSearch
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
data/spec/engines_spec.rb CHANGED
@@ -24,7 +24,7 @@ Dir[File.join(File.dirname(__FILE__), 'models', '*.rb')].map { |f| File.basename
24
24
  cleanup(engine)
25
25
  @findable = Object.const_get("#{engine}Model").create(title: "Findable Findable", junk: "Junk field")
26
26
  @quite_findable = Object.const_get("#{engine}Model").create(title: "Some title", text: "Findable text")
27
- @another = Object.const_get("Another#{engine}Model").create(title: "Another findable title")
27
+ @another = Object.const_get("Another#{engine}Model").create(title: "Another <strong>findable</strong> title with tags")
28
28
  @junk = Object.const_get("#{engine}Model").create(title: "Junk", junk: "Not Findable junk")
29
29
  @special = Object.const_get("#{engine}Model").create(title: "Not findable because it's special", special: true)
30
30
  end
@@ -33,7 +33,7 @@ Dir[File.join(File.dirname(__FILE__), 'models', '*.rb')].map { |f| File.basename
33
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 <strong>findable</strong> title with tags",
37
37
  "virtual" => "virtual"
38
38
  },
39
39
  {
data/spec/mongoid_spec.rb CHANGED
@@ -18,7 +18,7 @@ describe ActiveSearch::Mongoid do
18
18
  before do
19
19
  Mongoid.master.collections.select { |c| c.name != 'system.indexes' }.each(&:drop)
20
20
  I18n.locale = :en
21
- @localized = LocalizedMongoidModel.create!(title: "English English")
21
+ @localized = LocalizedMongoidModel.create!(title: "<strong>English</strong> English")
22
22
  I18n.with_locale(:es) do
23
23
  @localized.title = "Español Español"
24
24
  @localized.save!
@@ -26,7 +26,7 @@ describe ActiveSearch::Mongoid do
26
26
  end
27
27
 
28
28
  it "should be able to find by different locales" do
29
- ActiveSearch.search("english").first._stored["title"]["en"].should == "English English"
29
+ ActiveSearch.search("english").first._stored["title"]["en"].should == "<strong>English</strong> English"
30
30
  I18n.with_locale(:es) do
31
31
  ActiveSearch.search("español").first._stored["title"]["es"].should == "Español Español"
32
32
  end
@@ -35,4 +35,8 @@ describe ActiveSearch::Mongoid do
35
35
  it "should store localized keywords" do
36
36
  ActiveSearch::Mongoid::Model.where(_original_type: "LocalizedMongoidModel", _original_id: @localized.id).first._keywords.should == ["en:english", "es:español"]
37
37
  end
38
+
39
+ it "should strip tags" do
40
+ ActiveSearch.search("english").first._keywords.should == ['en:english', 'es:español']
41
+ end
38
42
  end
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.11
4
+ version: 0.0.12
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-15 00:00:00.000000000 Z
12
+ date: 2013-04-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport