Module: Xapit
- Defined in:
- lib/xapit.rb,
lib/xapit/server/app.rb,
lib/xapit/client/facet.rb,
lib/xapit/server/query.rb,
lib/xapit/client/railtie.rb,
lib/xapit/server/indexer.rb,
lib/xapit/server/database.rb,
lib/xapit/client/collection.rb,
lib/xapit/client/membership.rb,
lib/xapit/client/facet_option.rb,
lib/xapit/client/index_builder.rb,
lib/xapit/client/remote_database.rb,
lib/generators/xapit/install_generator.rb,
lib/xapit/client/model_adapters/active_record_adapter.rb,
lib/xapit/client/model_adapters/default_model_adapter.rb,
lib/xapit/client/model_adapters/abstract_model_adapter.rb
Defined Under Namespace
Modules: Client, Generators, Server
Classes: Disabled, Error
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.config ⇒ Object
Returns the value of attribute config.
15
16
17
|
# File 'lib/xapit.rb', line 15
def config
@config
end
|
Class Method Details
.database ⇒ Object
31
32
33
34
35
36
37
38
|
# File 'lib/xapit.rb', line 31
def database
raise Disabled, "Unable to access Xapit database because it is disabled in configuration." unless Xapit.config[:enabled]
if config[:server]
@database ||= Xapit::Client::RemoteDatabase.new(config[:server])
else
@database ||= Xapit::Server::Database.new(config[:database_path])
end
end
|
.enable ⇒ Object
68
69
70
|
# File 'lib/xapit.rb', line 68
def enable
config[:enabled] = true
end
|
.facet_identifier(attribute, value) ⇒ Object
50
51
52
|
# File 'lib/xapit.rb', line 50
def facet_identifier(attribute, value)
Digest::SHA1.hexdigest(["xapit", attribute, value].join)[0..6]
end
|
.index(*models) ⇒ Object
72
73
74
75
76
|
# File 'lib/xapit.rb', line 72
def index(*models)
models.each do |model|
model.xapit_model_adapter.index_all
end
end
|
.load_config(filename, environment) ⇒ Object
40
41
42
43
44
|
# File 'lib/xapit.rb', line 40
def load_config(filename, environment)
@loaded_config = symbolize_keys(YAML.load_file(filename)[environment.to_s])
raise ArgumentError, "The #{environment} environment does not exist in #{filename}" if @loaded_config.nil?
@config.merge!(@loaded_config)
end
|
.reload ⇒ Object
26
27
28
29
|
# File 'lib/xapit.rb', line 26
def reload
reset_config
@config.merge!(@loaded_config) if @loaded_config
end
|
.reset_config ⇒ Object
17
18
19
20
21
22
23
24
|
# File 'lib/xapit.rb', line 17
def reset_config
@database = nil
@config = {
:enabled => true,
:spelling => true,
:stemming => "english"
}
end
|
.serialize_value(value) ⇒ Object
58
59
60
61
62
63
64
65
66
|
# File 'lib/xapit.rb', line 58
def serialize_value(value)
if value.kind_of?(Time)
Xapian.sortable_serialise(value.to_i)
elsif value.kind_of?(Numeric) || value.to_s =~ /^[0-9]+$/
Xapian.sortable_serialise(value.to_f)
else
value.to_s.downcase
end
end
|
.symbolize_keys(arg) ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/xapit.rb', line 80
def symbolize_keys(arg)
case arg
when Array
arg.map { |elem| symbolize_keys(elem) }
when Hash
Hash[
arg.map { |key, value|
k = key.is_a?(String) ? key.to_sym : key
v = symbolize_keys(value)
[k,v]
}]
else
arg
end
end
|
.value_index(type, attribute) ⇒ Object
46
47
48
|
# File 'lib/xapit.rb', line 46
def value_index(type, attribute)
Zlib.crc32(["xapit", type, attribute].join) % 99999999 end
|