Commit 3988ec2cb1d90a7ed8d84811b36458fc7afb1032

Authored by Andrew Kane
1 parent 295bd668

Added highlight test

lib/searchkick/reindex.rb
@@ -202,8 +202,8 @@ module Searchkick @@ -202,8 +202,8 @@ module Searchkick
202 type: "multi_field", 202 type: "multi_field",
203 fields: { 203 fields: {
204 field => {type: "string", index: "not_analyzed"}, 204 field => {type: "string", index: "not_analyzed"},
205 - "analyzed" => {type: "string", index: "analyzed", term_vector: "with_positions_offsets"}  
206 - # term_vector for fast / correct highlighting 205 + "analyzed" => {type: "string", index: "analyzed"}
  206 + # term_vector: "with_positions_offsets" for fast / correct highlighting
207 # http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-highlighting.html#_fast_vector_highlighter 207 # http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-highlighting.html#_fast_vector_highlighter
208 } 208 }
209 } 209 }
test/highlight_test.rb 0 → 100644
@@ -0,0 +1,22 @@ @@ -0,0 +1,22 @@
  1 +require_relative "test_helper"
  2 +
  3 +class TestHighlight < Minitest::Unit::TestCase
  4 +
  5 + def test_basic
  6 + store_names ["Two Door Cinema Club"]
  7 + assert_equal "Two Door <em>Cinema</em> Club", Product.search("cinema", fields: [:name], highlight: true).each_with_hit.first[1]["highlight"]["name.analyzed"].first
  8 + end
  9 +
  10 + def test_tag
  11 + store_names ["Two Door Cinema Club"]
  12 + assert_equal "Two Door <strong>Cinema</strong> Club", Product.search("cinema", fields: [:name], highlight: {tag: "<strong>"}).each_with_hit.first[1]["highlight"]["name.analyzed"].first
  13 + end
  14 +
  15 + def test_multiple_fields
  16 + store [{name: "Two Door Cinema Club", color: "Cinema Orange"}]
  17 + highlight = Product.search("cinema", fields: [:name, :color], highlight: true).each_with_hit.first[1]["highlight"]
  18 + assert_equal "Two Door <em>Cinema</em> Club", highlight["name.analyzed"].first
  19 + assert_equal "<em>Cinema</em> Orange", highlight["color.analyzed"].first
  20 + end
  21 +
  22 +end