Module: Lexster
- Defined in:
- lib/lexster.rb,
lib/lexster/node.rb,
lib/lexster/batch.rb,
lib/lexster/config.rb,
lib/lexster/railtie.rb,
lib/lexster/version.rb,
lib/lexster/model_config.rb,
lib/lexster/relationship.rb,
lib/lexster/search_session.rb,
lib/lexster/model_additions.rb,
lib/lexster/database_cleaner.rb
Defined Under Namespace
Modules: ModelAdditions, Node, Relationship
Classes: Batch, BatchPromiseProxy, Config, ModelConfig, NeoDatabaseCleaner, Railtie, SearchConfig, SearchSession, SingleResultPromiseProxy
Constant Summary
collapse
- DEFAULT_FULLTEXT_SEARCH_INDEX_NAME =
:lexster_default_search_index
- NODE_AUTO_INDEX_NAME =
'node_auto_index'
- RELATIONSHIP_AUTO_INDEX_NAME =
'relationship_auto_index'
- UNIQUE_ID_KEY =
'lexster_unique_id'
- VERSION =
"0.0.1"
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.config ⇒ Object
Returns the value of attribute config.
24
25
26
|
# File 'lib/lexster.rb', line 24
def config
@config
end
|
.db ⇒ Object
Returns the value of attribute db.
20
21
22
|
# File 'lib/lexster.rb', line 20
def db
@db
end
|
.env_loaded ⇒ Object
Returns the value of attribute env_loaded.
23
24
25
|
# File 'lib/lexster.rb', line 23
def env_loaded
@env_loaded
end
|
.logger ⇒ Object
Returns the value of attribute logger.
21
22
23
|
# File 'lib/lexster.rb', line 21
def logger
@logger
end
|
.ref_node ⇒ Object
Returns the value of attribute ref_node.
22
23
24
|
# File 'lib/lexster.rb', line 22
def ref_node
@ref_node
end
|
Class Method Details
.batch(options = {}, &block) ⇒ Object
68
69
70
|
# File 'lib/lexster.rb', line 68
def batch(options={}, &block)
Lexster::Batch.new(options, &block).run
end
|
.clean_db(confirm) ⇒ Object
84
85
86
87
|
# File 'lib/lexster.rb', line 84
def clean_db(confirm)
puts "must call with confirm: Lexster.clean_db(:yes_i_am_sure)" and return unless confirm == :yes_i_am_sure
Lexster::NeoDatabaseCleaner.clean_db
end
|
46
47
48
|
# File 'lib/lexster.rb', line 46
def configure
yield config
end
|
.enabled ⇒ Object
Also known as:
enabled?
94
95
96
97
98
|
# File 'lib/lexster.rb', line 94
def enabled
flag = Thread.current[:lexster_enabled]
flag.nil? ? true : flag
end
|
.enabled=(flag) ⇒ Object
90
91
92
|
# File 'lib/lexster.rb', line 90
def enabled=(flag)
Thread.current[:lexster_enabled] = flag
end
|
.ensure_default_fulltext_search_index ⇒ Object
create a fulltext index if not exists
.execute_script_or_add_to_batch(gremlin_query, script_vars) ⇒ Object
.initialize_all ⇒ Object
50
51
52
53
54
55
|
# File 'lib/lexster.rb', line 50
def initialize_all
@env_loaded = true
logger.info "Lexster initialize_all"
initialize_relationships
initialize_server
end
|
.initialize_server ⇒ Object
57
58
59
60
61
|
# File 'lib/lexster.rb', line 57
def initialize_server
initialize_auto_index
initialize_subrefs
initialize_per_model_indexes
end
|
.node_models ⇒ Object
26
27
28
|
# File 'lib/lexster.rb', line 26
def node_models
@node_models ||= []
end
|
.relationship_models ⇒ Object
30
31
32
|
# File 'lib/lexster.rb', line 30
def relationship_models
@relationship_models ||= []
end
|
.reset_cached_variables ⇒ Object
80
81
82
|
# File 'lib/lexster.rb', line 80
def reset_cached_variables
initialize_subrefs
end
|
.search(types, term, options = {}) ⇒ Object
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
# File 'lib/lexster.rb', line 126
def search(types, term, options = {})
options = options.reverse_merge(limit: 15,match_type: "AND")
types = [*types]
query = []
types.each do |type|
query_for_type = []
query_for_type << "ar_type:#{type.name}"
case term
when String
search_in_fields = type.lexster_config.search_options.fulltext_fields.keys
next if search_in_fields.empty?
query_for_type << search_in_fields.map{ |field| generate_field_query(field, term, true, options[:match_type]) }.join(" OR ")
when Hash
term.each do |field, value|
query_for_type << generate_field_query(field, value, false)
end
end
query << "(#{query_for_type.join(") AND (")})"
end
query = "(#{query.join(") OR (")})"
logger.info "Lexster query #{query}"
gremlin_query = <<-GREMLIN
#{options[:before_query]}
idx = g.getRawGraph().index().forNodes('#{DEFAULT_FULLTEXT_SEARCH_INDEX_NAME}')
hits = idx.query('#{sanitize_query_for_gremlin(query)}')
hits = #{options[:limit] ? "hits.take(#{options[:limit]})" : "hits"}
#{options[:after_query]}
GREMLIN
logger.info "[NEOID] search:\n#{gremlin_query}"
results = Lexster.db.execute_script(gremlin_query)
SearchSession.new(results, *types)
end
|
.use(flag = true) ⇒ Object
101
102
103
104
105
106
|
# File 'lib/lexster.rb', line 101
def use(flag=true)
old, self.enabled = enabled?, flag
yield if block_given?
ensure
self.enabled = old
end
|