es-elasticity 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/elasticity/document.rb +3 -9
- data/lib/elasticity/search.rb +17 -1
- data/lib/elasticity/version.rb +1 -1
- data/spec/units/document_spec.rb +0 -1
- data/spec/units/multi_search_spec.rb +1 -1
- data/spec/units/search_spec.rb +15 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92bedfd2fa34df6c303c9c0945ba55c7613c7a31
|
4
|
+
data.tar.gz: bc68cc7bd8bd36ec8d195a53df1684871b20caec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87b00d0798444997de4c2fe057a5cd1c7bd4990a38b3cecaa78795fb0dd1a069ab3aff3311df61abfd828175e1db9f7cebb66a36007c643d68b4a4cfc883b92e
|
7
|
+
data.tar.gz: ea32e3c290a7ec6238fc64e43f0b2792ea259ab444ac3868eb8a9ff1944ff05c59cd2fdd1de410a9353eb91db52d98a3a8cd811d7c7751534e884628ed30deb0
|
data/lib/elasticity/document.rb
CHANGED
@@ -23,13 +23,6 @@ module Elasticity
|
|
23
23
|
self.index.delete
|
24
24
|
end
|
25
25
|
|
26
|
-
# The index name to be used for indexing and storing data for this document model.
|
27
|
-
# By default, it's the class name converted to underscore and plural.
|
28
|
-
def self.index_name
|
29
|
-
return @index_name if defined?(@index_name)
|
30
|
-
@index_name = self.name.underscore.pluralize
|
31
|
-
end
|
32
|
-
|
33
26
|
# Sets the index name to something else than the default
|
34
27
|
def self.index_name=(name)
|
35
28
|
@index_name = name
|
@@ -38,7 +31,7 @@ module Elasticity
|
|
38
31
|
|
39
32
|
# Namespaced index name
|
40
33
|
def self.namespaced_index_name
|
41
|
-
name = self.
|
34
|
+
name = @index_name || self.name.underscore.pluralize
|
42
35
|
|
43
36
|
if namespace = Elasticity.config.namespace
|
44
37
|
name = "#{namespace}_#{name}"
|
@@ -99,7 +92,7 @@ module Elasticity
|
|
99
92
|
end
|
100
93
|
|
101
94
|
# Define common attributes for all documents
|
102
|
-
attr_accessor :_id
|
95
|
+
attr_accessor :_id, :highlighted
|
103
96
|
|
104
97
|
# Creates a new Document instance with the provided attributes.
|
105
98
|
def initialize(attributes = {})
|
@@ -114,6 +107,7 @@ module Elasticity
|
|
114
107
|
|
115
108
|
# Defines equality by comparing the ID and values of each instance variable.
|
116
109
|
def ==(other)
|
110
|
+
return false if other.nil?
|
117
111
|
return false if _id != other._id
|
118
112
|
|
119
113
|
instance_variables.all? do |ivar|
|
data/lib/elasticity/search.rb
CHANGED
@@ -99,7 +99,23 @@ module Elasticity
|
|
99
99
|
|
100
100
|
def map(hits)
|
101
101
|
hits.map do |hit|
|
102
|
-
|
102
|
+
attrs = hit["_source"].merge(_id: hit['_id'])
|
103
|
+
|
104
|
+
if hit["highlight"]
|
105
|
+
highlighted_attrs = attrs.dup
|
106
|
+
attrs_set = Set.new
|
107
|
+
|
108
|
+
hit["highlight"].each do |name, v|
|
109
|
+
name = name.gsub(/\..*\z/, '')
|
110
|
+
next if attrs_set.include?(name)
|
111
|
+
highlighted_attrs[name] = v
|
112
|
+
attrs_set << name
|
113
|
+
end
|
114
|
+
|
115
|
+
highlighted = @document_klass.new(highlighted_attrs)
|
116
|
+
end
|
117
|
+
|
118
|
+
@document_klass.new(attrs.merge(highlighted: highlighted))
|
103
119
|
end
|
104
120
|
end
|
105
121
|
end
|
data/lib/elasticity/version.rb
CHANGED
data/spec/units/document_spec.rb
CHANGED
@@ -47,7 +47,6 @@ RSpec.describe Elasticity::Document do
|
|
47
47
|
subject { klass }
|
48
48
|
|
49
49
|
it "extracts index name and document type from the class name" do
|
50
|
-
expect(subject.index_name).to eq "class_names"
|
51
50
|
expect(subject.namespaced_index_name).to eq "elasticity_test_class_names"
|
52
51
|
expect(subject.document_type).to eq "class_name"
|
53
52
|
expect(subject.index.name).to eq "elasticity_test_class_names"
|
data/spec/units/search_spec.rb
CHANGED
@@ -23,10 +23,16 @@ RSpec.describe "Search" do
|
|
23
23
|
{ "hits" => { "total" => 0, "hits" => [] }}
|
24
24
|
end
|
25
25
|
|
26
|
+
let :highlight_response do
|
27
|
+
{ "hits" => { "total" => 1, "hits" => [
|
28
|
+
{ "_id" => 1, "_source" => { "name" => "foo", "age" => 21 }, "highlight" => { "name" => "<em>foo</em>" } },
|
29
|
+
]}}
|
30
|
+
end
|
31
|
+
|
26
32
|
let :klass do
|
27
33
|
Class.new do
|
28
34
|
include ActiveModel::Model
|
29
|
-
attr_accessor :_id, :name
|
35
|
+
attr_accessor :_id, :name, :age, :highlighted
|
30
36
|
|
31
37
|
def ==(other)
|
32
38
|
self._id == other._id && self.name == other.name
|
@@ -82,6 +88,14 @@ RSpec.describe "Search" do
|
|
82
88
|
|
83
89
|
expect(subject.active_records(relation).mapping).to be relation
|
84
90
|
end
|
91
|
+
|
92
|
+
it "creates highlighted object for documents" do
|
93
|
+
expect(index).to receive(:search).with(document_type, body).and_return(highlight_response)
|
94
|
+
doc = subject.documents(klass).first
|
95
|
+
|
96
|
+
expect(doc).to_not be_nil
|
97
|
+
expect(doc.highlighted).to eq klass.new(_id: 1, name: "<em>foo</em>", age: 21)
|
98
|
+
end
|
85
99
|
end
|
86
100
|
|
87
101
|
describe Elasticity::DocumentSearchProxy do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: es-elasticity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Kochenburger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|