solrsan 0.0.24 → 0.0.25

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- solrsan (0.0.23)
4
+ solrsan (0.0.24)
5
5
  activemodel (~> 3.0.5)
6
6
  activesupport (~> 3.0.5)
7
7
  rsolr (~> 1.0.0)
@@ -410,8 +410,8 @@
410
410
  <!-- Configure the standard formatter -->
411
411
  <formatter name="html" class="org.apache.solr.highlight.HtmlFormatter" default="true">
412
412
  <lst name="defaults">
413
- <str name="hl.simple.pre"><![CDATA[<em>]]></str>
414
- <str name="hl.simple.post"><![CDATA[</em>]]></str>
413
+ <str name="hl.simple.pre"><![CDATA[<mark>]]></str>
414
+ <str name="hl.simple.post"><![CDATA[</mark>]]></str>
415
415
  </lst>
416
416
  </formatter>
417
417
  </highlighting>
@@ -2,6 +2,10 @@ module Solrsan
2
2
  module Search
3
3
  extend ActiveSupport::Concern
4
4
  module ClassMethods
5
+
6
+ HL_START_TAG = "<mark>"
7
+ HL_END_TAG = "</mark>"
8
+
5
9
  def class_name
6
10
  to_s.underscore
7
11
  end
@@ -143,7 +147,16 @@ module Solrsan
143
147
 
144
148
  highlighted_docs = search_response[:docs].map do |doc|
145
149
  hl_metadata = search_response[:highlighting][doc['id']]
146
- hl_metadata.each{ |k,v| doc[k] = v unless excluded_highlighting_fields.include?(k)} if hl_metadata
150
+
151
+ hl_metadata.drop_while{|k,v| excluded_highlighting_fields.include?(k) }.each do |k,v|
152
+ new_value = if v.is_a?(Array)
153
+ matched = v.map{|t| t.gsub(HL_START_TAG,"").gsub(HL_END_TAG,"") }
154
+ doc[k].drop_while{|text| matched.include?(text) }.concat(v)
155
+ else
156
+ v
157
+ end
158
+ doc[k] = new_value
159
+ end if hl_metadata
147
160
 
148
161
  doc
149
162
  end
@@ -1,3 +1,3 @@
1
1
  module Solrsan
2
- VERSION = "0.0.24"
2
+ VERSION = "0.0.25"
3
3
  end
@@ -165,16 +165,16 @@ class SearchTest < Test::Unit::TestCase
165
165
  highlighting = response[:highlighting]
166
166
 
167
167
  first_result = highlighting.first
168
- assert first_result[1]['tags'].include?("<em>solr</em>")
168
+ assert first_result[1]['tags'].include?("<mark>solr</mark>")
169
169
  end
170
170
 
171
171
  def test_embed_highlighting
172
- Document.index(Document.new(:id => 3, :author => "Bert", :title => "solr lucene",:review_count => 10, :tags => ["solr"]))
172
+ Document.index(Document.new(:id => 3, :author => "Bert", :title => "solr lucene",:review_count => 10, :tags => ["solr", "sphinx"]))
173
173
 
174
174
  response = Document.search(:q => "solr",
175
175
  :'hl.fl' => "*")
176
176
  docs = response[:docs]
177
- assert docs.first['tags'].include?("<em>solr</em>")
177
+ assert_equal ["sphinx", "<mark>solr</mark>"], docs.first['tags']
178
178
  end
179
179
  end
180
180
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solrsan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.24
4
+ version: 0.0.25
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-03-24 00:00:00.000000000 -07:00
12
+ date: 2011-03-25 00:00:00.000000000 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rsolr
17
- requirement: &2153746600 !ruby/object:Gem::Requirement
17
+ requirement: &2160641540 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 1.0.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2153746600
25
+ version_requirements: *2160641540
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: activemodel
28
- requirement: &2153746100 !ruby/object:Gem::Requirement
28
+ requirement: &2160641040 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 3.0.5
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *2153746100
36
+ version_requirements: *2160641040
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: activesupport
39
- requirement: &2153745640 !ruby/object:Gem::Requirement
39
+ requirement: &2160640580 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,7 +44,7 @@ dependencies:
44
44
  version: 3.0.5
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *2153745640
47
+ version_requirements: *2160640580
48
48
  description: solrsan is a lightweight wrapper for using Apache Solr within a Ruby
49
49
  application including Rails and Sinatra.
50
50
  email: