isomorfeus-data 2.0.19 → 2.0.20
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.
- checksums.yaml +4 -4
- data/lib/isomorfeus/data/{ferret_accelerator.rb → document_accelerator.rb} +2 -2
- data/lib/isomorfeus/data/object_accelerator.rb +75 -0
- data/lib/isomorfeus/data/{hamster_storage_expander.rb → object_expander.rb} +1 -1
- data/lib/isomorfeus/data/version.rb +1 -1
- data/lib/isomorfeus-data.rb +3 -3
- data/lib/isomorfeus_data/lucid_document/mixin.rb +2 -2
- data/lib/isomorfeus_data/lucid_object/mixin.rb +11 -6
- metadata +11 -11
- data/lib/isomorfeus/data/hamster_accelerator.rb +0 -87
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bc1da15cc5909c1c6fe181094dba6c61f8bd070dc57441e3df7d47e13f5179d
|
4
|
+
data.tar.gz: 60106fca2424268f4b92624c1945e364406a958de65c601bf3949c0a4c5ade55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24ef5ddf157caff32c7bded5e0728b03ab2e226754a6cb3522d7ffab1814108e9643a5fb2f4c39a62f463e16ec5438699213d9e012d5ca5c9e65d1a04b21c595
|
7
|
+
data.tar.gz: 257cde03efe55526ecff7b2f5513cc8f0109977c4260f35545682384773f1ca7fb11030479a1b5e456ebdafd9bfb83ebc748d4d5867c5b36703f1906a32d9ab6
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Isomorfeus
|
2
2
|
module Data
|
3
|
-
class
|
3
|
+
class DocumentAccelerator
|
4
4
|
def self.finalize(fer_acc)
|
5
5
|
proc { fer_acc.close_index }
|
6
6
|
end
|
@@ -73,7 +73,7 @@ module Isomorfeus
|
|
73
73
|
def open_index
|
74
74
|
FileUtils.mkdir_p(Isomorfeus.data_documents_path) unless Dir.exist?(Isomorfeus.data_documents_path)
|
75
75
|
field_infos = Isomorfeus::Ferret::Index::FieldInfos.new(store: :yes, index: :yes, term_vector: :with_positions_offsets)
|
76
|
-
@index = Isomorfeus::Ferret::Index::Index.new(path: index_path, key: :key, auto_flush: true, lock_retry_time: 5)
|
76
|
+
@index = Isomorfeus::Ferret::Index::Index.new(path: index_path, key: :key, auto_flush: true, lock_retry_time: 5, field_infos: field_infos)
|
77
77
|
@index.field_infos.add_field(:key, store: :yes, index: :yes, term_vector: :no) unless @index.field_infos[:key]
|
78
78
|
@doc_class.field_options.each do |field, options|
|
79
79
|
@index.field_infos.add_field(field, options) unless @index.field_infos[field]
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Isomorfeus
|
2
|
+
module Data
|
3
|
+
class ObjectAccelerator
|
4
|
+
def self.finalize(ham_acc)
|
5
|
+
proc { ham_acc.close_index }
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_accessor :index
|
9
|
+
|
10
|
+
def initialize(&block)
|
11
|
+
if block_given?
|
12
|
+
res = block.call(self)
|
13
|
+
@index = res unless @index
|
14
|
+
else
|
15
|
+
open_index
|
16
|
+
end
|
17
|
+
ObjectSpace.define_finalizer(self, self.class.finalize(self))
|
18
|
+
end
|
19
|
+
|
20
|
+
def destroy_index
|
21
|
+
close_index
|
22
|
+
FileUtils.rm_rf(Isomorfeus.data_object_idx_path)
|
23
|
+
end
|
24
|
+
|
25
|
+
def close_index
|
26
|
+
@index.close
|
27
|
+
end
|
28
|
+
|
29
|
+
def create_doc(document)
|
30
|
+
@index.add_document(document)
|
31
|
+
end
|
32
|
+
|
33
|
+
def destroy_doc(key)
|
34
|
+
id = get_doc_id(key)
|
35
|
+
@index.delete(id) if id
|
36
|
+
true
|
37
|
+
end
|
38
|
+
|
39
|
+
def load_doc(key)
|
40
|
+
id = get_doc_id(key)
|
41
|
+
@index.doc(id)&.load&.to_h if id
|
42
|
+
end
|
43
|
+
|
44
|
+
def save_doc(key, document)
|
45
|
+
id = get_doc_id(key)
|
46
|
+
if id
|
47
|
+
@index.update(id, document)
|
48
|
+
true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def search_each(query, options, &block)
|
53
|
+
@index.search_each(query, options, &block)
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def get_doc_id(key)
|
59
|
+
# special characters must be escaped, characters taken from the ferret query parser documentation
|
60
|
+
escaped_key = key.gsub(/([\\\&\:\(\)\[\]\{\}\!\"\~\^\|\<\>\=\*\?\+\-\s])/, '\\\\\1')
|
61
|
+
top_docs = @index.search("sid_s_attr:\"#{escaped_key}\"", limit: 1)
|
62
|
+
id = top_docs.hits[0].doc if top_docs.total_hits == 1
|
63
|
+
end
|
64
|
+
|
65
|
+
def open_index
|
66
|
+
FileUtils.mkdir_p(Isomorfeus.data_object_idx_path) unless Dir.exist?(Isomorfeus.data_object_idx_path)
|
67
|
+
@index = Isomorfeus::Ferret::Index::Index.new(path: Isomorfeus.data_object_idx_path, key: :sid_s_attr, auto_flush: true, lock_retry_time: 5)
|
68
|
+
@index.field_infos.add_field(:attribute, store: :no, term_vector: :no) unless index.field_infos[:attribute]
|
69
|
+
@index.field_infos.add_field(:class_name, store: :no, term_vector: :no) unless index.field_infos[:class_name]
|
70
|
+
@index.field_infos.add_field(:value, store: :no) unless index.field_infos[:value]
|
71
|
+
@index.field_infos.add_field(:sid_s_attr, store: :yes, term_vector: :no) unless index.field_infos[:sid_s_attr]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/isomorfeus-data.rb
CHANGED
@@ -23,11 +23,11 @@ else
|
|
23
23
|
require 'active_support/core_ext/hash'
|
24
24
|
|
25
25
|
require 'isomorfeus-ferret'
|
26
|
-
require 'isomorfeus/data/
|
26
|
+
require 'isomorfeus/data/document_accelerator'
|
27
27
|
|
28
28
|
require 'isomorfeus-hamster'
|
29
|
-
require 'isomorfeus/data/
|
30
|
-
require 'isomorfeus/data/
|
29
|
+
require 'isomorfeus/data/object_expander'
|
30
|
+
require 'isomorfeus/data/object_accelerator'
|
31
31
|
|
32
32
|
require 'isomorfeus_data/lucid_query_result'
|
33
33
|
require 'isomorfeus_data/lucid_object/mixin'
|
@@ -92,9 +92,9 @@ module LucidDocument
|
|
92
92
|
def ferret_accelerator
|
93
93
|
return @ferret_accelerator if @ferret_accelerator
|
94
94
|
@ferret_accelerator = if @_setup_index_block
|
95
|
-
Isomorfeus::Data::
|
95
|
+
Isomorfeus::Data::DocumentAccelerator.new(self, &@_setup_index_block)
|
96
96
|
else
|
97
|
-
Isomorfeus::Data::
|
97
|
+
Isomorfeus::Data::DocumentAccelerator.new(self)
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
@@ -90,18 +90,18 @@ module LucidObject
|
|
90
90
|
def hamster_storage_expander
|
91
91
|
return @hamster_storage_expander if @hamster_storage_expander
|
92
92
|
@hamster_storage_expander = if @_setup_environment_block
|
93
|
-
Isomorfeus::Data::
|
93
|
+
Isomorfeus::Data::ObjectExpander.new(&@_setup_index_block)
|
94
94
|
else
|
95
|
-
Isomorfeus::Data::
|
95
|
+
Isomorfeus::Data::ObjectExpander.new
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
99
|
def hamster_accelerator
|
100
100
|
return @hamster_accelerator if @hamster_accelerator
|
101
101
|
@hamster_accelerator = if @_setup_index_block
|
102
|
-
Isomorfeus::Data::
|
102
|
+
Isomorfeus::Data::ObjectAccelerator.new(&@_setup_index_block)
|
103
103
|
else
|
104
|
-
Isomorfeus::Data::
|
104
|
+
Isomorfeus::Data::ObjectAccelerator.new
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
@@ -113,7 +113,7 @@ module LucidObject
|
|
113
113
|
query = "+value:#{val} +class_name:#{self.name}"
|
114
114
|
query << " +attribute:#{attr}" if attr != '*'
|
115
115
|
self.hamster_accelerator.search_each(query, options) do |id|
|
116
|
-
doc = self.hamster_accelerator.
|
116
|
+
doc = self.hamster_accelerator.index.doc(id)&.load
|
117
117
|
if doc
|
118
118
|
sid_s = doc[:sid_s_attr].split(':|:')[0]
|
119
119
|
obj = self.load(key: sid_s)
|
@@ -145,7 +145,7 @@ module LucidObject
|
|
145
145
|
self.class.hamster_storage_expander.create_object(self.sid_s, self)
|
146
146
|
self.class.indexed_attributes.each do |attr, idx_type|
|
147
147
|
if idx_type == :text
|
148
|
-
self.
|
148
|
+
self._create_text_indexed_attribute(attr)
|
149
149
|
else
|
150
150
|
self._store_value_indexed_attribute(attr)
|
151
151
|
end
|
@@ -200,6 +200,11 @@ module LucidObject
|
|
200
200
|
@_raw_attributes = attributes
|
201
201
|
end
|
202
202
|
|
203
|
+
def _create_text_indexed_attribute(attr)
|
204
|
+
doc = { sid_s_attr: "#{self.sid_s}:|:[#{attr}]", value: self.send(attr).to_s, attribute: attr.to_s, class_name: @class_name }
|
205
|
+
self.class.hamster_accelerator.create_doc(doc)
|
206
|
+
end
|
207
|
+
|
203
208
|
def _store_text_indexed_attribute(attr)
|
204
209
|
doc = { sid_s_attr: "#{self.sid_s}:|:[#{attr}]", value: self.send(attr).to_s, attribute: attr.to_s, class_name: @class_name }
|
205
210
|
self.class.hamster_accelerator.save_doc("#{self.sid_s}:|:[#{attr}]", doc)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: isomorfeus-data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.20
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Biedermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-02-
|
11
|
+
date: 2022-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -100,14 +100,14 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 0.6.
|
103
|
+
version: 0.6.3
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 0.6.
|
110
|
+
version: 0.6.3
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: isomorfeus-preact
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,28 +142,28 @@ dependencies:
|
|
142
142
|
requirements:
|
143
143
|
- - '='
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: 2.0.
|
145
|
+
version: 2.0.20
|
146
146
|
type: :runtime
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - '='
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: 2.0.
|
152
|
+
version: 2.0.20
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: isomorfeus
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
157
|
- - '='
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: 2.0.
|
159
|
+
version: 2.0.20
|
160
160
|
type: :development
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - '='
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: 2.0.
|
166
|
+
version: 2.0.20
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: rake
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -207,13 +207,13 @@ files:
|
|
207
207
|
- lib/isomorfeus-data.rb
|
208
208
|
- lib/isomorfeus/data/attribute_support.rb
|
209
209
|
- lib/isomorfeus/data/config.rb
|
210
|
-
- lib/isomorfeus/data/
|
210
|
+
- lib/isomorfeus/data/document_accelerator.rb
|
211
211
|
- lib/isomorfeus/data/field_support.rb
|
212
212
|
- lib/isomorfeus/data/generic_class_api.rb
|
213
213
|
- lib/isomorfeus/data/generic_instance_api.rb
|
214
|
-
- lib/isomorfeus/data/hamster_accelerator.rb
|
215
|
-
- lib/isomorfeus/data/hamster_storage_expander.rb
|
216
214
|
- lib/isomorfeus/data/handler/generic.rb
|
215
|
+
- lib/isomorfeus/data/object_accelerator.rb
|
216
|
+
- lib/isomorfeus/data/object_expander.rb
|
217
217
|
- lib/isomorfeus/data/reducer.rb
|
218
218
|
- lib/isomorfeus/data/version.rb
|
219
219
|
- lib/isomorfeus_data/lucid_document/base.rb
|
@@ -1,87 +0,0 @@
|
|
1
|
-
module Isomorfeus
|
2
|
-
module Data
|
3
|
-
class HamsterAccelerator
|
4
|
-
class << self
|
5
|
-
def index
|
6
|
-
@index
|
7
|
-
end
|
8
|
-
|
9
|
-
def index=(idx)
|
10
|
-
@index = idx
|
11
|
-
end
|
12
|
-
|
13
|
-
def ref
|
14
|
-
@ref ||= 0
|
15
|
-
end
|
16
|
-
|
17
|
-
def ref=(val)
|
18
|
-
@ref = val
|
19
|
-
end
|
20
|
-
|
21
|
-
def refa
|
22
|
-
self.ref += 1
|
23
|
-
end
|
24
|
-
|
25
|
-
def refs
|
26
|
-
self.ref -= 1 if self.ref > 0
|
27
|
-
end
|
28
|
-
|
29
|
-
def finalize(cls)
|
30
|
-
proc do
|
31
|
-
cls.refs
|
32
|
-
cls.index.close if cls.ref == 0
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def initialize(&block)
|
38
|
-
if block_given?
|
39
|
-
res = block.call(self)
|
40
|
-
self.class.index = res unless self.class.index
|
41
|
-
else
|
42
|
-
open_index
|
43
|
-
end
|
44
|
-
ObjectSpace.define_finalizer(self, self.class.finalize(self.class))
|
45
|
-
end
|
46
|
-
|
47
|
-
def destroy_index
|
48
|
-
close_index
|
49
|
-
FileUtils.rm_rf(Isomorfeus.data_object_idx_path)
|
50
|
-
end
|
51
|
-
|
52
|
-
def destroy_doc(id)
|
53
|
-
self.class.index.delete(id)
|
54
|
-
true
|
55
|
-
end
|
56
|
-
|
57
|
-
def load_doc(id)
|
58
|
-
self.class.index.doc(id)&.load
|
59
|
-
end
|
60
|
-
|
61
|
-
def save_doc(id, document)
|
62
|
-
self.class.index.update(id, document)
|
63
|
-
end
|
64
|
-
|
65
|
-
def search_each(query, options, &block)
|
66
|
-
self.class.index.search_each(query, options, &block)
|
67
|
-
end
|
68
|
-
|
69
|
-
private
|
70
|
-
|
71
|
-
def open_index
|
72
|
-
return self.class.refa if self.class.index
|
73
|
-
unless Dir.exist?(Isomorfeus.data_object_idx_path)
|
74
|
-
FileUtils.mkdir_p(Isomorfeus.data_object_idx_path)
|
75
|
-
fis = Isomorfeus::Ferret::Index::FieldInfos.new
|
76
|
-
fis.add_field(:attribute, store: :no)
|
77
|
-
fis.add_field(:class_name, store: :no)
|
78
|
-
fis.add_field(:value, store: :no)
|
79
|
-
fis.add_field(:sid_s_attr, store: :yes)
|
80
|
-
fis.create_index(Isomorfeus.data_object_idx_path)
|
81
|
-
end
|
82
|
-
self.class.index = Isomorfeus::Ferret::Index::Index.new(path: Isomorfeus.data_object_idx_path, id_field: :sid_s_attr)
|
83
|
-
self.class.refa
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|