isomorfeus-data 2.0.19 → 2.1.0
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/README.md +1 -1
- data/lib/isomorfeus/data/config.rb +9 -9
- data/lib/isomorfeus/data/{ferret_accelerator.rb → document_accelerator.rb} +5 -9
- data/lib/isomorfeus/data/handler/generic.rb +22 -22
- data/lib/isomorfeus/data/object_accelerator.rb +76 -0
- data/lib/isomorfeus/data/{hamster_storage_expander.rb → object_expander.rb} +13 -41
- data/lib/isomorfeus/data/reducer.rb +1 -1
- data/lib/isomorfeus/data/version.rb +1 -1
- data/lib/isomorfeus-data.rb +5 -3
- data/lib/isomorfeus_data/lucid_document/mixin.rb +10 -2
- data/lib/isomorfeus_data/lucid_file/mixin.rb +8 -0
- data/lib/isomorfeus_data/lucid_object/mixin.rb +42 -29
- data/lib/isomorfeus_data/lucid_query/mixin.rb +2 -1
- metadata +53 -25
- 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: 336c73e455b2044f1b96dc1a1e2e7a7b9ca0ef962f9121dcd9df9d0e1bea02bb
|
|
4
|
+
data.tar.gz: 36cd08025344752f7bcac649aabc6e26ecfa85dd00da2135ab4e43f10b3b47e0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e97477903e581484d03c93712871671ed56d864f1c7db9379e758c3229913db7c8b08ed8ac33a127ecaf500590f31fbcffcab7cbce7ed97f37c8eb64bab2879b
|
|
7
|
+
data.tar.gz: 05c46807e85b6403e47b34359fb90cb71f0c8b0b14ddb03973891e985cc83f310544a58f78f85204e462ff41c4a1f8114e2b36e0de0631b024e0b6dcab167f79
|
data/README.md
CHANGED
|
@@ -56,7 +56,7 @@ module Isomorfeus
|
|
|
56
56
|
valid_file_classes[raw_class_name(klass)] = true
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
-
attr_accessor :
|
|
59
|
+
attr_accessor :storage_path
|
|
60
60
|
attr_accessor :files_path
|
|
61
61
|
|
|
62
62
|
attr_accessor :ferret_path
|
|
@@ -64,23 +64,23 @@ module Isomorfeus
|
|
|
64
64
|
|
|
65
65
|
attr_accessor :hamster_path
|
|
66
66
|
attr_accessor :hamster_mapsize
|
|
67
|
-
attr_accessor :
|
|
68
|
-
attr_accessor :
|
|
67
|
+
attr_accessor :data_object_envs_path
|
|
68
|
+
attr_accessor :data_object_idxs_path
|
|
69
69
|
end
|
|
70
70
|
end
|
|
71
71
|
|
|
72
72
|
if RUBY_ENGINE != 'opal'
|
|
73
|
-
self.
|
|
74
|
-
self.files_path = File.expand_path(File.join(self.
|
|
73
|
+
self.storage_path = File.expand_path(File.join(Isomorfeus.root, 'storage', Isomorfeus.env))
|
|
74
|
+
self.files_path = File.expand_path(File.join(self.storage_path, 'files'))
|
|
75
75
|
|
|
76
76
|
# documents and indices
|
|
77
|
-
self.ferret_path = File.expand_path(File.join(self.
|
|
77
|
+
self.ferret_path = File.expand_path(File.join(self.storage_path, 'ferret'))
|
|
78
78
|
self.data_documents_path = File.expand_path(File.join(self.ferret_path, 'documents'))
|
|
79
79
|
|
|
80
80
|
# objects, nodes and edges
|
|
81
|
-
self.hamster_path = File.expand_path(File.join(self.
|
|
81
|
+
self.hamster_path = File.expand_path(File.join(self.storage_path, 'hamster'))
|
|
82
82
|
self.hamster_mapsize = 4294967296
|
|
83
|
-
self.
|
|
84
|
-
self.
|
|
83
|
+
self.data_object_envs_path = File.expand_path(File.join(self.hamster_path, 'object_envs'))
|
|
84
|
+
self.data_object_idxs_path = File.expand_path(File.join(self.hamster_path, 'object_idxs'))
|
|
85
85
|
end
|
|
86
86
|
end
|
|
@@ -1,21 +1,21 @@
|
|
|
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
|
|
7
7
|
|
|
8
|
-
attr_reader :doc_class, :doc_class_name
|
|
8
|
+
attr_reader :doc_class, :doc_class_name
|
|
9
9
|
attr_accessor :index
|
|
10
10
|
|
|
11
11
|
def initialize(doc_class, &block)
|
|
12
12
|
@doc_class = doc_class
|
|
13
13
|
@doc_class_name = doc_class.name
|
|
14
|
-
@doc_class_name_u = @doc_class_name.underscore
|
|
15
14
|
if block_given?
|
|
16
15
|
res = block.call(self)
|
|
17
16
|
@index = res unless @index
|
|
18
17
|
else
|
|
18
|
+
@index_path = File.expand_path(File.join(Isomorfeus.data_documents_path, @doc_class_name.underscore))
|
|
19
19
|
open_index
|
|
20
20
|
end
|
|
21
21
|
ObjectSpace.define_finalizer(self, self.class.finalize(self))
|
|
@@ -23,7 +23,7 @@ module Isomorfeus
|
|
|
23
23
|
|
|
24
24
|
def destroy_index
|
|
25
25
|
close_index
|
|
26
|
-
FileUtils.rm_rf(index_path
|
|
26
|
+
FileUtils.rm_rf(@index_path)
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def close_index
|
|
@@ -66,14 +66,10 @@ module Isomorfeus
|
|
|
66
66
|
id = top_docs.hits[0].doc if top_docs.total_hits == 1
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
-
def index_path
|
|
70
|
-
File.expand_path(File.join(Isomorfeus.data_documents_path, @doc_class_name_u))
|
|
71
|
-
end
|
|
72
|
-
|
|
73
69
|
def open_index
|
|
74
70
|
FileUtils.mkdir_p(Isomorfeus.data_documents_path) unless Dir.exist?(Isomorfeus.data_documents_path)
|
|
75
71
|
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)
|
|
72
|
+
@index = Isomorfeus::Ferret::Index::Index.new(path: @index_path, key: :key, auto_flush: true, lock_retry_time: 5, field_infos: field_infos)
|
|
77
73
|
@index.field_infos.add_field(:key, store: :yes, index: :yes, term_vector: :no) unless @index.field_infos[:key]
|
|
78
74
|
@doc_class.field_options.each do |field, options|
|
|
79
75
|
@index.field_infos.add_field(field, options) unless @index.field_infos[field]
|
|
@@ -19,7 +19,7 @@ module Isomorfeus
|
|
|
19
19
|
response_agent.request[type_class_name].each_key do |action|
|
|
20
20
|
case action
|
|
21
21
|
when 'load' then process_load(response_agent, type_class, type_class_name)
|
|
22
|
-
when '
|
|
22
|
+
when 'execute' then process_execute(response_agent, type_class, type_class_name)
|
|
23
23
|
when 'create' then process_create(response_agent, type_class, type_class_name)
|
|
24
24
|
when 'save' then process_save(response_agent, type_class, type_class_name)
|
|
25
25
|
when 'destroy' then process_destroy(response_agent, type_class, type_class_name)
|
|
@@ -40,7 +40,7 @@ module Isomorfeus
|
|
|
40
40
|
data = response_agent.request[type_class_name]['create']
|
|
41
41
|
instance_data = data['instance']
|
|
42
42
|
included_items_data = data.key?('included_items') ? data['included_items'] : nil
|
|
43
|
-
if Isomorfeus.current_user.authorized?(type_class, :create,
|
|
43
|
+
if Isomorfeus.current_user.authorized?(type_class, :create, type_class.props_from_data(instance_data))
|
|
44
44
|
instance = type_class.instance_from_transport(instance_data, included_items_data)
|
|
45
45
|
created_type = instance.create
|
|
46
46
|
if created_type
|
|
@@ -56,6 +56,25 @@ module Isomorfeus
|
|
|
56
56
|
end
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
+
def process_execute(response_agent, type_class, type_class_name)
|
|
60
|
+
# 'Isomorfeus::Data::Handler::Generic', self.name, :execute, props_json
|
|
61
|
+
props = response_agent.request[type_class_name]['execute']
|
|
62
|
+
props.transform_keys!(&:to_sym)
|
|
63
|
+
if Isomorfeus.current_user.authorized?(type_class, :execute, props)
|
|
64
|
+
queried_type = type_class.execute(**props)
|
|
65
|
+
if queried_type
|
|
66
|
+
response_agent.outer_result = {} unless response_agent.outer_result
|
|
67
|
+
response_agent.outer_result.deep_merge!(data: queried_type.to_transport)
|
|
68
|
+
if queried_type.respond_to?(:included_items_to_transport)
|
|
69
|
+
response_agent.outer_result.deep_merge!(data: queried_type.included_items_to_transport)
|
|
70
|
+
end
|
|
71
|
+
response_agent.agent_result = { success: 'ok' }
|
|
72
|
+
else response_agent.error = { error: { type_class_name => 'Query returned nothing!' }}
|
|
73
|
+
end
|
|
74
|
+
else response_agent.error = { error: 'Access denied!' }
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
59
78
|
def process_load(response_agent, type_class, type_class_name)
|
|
60
79
|
# 'Isomorfeus::Data::Handler::Generic', self.name, :load, key: key
|
|
61
80
|
props = response_agent.request[type_class_name]['load']
|
|
@@ -75,31 +94,12 @@ module Isomorfeus
|
|
|
75
94
|
end
|
|
76
95
|
end
|
|
77
96
|
|
|
78
|
-
def process_query(response_agent, type_class, type_class_name)
|
|
79
|
-
# 'Isomorfeus::Data::Handler::Generic', self.name, :query, props_json
|
|
80
|
-
props = response_agent.request[type_class_name]['query']
|
|
81
|
-
props.transform_keys!(&:to_sym)
|
|
82
|
-
if Isomorfeus.current_user.authorized?(type_class, :query, props)
|
|
83
|
-
queried_type = type_class.execute(**props)
|
|
84
|
-
if queried_type
|
|
85
|
-
response_agent.outer_result = {} unless response_agent.outer_result
|
|
86
|
-
response_agent.outer_result.deep_merge!(data: queried_type.to_transport)
|
|
87
|
-
if queried_type.respond_to?(:included_items_to_transport)
|
|
88
|
-
response_agent.outer_result.deep_merge!(data: queried_type.included_items_to_transport)
|
|
89
|
-
end
|
|
90
|
-
response_agent.agent_result = { success: 'ok' }
|
|
91
|
-
else response_agent.error = { error: { type_class_name => 'Query returned nothing!' }}
|
|
92
|
-
end
|
|
93
|
-
else response_agent.error = { error: 'Access denied!' }
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
|
|
97
97
|
def process_save(response_agent, type_class, type_class_name)
|
|
98
98
|
# 'Isomorfeus::Data::Handler::Generic', self.name, :save, data_hash
|
|
99
99
|
data = response_agent.request[type_class_name]['save']
|
|
100
100
|
instance_data = data['instance']
|
|
101
101
|
included_items_data = data.key?('included_items') ? data['included_items'] : nil
|
|
102
|
-
if Isomorfeus.current_user.authorized?(type_class, :save,
|
|
102
|
+
if Isomorfeus.current_user.authorized?(type_class, :save, type_class.props_from_data(instance_data))
|
|
103
103
|
instance = type_class.instance_from_transport(instance_data, included_items_data)
|
|
104
104
|
saved_type = instance.save
|
|
105
105
|
if saved_type
|
|
@@ -0,0 +1,76 @@
|
|
|
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(object_class_name, &block)
|
|
11
|
+
if block_given?
|
|
12
|
+
res = block.call(self)
|
|
13
|
+
@index = res unless @index
|
|
14
|
+
else
|
|
15
|
+
@index_path = File.expand_path(File.join(Isomorfeus.data_object_idxs_path, object_class_name.underscore))
|
|
16
|
+
open_index
|
|
17
|
+
end
|
|
18
|
+
ObjectSpace.define_finalizer(self, self.class.finalize(self))
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def destroy_index
|
|
22
|
+
close_index
|
|
23
|
+
FileUtils.rm_rf(@index_path)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def close_index
|
|
27
|
+
@index.close
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def create_doc(document)
|
|
31
|
+
@index.add_document(document)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def destroy_doc(key)
|
|
35
|
+
id = get_doc_id(key)
|
|
36
|
+
@index.delete(id) if id
|
|
37
|
+
true
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def load_doc(key)
|
|
41
|
+
id = get_doc_id(key)
|
|
42
|
+
@index.doc(id)&.load&.to_h if id
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def save_doc(key, document)
|
|
46
|
+
id = get_doc_id(key)
|
|
47
|
+
if id
|
|
48
|
+
@index.update(id, document)
|
|
49
|
+
true
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def search_each(query, options, &block)
|
|
54
|
+
@index.search_each(query, options, &block)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
private
|
|
58
|
+
|
|
59
|
+
def get_doc_id(key)
|
|
60
|
+
# special characters must be escaped, characters taken from the ferret query parser documentation
|
|
61
|
+
escaped_key = key.gsub(/([\\\&\:\(\)\[\]\{\}\!\"\~\^\|\<\>\=\*\?\+\-\s])/, '\\\\\1')
|
|
62
|
+
top_docs = @index.search("sid_s_attr:\"#{escaped_key}\"", limit: 1)
|
|
63
|
+
id = top_docs.hits[0].doc if top_docs.total_hits == 1
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def open_index
|
|
67
|
+
FileUtils.mkdir_p(@index_path) unless Dir.exist?(@index_path)
|
|
68
|
+
@index = Isomorfeus::Ferret::Index::Index.new(path: @index_path, key: :sid_s_attr, auto_flush: true, lock_retry_time: 5)
|
|
69
|
+
@index.field_infos.add_field(:attribute, store: :no, term_vector: :no) unless @index.field_infos[:attribute]
|
|
70
|
+
@index.field_infos.add_field(:class_name, store: :no, term_vector: :no) unless @index.field_infos[:class_name]
|
|
71
|
+
@index.field_infos.add_field(:value, store: :no) unless @index.field_infos[:value]
|
|
72
|
+
@index.field_infos.add_field(:sid_s_attr, store: :yes, term_vector: :no) unless @index.field_infos[:sid_s_attr]
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -1,52 +1,26 @@
|
|
|
1
1
|
module Isomorfeus
|
|
2
2
|
module Data
|
|
3
|
-
class
|
|
3
|
+
class ObjectExpander
|
|
4
4
|
class << self
|
|
5
|
-
def
|
|
6
|
-
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def environment=(env)
|
|
10
|
-
@environment = env
|
|
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
|
-
if cls.ref == 0
|
|
33
|
-
cls.environment.close rescue nil
|
|
34
|
-
end
|
|
35
|
-
end
|
|
5
|
+
def finalize(ins)
|
|
6
|
+
proc { ins.environment.close rescue nil }
|
|
36
7
|
end
|
|
37
8
|
end
|
|
38
9
|
|
|
39
|
-
|
|
10
|
+
attr_accessor :environment
|
|
11
|
+
|
|
12
|
+
def initialize(object_class_name, &block)
|
|
40
13
|
if block_given?
|
|
41
14
|
res = block.call(self)
|
|
42
|
-
self.
|
|
15
|
+
self.environment = res unless self.environment
|
|
43
16
|
else
|
|
17
|
+
@env_path = File.expand_path(File.join(Isomorfeus.data_object_envs_path, object_class_name.underscore))
|
|
44
18
|
open_environment
|
|
45
19
|
end
|
|
46
|
-
@db = self.
|
|
47
|
-
@index_db = self.
|
|
20
|
+
@db = self.environment.database('objects', create: true)
|
|
21
|
+
@index_db = self.environment.database('index', create: true, dupsort: true)
|
|
48
22
|
@use_class_cache = !Isomorfeus.development?
|
|
49
|
-
ObjectSpace.define_finalizer(self, self.class.finalize(self
|
|
23
|
+
ObjectSpace.define_finalizer(self, self.class.finalize(self))
|
|
50
24
|
end
|
|
51
25
|
|
|
52
26
|
def create_object(sid_s, obj)
|
|
@@ -91,10 +65,8 @@ module Isomorfeus
|
|
|
91
65
|
private
|
|
92
66
|
|
|
93
67
|
def open_environment
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
self.class.environment = Isomorfeus::Hamster.new(Isomorfeus.data_object_env_path, mapsize: Isomorfeus.hamster_mapsize)
|
|
97
|
-
self.class.refa
|
|
68
|
+
FileUtils.mkdir_p(@env_path) unless Dir.exist?(@env_path)
|
|
69
|
+
self.environment = Isomorfeus::Hamster.new(@env_path, mapsize: Isomorfeus.hamster_mapsize)
|
|
98
70
|
end
|
|
99
71
|
end
|
|
100
72
|
end
|
data/lib/isomorfeus-data.rb
CHANGED
|
@@ -2,7 +2,9 @@ require 'base64'
|
|
|
2
2
|
require 'stringio'
|
|
3
3
|
require 'data_uri'
|
|
4
4
|
require 'securerandom'
|
|
5
|
+
require 'isomorfeus-policy'
|
|
5
6
|
require 'isomorfeus-transport'
|
|
7
|
+
require 'isomorfeus-i18n'
|
|
6
8
|
require 'isomorfeus/data/config'
|
|
7
9
|
require 'isomorfeus/data/attribute_support'
|
|
8
10
|
require 'isomorfeus/data/field_support'
|
|
@@ -23,11 +25,11 @@ else
|
|
|
23
25
|
require 'active_support/core_ext/hash'
|
|
24
26
|
|
|
25
27
|
require 'isomorfeus-ferret'
|
|
26
|
-
require 'isomorfeus/data/
|
|
28
|
+
require 'isomorfeus/data/document_accelerator'
|
|
27
29
|
|
|
28
30
|
require 'isomorfeus-hamster'
|
|
29
|
-
require 'isomorfeus/data/
|
|
30
|
-
require 'isomorfeus/data/
|
|
31
|
+
require 'isomorfeus/data/object_expander'
|
|
32
|
+
require 'isomorfeus/data/object_accelerator'
|
|
31
33
|
|
|
32
34
|
require 'isomorfeus_data/lucid_query_result'
|
|
33
35
|
require 'isomorfeus_data/lucid_object/mixin'
|
|
@@ -4,6 +4,7 @@ module LucidDocument
|
|
|
4
4
|
base.include(Isomorfeus::Data::FieldSupport)
|
|
5
5
|
base.extend(Isomorfeus::Data::GenericClassApi)
|
|
6
6
|
base.include(Isomorfeus::Data::GenericInstanceApi)
|
|
7
|
+
base.include(LucidI18n::Mixin)
|
|
7
8
|
|
|
8
9
|
base.instance_exec do
|
|
9
10
|
def escape_string(s)
|
|
@@ -85,6 +86,13 @@ module LucidDocument
|
|
|
85
86
|
new(key: key, revision: revision, fields: fields)
|
|
86
87
|
end
|
|
87
88
|
|
|
89
|
+
def props_from_data(instance_data)
|
|
90
|
+
key = instance_data[self.name].keys.first
|
|
91
|
+
revision = instance_data[self.name][key].key?('revision') ? instance_data[self.name][key]['revision'] : nil
|
|
92
|
+
fields = instance_data[self.name][key].key?('fields') ? instance_data[self.name][key]['fields'].transform_keys!(&:to_sym) : nil
|
|
93
|
+
LucidProps.new({ key: key, revision: revision }.merge!(fields))
|
|
94
|
+
end
|
|
95
|
+
|
|
88
96
|
def setup_index(&block)
|
|
89
97
|
@_setup_index_block = block
|
|
90
98
|
end
|
|
@@ -92,9 +100,9 @@ module LucidDocument
|
|
|
92
100
|
def ferret_accelerator
|
|
93
101
|
return @ferret_accelerator if @ferret_accelerator
|
|
94
102
|
@ferret_accelerator = if @_setup_index_block
|
|
95
|
-
Isomorfeus::Data::
|
|
103
|
+
Isomorfeus::Data::DocumentAccelerator.new(self, &@_setup_index_block)
|
|
96
104
|
else
|
|
97
|
-
Isomorfeus::Data::
|
|
105
|
+
Isomorfeus::Data::DocumentAccelerator.new(self)
|
|
98
106
|
end
|
|
99
107
|
end
|
|
100
108
|
|
|
@@ -3,6 +3,7 @@ module LucidFile
|
|
|
3
3
|
def self.included(base)
|
|
4
4
|
base.extend(Isomorfeus::Data::GenericClassApi)
|
|
5
5
|
base.include(Isomorfeus::Data::GenericInstanceApi)
|
|
6
|
+
base.include(LucidI18n::Mixin)
|
|
6
7
|
|
|
7
8
|
def changed!
|
|
8
9
|
@_changed = true
|
|
@@ -140,6 +141,13 @@ module LucidFile
|
|
|
140
141
|
new(key: key, revision: revision, data_uri: data_uri)
|
|
141
142
|
end
|
|
142
143
|
|
|
144
|
+
def props_from_data(instance_data)
|
|
145
|
+
key = instance_data[self.name].keys.first
|
|
146
|
+
revision = instance_data[self.name][key].key?('revision') ? instance_data[self.name][key]['revision'] : nil
|
|
147
|
+
data_uri = instance_data[self.name][key].key?('data_uri') ? instance_data[self.name][key]['data_uri'] : nil
|
|
148
|
+
LucidProps.new({ key: key, revision: revision, data_uri: data_uri })
|
|
149
|
+
end
|
|
150
|
+
|
|
143
151
|
def files_path
|
|
144
152
|
@files_path ||= Isomorfeus.files_path
|
|
145
153
|
end
|
|
@@ -4,6 +4,7 @@ module LucidObject
|
|
|
4
4
|
base.include(Isomorfeus::Data::AttributeSupport)
|
|
5
5
|
base.extend(Isomorfeus::Data::GenericClassApi)
|
|
6
6
|
base.include(Isomorfeus::Data::GenericInstanceApi)
|
|
7
|
+
base.include(LucidI18n::Mixin)
|
|
7
8
|
|
|
8
9
|
def [](name)
|
|
9
10
|
send(name)
|
|
@@ -79,6 +80,13 @@ module LucidObject
|
|
|
79
80
|
new(key: key, revision: revision, attributes: attributes)
|
|
80
81
|
end
|
|
81
82
|
|
|
83
|
+
def props_from_data(instance_data)
|
|
84
|
+
key = instance_data[self.name].keys.first
|
|
85
|
+
revision = instance_data[self.name][key].key?('revision') ? instance_data[self.name][key]['revision'] : nil
|
|
86
|
+
attributes = instance_data[self.name][key].key?('attributes') ? instance_data[self.name][key]['attributes'].transform_keys!(&:to_sym) : nil
|
|
87
|
+
LucidProps.new({ key: key, revision: revision }.merge!(attributes))
|
|
88
|
+
end
|
|
89
|
+
|
|
82
90
|
def setup_environment(&block)
|
|
83
91
|
@_setup_environment_block = block
|
|
84
92
|
end
|
|
@@ -87,21 +95,21 @@ module LucidObject
|
|
|
87
95
|
@_setup_index_block = block
|
|
88
96
|
end
|
|
89
97
|
|
|
90
|
-
def
|
|
91
|
-
return @
|
|
92
|
-
@
|
|
93
|
-
Isomorfeus::Data::
|
|
98
|
+
def object_expander
|
|
99
|
+
return @object_expander if @object_expander
|
|
100
|
+
@object_expander = if @_setup_environment_block
|
|
101
|
+
Isomorfeus::Data::ObjectExpander.new(self.to_s, &@_setup_index_block)
|
|
94
102
|
else
|
|
95
|
-
Isomorfeus::Data::
|
|
103
|
+
Isomorfeus::Data::ObjectExpander.new(self.to_s)
|
|
96
104
|
end
|
|
97
105
|
end
|
|
98
106
|
|
|
99
|
-
def
|
|
100
|
-
return @
|
|
101
|
-
@
|
|
102
|
-
Isomorfeus::Data::
|
|
107
|
+
def object_accelerator
|
|
108
|
+
return @object_accelerator if @object_accelerator
|
|
109
|
+
@object_accelerator = if @_setup_index_block
|
|
110
|
+
Isomorfeus::Data::ObjectAccelerator.new(self.to_s, &@_setup_index_block)
|
|
103
111
|
else
|
|
104
|
-
Isomorfeus::Data::
|
|
112
|
+
Isomorfeus::Data::ObjectAccelerator.new(self.to_s)
|
|
105
113
|
end
|
|
106
114
|
end
|
|
107
115
|
|
|
@@ -112,8 +120,8 @@ module LucidObject
|
|
|
112
120
|
if idx_type == :text
|
|
113
121
|
query = "+value:#{val} +class_name:#{self.name}"
|
|
114
122
|
query << " +attribute:#{attr}" if attr != '*'
|
|
115
|
-
self.
|
|
116
|
-
doc = self.
|
|
123
|
+
self.object_accelerator.search_each(query, options) do |id|
|
|
124
|
+
doc = self.object_accelerator.index.doc(id)&.load
|
|
117
125
|
if doc
|
|
118
126
|
sid_s = doc[:sid_s_attr].split(':|:')[0]
|
|
119
127
|
obj = self.load(key: sid_s)
|
|
@@ -122,13 +130,13 @@ module LucidObject
|
|
|
122
130
|
end
|
|
123
131
|
else
|
|
124
132
|
if val == '*'
|
|
125
|
-
self.
|
|
133
|
+
self.object_expander.each do |obj|
|
|
126
134
|
objs << obj if obj.class == self
|
|
127
135
|
end
|
|
128
136
|
else
|
|
129
137
|
attr_s = ":[#{attr}]"
|
|
130
138
|
accept_all_attr = attr_s == ":[*]" ? true : false
|
|
131
|
-
self.
|
|
139
|
+
self.object_expander.search(":[#{self.name}]:|:[:#{val}:]:") do |sid_s_attr|
|
|
132
140
|
if accept_all_attr || sid_s_attr.end_with?(attr_s)
|
|
133
141
|
sid_s = sid_s_attr.split(':|:[')[0]
|
|
134
142
|
obj = self.load(key: sid_s)
|
|
@@ -142,10 +150,10 @@ module LucidObject
|
|
|
142
150
|
|
|
143
151
|
execute_create do
|
|
144
152
|
self.key = SecureRandom.uuid unless self.key
|
|
145
|
-
self.class.
|
|
153
|
+
self.class.object_expander.create_object(self.sid_s, self)
|
|
146
154
|
self.class.indexed_attributes.each do |attr, idx_type|
|
|
147
155
|
if idx_type == :text
|
|
148
|
-
self.
|
|
156
|
+
self._create_text_indexed_attribute(attr)
|
|
149
157
|
else
|
|
150
158
|
self._store_value_indexed_attribute(attr)
|
|
151
159
|
end
|
|
@@ -156,14 +164,14 @@ module LucidObject
|
|
|
156
164
|
execute_destroy do |key:|
|
|
157
165
|
key = key.to_s
|
|
158
166
|
sid_s = key.start_with?('[') ? key : gen_sid_s(key)
|
|
159
|
-
self.
|
|
167
|
+
self.object_expander.destroy_object(sid_s)
|
|
160
168
|
self.indexed_attributes.each do |attr, idx_type|
|
|
161
169
|
if idx_type == :text
|
|
162
|
-
self.
|
|
170
|
+
self.object_accelerator.destroy_doc("#{sid_s}:|:[#{attr}]")
|
|
163
171
|
else
|
|
164
|
-
old_val = self.
|
|
165
|
-
self.
|
|
166
|
-
self.
|
|
172
|
+
old_val = self.object_expander.index_get("#{sid_s}:|:[#{attr}]")
|
|
173
|
+
self.object_expander.index_delete("#{sid_s}:|:[#{attr}]", old_val)
|
|
174
|
+
self.object_expander.index_delete(":[#{self.name}]:|:[:#{old_val}:]:", "#{sid_s}:|:[#{attr}]")
|
|
167
175
|
end
|
|
168
176
|
end
|
|
169
177
|
true
|
|
@@ -172,12 +180,12 @@ module LucidObject
|
|
|
172
180
|
execute_load do |key:|
|
|
173
181
|
key = key.to_s
|
|
174
182
|
sid_s = key.start_with?('[') ? key : gen_sid_s(key)
|
|
175
|
-
self.
|
|
183
|
+
self.object_expander.load_object(sid_s)
|
|
176
184
|
end
|
|
177
185
|
|
|
178
186
|
execute_save do
|
|
179
187
|
self.key = SecureRandom.uuid unless self.key
|
|
180
|
-
self.class.
|
|
188
|
+
self.class.object_expander.save_object(self.sid_s, self)
|
|
181
189
|
self.class.indexed_attributes.each do |attr, val|
|
|
182
190
|
if val == :text
|
|
183
191
|
self._store_text_indexed_attribute(attr)
|
|
@@ -200,18 +208,23 @@ module LucidObject
|
|
|
200
208
|
@_raw_attributes = attributes
|
|
201
209
|
end
|
|
202
210
|
|
|
211
|
+
def _create_text_indexed_attribute(attr)
|
|
212
|
+
doc = { sid_s_attr: "#{self.sid_s}:|:[#{attr}]", value: self.send(attr).to_s, attribute: attr.to_s, class_name: @class_name }
|
|
213
|
+
self.class.object_accelerator.create_doc(doc)
|
|
214
|
+
end
|
|
215
|
+
|
|
203
216
|
def _store_text_indexed_attribute(attr)
|
|
204
217
|
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.
|
|
218
|
+
self.class.object_accelerator.save_doc("#{self.sid_s}:|:[#{attr}]", doc)
|
|
206
219
|
end
|
|
207
220
|
|
|
208
221
|
def _store_value_indexed_attribute(attr)
|
|
209
|
-
old_val = self.class.
|
|
210
|
-
self.class.
|
|
211
|
-
self.class.
|
|
222
|
+
old_val = self.class.object_expander.index_get("#{self.sid_s}:|:[#{attr}]")
|
|
223
|
+
self.class.object_expander.index_delete("#{self.sid_s}:|:[#{attr}]", old_val)
|
|
224
|
+
self.class.object_expander.index_delete(":[#{self.class.name}]:|:[:#{old_val}:]:", "#{self.sid_s}:|:[#{attr}]")
|
|
212
225
|
val = "#{self.send(attr)}"[0..300]
|
|
213
|
-
self.class.
|
|
214
|
-
self.class.
|
|
226
|
+
self.class.object_expander.index_put("#{self.sid_s}:|:[#{attr}]", val)
|
|
227
|
+
self.class.object_expander.index_put(":[#{self.class.name}]:|:[:#{val}:]:", "#{self.sid_s}:|:[#{attr}]")
|
|
215
228
|
end
|
|
216
229
|
|
|
217
230
|
def _unchange!
|
|
@@ -2,6 +2,7 @@ module LucidQuery
|
|
|
2
2
|
module Mixin
|
|
3
3
|
def self.included(base)
|
|
4
4
|
base.extend(LucidPropDeclaration::Mixin)
|
|
5
|
+
base.include(LucidI18n::Mixin)
|
|
5
6
|
|
|
6
7
|
if RUBY_ENGINE == 'opal'
|
|
7
8
|
base.instance_exec do
|
|
@@ -22,7 +23,7 @@ module LucidQuery
|
|
|
22
23
|
end
|
|
23
24
|
props = validated_props(props)
|
|
24
25
|
props[:key] = query_result_instance.key
|
|
25
|
-
Isomorfeus::Transport.promise_send_path( 'Isomorfeus::Data::Handler::Generic', self.name, :
|
|
26
|
+
Isomorfeus::Transport.promise_send_path( 'Isomorfeus::Data::Handler::Generic', self.name, :execute, props).then do |agent|
|
|
26
27
|
agent.process do
|
|
27
28
|
query_result_instance._load_from_store!
|
|
28
29
|
Isomorfeus.store.dispatch(type: 'DATA_LOAD', data: agent.full_response[:data])
|
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.1.0
|
|
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-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -16,14 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 7.0.
|
|
19
|
+
version: 7.0.2
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: 7.0.
|
|
26
|
+
version: 7.0.2
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: oj
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -72,98 +72,126 @@ dependencies:
|
|
|
72
72
|
requirements:
|
|
73
73
|
- - "~>"
|
|
74
74
|
- !ruby/object:Gem::Version
|
|
75
|
-
version: 0.14.
|
|
75
|
+
version: 0.14.10
|
|
76
76
|
type: :runtime
|
|
77
77
|
prerelease: false
|
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
|
79
79
|
requirements:
|
|
80
80
|
- - "~>"
|
|
81
81
|
- !ruby/object:Gem::Version
|
|
82
|
-
version: 0.14.
|
|
82
|
+
version: 0.14.10
|
|
83
83
|
- !ruby/object:Gem::Dependency
|
|
84
84
|
name: isomorfeus-ferret
|
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
|
86
86
|
requirements:
|
|
87
87
|
- - "~>"
|
|
88
88
|
- !ruby/object:Gem::Version
|
|
89
|
-
version: 0.12.
|
|
89
|
+
version: 0.12.6
|
|
90
90
|
type: :runtime
|
|
91
91
|
prerelease: false
|
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
93
|
requirements:
|
|
94
94
|
- - "~>"
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
|
-
version: 0.12.
|
|
96
|
+
version: 0.12.6
|
|
97
97
|
- !ruby/object:Gem::Dependency
|
|
98
98
|
name: isomorfeus-hamster
|
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
|
100
100
|
requirements:
|
|
101
101
|
- - "~>"
|
|
102
102
|
- !ruby/object:Gem::Version
|
|
103
|
-
version: 0.6.
|
|
103
|
+
version: 0.6.4
|
|
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.4
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: isomorfeus-i18n
|
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - '='
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: 2.1.0
|
|
118
|
+
type: :runtime
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - '='
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: 2.1.0
|
|
125
|
+
- !ruby/object:Gem::Dependency
|
|
126
|
+
name: isomorfeus-policy
|
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
|
128
|
+
requirements:
|
|
129
|
+
- - '='
|
|
130
|
+
- !ruby/object:Gem::Version
|
|
131
|
+
version: 2.1.0
|
|
132
|
+
type: :runtime
|
|
133
|
+
prerelease: false
|
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
135
|
+
requirements:
|
|
136
|
+
- - '='
|
|
137
|
+
- !ruby/object:Gem::Version
|
|
138
|
+
version: 2.1.0
|
|
111
139
|
- !ruby/object:Gem::Dependency
|
|
112
140
|
name: isomorfeus-preact
|
|
113
141
|
requirement: !ruby/object:Gem::Requirement
|
|
114
142
|
requirements:
|
|
115
143
|
- - "~>"
|
|
116
144
|
- !ruby/object:Gem::Version
|
|
117
|
-
version: 10.6.
|
|
145
|
+
version: 10.6.34
|
|
118
146
|
type: :runtime
|
|
119
147
|
prerelease: false
|
|
120
148
|
version_requirements: !ruby/object:Gem::Requirement
|
|
121
149
|
requirements:
|
|
122
150
|
- - "~>"
|
|
123
151
|
- !ruby/object:Gem::Version
|
|
124
|
-
version: 10.6.
|
|
152
|
+
version: 10.6.34
|
|
125
153
|
- !ruby/object:Gem::Dependency
|
|
126
154
|
name: isomorfeus-redux
|
|
127
155
|
requirement: !ruby/object:Gem::Requirement
|
|
128
156
|
requirements:
|
|
129
157
|
- - "~>"
|
|
130
158
|
- !ruby/object:Gem::Version
|
|
131
|
-
version: 4.1.
|
|
159
|
+
version: 4.1.15
|
|
132
160
|
type: :runtime
|
|
133
161
|
prerelease: false
|
|
134
162
|
version_requirements: !ruby/object:Gem::Requirement
|
|
135
163
|
requirements:
|
|
136
164
|
- - "~>"
|
|
137
165
|
- !ruby/object:Gem::Version
|
|
138
|
-
version: 4.1.
|
|
166
|
+
version: 4.1.15
|
|
139
167
|
- !ruby/object:Gem::Dependency
|
|
140
168
|
name: isomorfeus-transport
|
|
141
169
|
requirement: !ruby/object:Gem::Requirement
|
|
142
170
|
requirements:
|
|
143
171
|
- - '='
|
|
144
172
|
- !ruby/object:Gem::Version
|
|
145
|
-
version: 2.0
|
|
173
|
+
version: 2.1.0
|
|
146
174
|
type: :runtime
|
|
147
175
|
prerelease: false
|
|
148
176
|
version_requirements: !ruby/object:Gem::Requirement
|
|
149
177
|
requirements:
|
|
150
178
|
- - '='
|
|
151
179
|
- !ruby/object:Gem::Version
|
|
152
|
-
version: 2.0
|
|
180
|
+
version: 2.1.0
|
|
153
181
|
- !ruby/object:Gem::Dependency
|
|
154
182
|
name: isomorfeus
|
|
155
183
|
requirement: !ruby/object:Gem::Requirement
|
|
156
184
|
requirements:
|
|
157
185
|
- - '='
|
|
158
186
|
- !ruby/object:Gem::Version
|
|
159
|
-
version: 2.0
|
|
187
|
+
version: 2.1.0
|
|
160
188
|
type: :development
|
|
161
189
|
prerelease: false
|
|
162
190
|
version_requirements: !ruby/object:Gem::Requirement
|
|
163
191
|
requirements:
|
|
164
192
|
- - '='
|
|
165
193
|
- !ruby/object:Gem::Version
|
|
166
|
-
version: 2.0
|
|
194
|
+
version: 2.1.0
|
|
167
195
|
- !ruby/object:Gem::Dependency
|
|
168
196
|
name: rake
|
|
169
197
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -192,8 +220,7 @@ dependencies:
|
|
|
192
220
|
- - "~>"
|
|
193
221
|
- !ruby/object:Gem::Version
|
|
194
222
|
version: 3.10.0
|
|
195
|
-
description:
|
|
196
|
-
and Collections with ease.
|
|
223
|
+
description: Develop apps with powerful reactive data access and queries.
|
|
197
224
|
email: jan@kursator.de
|
|
198
225
|
executables: []
|
|
199
226
|
extensions: []
|
|
@@ -207,13 +234,13 @@ files:
|
|
|
207
234
|
- lib/isomorfeus-data.rb
|
|
208
235
|
- lib/isomorfeus/data/attribute_support.rb
|
|
209
236
|
- lib/isomorfeus/data/config.rb
|
|
210
|
-
- lib/isomorfeus/data/
|
|
237
|
+
- lib/isomorfeus/data/document_accelerator.rb
|
|
211
238
|
- lib/isomorfeus/data/field_support.rb
|
|
212
239
|
- lib/isomorfeus/data/generic_class_api.rb
|
|
213
240
|
- lib/isomorfeus/data/generic_instance_api.rb
|
|
214
|
-
- lib/isomorfeus/data/hamster_accelerator.rb
|
|
215
|
-
- lib/isomorfeus/data/hamster_storage_expander.rb
|
|
216
241
|
- lib/isomorfeus/data/handler/generic.rb
|
|
242
|
+
- lib/isomorfeus/data/object_accelerator.rb
|
|
243
|
+
- lib/isomorfeus/data/object_expander.rb
|
|
217
244
|
- lib/isomorfeus/data/reducer.rb
|
|
218
245
|
- lib/isomorfeus/data/version.rb
|
|
219
246
|
- lib/isomorfeus_data/lucid_document/base.rb
|
|
@@ -228,11 +255,12 @@ files:
|
|
|
228
255
|
- opal/uri.rb
|
|
229
256
|
- opal/uri/common.rb
|
|
230
257
|
- opal/uri/generic.rb
|
|
231
|
-
homepage:
|
|
258
|
+
homepage: https://isomorfeus.com
|
|
232
259
|
licenses:
|
|
233
260
|
- MIT
|
|
234
261
|
metadata:
|
|
235
262
|
github_repo: ssh://github.com/isomorfeus/gems
|
|
263
|
+
source_code_uri: https://github.com/isomorfeus/isomorfeus-project/isomorfeus-data
|
|
236
264
|
post_install_message:
|
|
237
265
|
rdoc_options: []
|
|
238
266
|
require_paths:
|
|
@@ -251,5 +279,5 @@ requirements: []
|
|
|
251
279
|
rubygems_version: 3.3.3
|
|
252
280
|
signing_key:
|
|
253
281
|
specification_version: 4
|
|
254
|
-
summary:
|
|
282
|
+
summary: Reactive objects, documents, files and queries for isomorfeus.
|
|
255
283
|
test_files: []
|
|
@@ -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
|