Class: Xapit::Config
- Inherits:
-
Object
- Object
- Xapit::Config
- Defined in:
- lib/xapit/config.rb
Overview
Singleton class for storing Xapit configuration settings. Currently this only includes the database path.
Class Attribute Summary collapse
-
.options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
- .breadcrumb_facets? ⇒ Boolean
-
.database ⇒ Object
Fetch Xapian::Database object at configured path.
- .default_options ⇒ Object
- .indexer ⇒ Object
-
.path ⇒ Object
The configured path to the database.
- .query_parser ⇒ Object
-
.remove_database ⇒ Object
Removes the configured database file and clears the stored one in memory.
-
.setup(options = {}) ⇒ Object
Setup configuration options.
-
.setup? ⇒ Boolean
See if setup options are already set.
- .spelling? ⇒ Boolean
- .stemming ⇒ Object
-
.writable_database ⇒ Object
Fetch Xapian::WritableDatabase object at configured path.
Class Attribute Details
.options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/xapit/config.rb', line 5 def @options end |
Class Method Details
.breadcrumb_facets? ⇒ Boolean
59 60 61 |
# File 'lib/xapit/config.rb', line 59 def @options[:breadcrumb_facets] end |
.database ⇒ Object
Fetch Xapian::Database object at configured path. Database is stored in memory.
64 65 66 |
# File 'lib/xapit/config.rb', line 64 def database @writable_database || (@database ||= Xapian::Database.new(path)) end |
.default_options ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/xapit/config.rb', line 24 def { :indexer => SimpleIndexer, :query_parser => ClassicQueryParser, :spelling => true, :stemming => "english" } end |
.indexer ⇒ Object
47 48 49 |
# File 'lib/xapit/config.rb', line 47 def indexer @options[:indexer] end |
.path ⇒ Object
The configured path to the database.
39 40 41 |
# File 'lib/xapit/config.rb', line 39 def path @options[:database_path] end |
.query_parser ⇒ Object
43 44 45 |
# File 'lib/xapit/config.rb', line 43 def query_parser @options[:query_parser] end |
.remove_database ⇒ Object
Removes the configured database file and clears the stored one in memory.
76 77 78 79 80 |
# File 'lib/xapit/config.rb', line 76 def remove_database # this can be a bit dangers, maybe do some checking here first? FileUtils.rm_rf(path) if File.exist? path @database = nil @writable_database = nil end |
.setup(options = {}) ⇒ Object
Setup configuration options. The following options are supported.
:database_path
: Where the database is stored. :stemming
: The language to use for stemming, defaults to “english”. :spelling
: True or false to enable/disable spelling, defaults to true. :indexer
: Class to handle the indexing, defaults to SimpleIndexer. :query_parser
: Class to handle the parsing, defaults to ClassicQueryParser. :breadcrumb_facets
: Use breadcrumb mode for applied facets. See Collection#applied_facet_options for details.
16 17 18 19 20 21 22 |
# File 'lib/xapit/config.rb', line 16 def setup( = {}) if @options && [:database_path] != @options[:database_path] @database = nil @writable_database = nil end @options = .reverse_merge() end |
.setup? ⇒ Boolean
See if setup options are already set.
34 35 36 |
# File 'lib/xapit/config.rb', line 34 def setup? @options end |
.spelling? ⇒ Boolean
51 52 53 |
# File 'lib/xapit/config.rb', line 51 def spelling? @options[:spelling] end |
.stemming ⇒ Object
55 56 57 |
# File 'lib/xapit/config.rb', line 55 def stemming @options[:stemming] end |
.writable_database ⇒ Object
Fetch Xapian::WritableDatabase object at configured path. Database is stored in memory. Creates the database directory if needed.
70 71 72 73 |
# File 'lib/xapit/config.rb', line 70 def writable_database FileUtils.mkdir_p(File.dirname(path)) unless File.exist?(File.dirname(path)) @writable_database ||= Xapian::WritableDatabase.new(path, Xapian::DB_CREATE_OR_OPEN) end |