class XapianDb::Config

Global configuration for XapianDb @example A typical configuration might look like this:

XapianDb::Config.setup do |config|
  config.adapter  :active_record
  config.writer   :direct
  config.database "db/xapian_db"
end

@author Gernot Kogler

Attributes

_adapter[R]

DSL methods


_beanstalk_daemon[R]

DSL methods


_database[R]

DSL methods


_enabled_query_flags[R]

DSL methods


_resque_queue[R]

DSL methods


_set_max_expansion[R]

DSL methods


_sidekiq_queue[R]

DSL methods


_sidekiq_retry[R]

DSL methods


_stemmer[R]

DSL methods


_stopper[R]

DSL methods


_term_min_length[R]

DSL methods


_term_splitter_count[R]

DSL methods


_writer[R]

DSL methods


Public Class Methods

query_flags() click to toggle source
   # File lib/xapian_db/config.rb
71 def query_flags
72   @config.instance_variable_get("@_enabled_query_flags") || [ Xapian::QueryParser::FLAG_WILDCARD,
73                                                               Xapian::QueryParser::FLAG_BOOLEAN,
74                                                               Xapian::QueryParser::FLAG_BOOLEAN_ANY_CASE,
75                                                               Xapian::QueryParser::FLAG_SPELLING_CORRECTION
76                                                             ]
77 end
resque_queue() click to toggle source
   # File lib/xapian_db/config.rb
47 def resque_queue
48   @config.instance_variable_get("@_resque_queue") || 'xapian_db'
49 end
set_max_expansion() click to toggle source
   # File lib/xapian_db/config.rb
59 def set_max_expansion
60   @config.instance_variable_get("@_set_max_expansion")
61 end
setup() { |config| ... } click to toggle source

Configure global options for XapianDb. Availabe options:

  • adapter (see {XapianDb::Config#adapter})

  • writer (see {XapianDb::Config#writer})

  • database (see {XapianDb::Config#database})

  • language (see {XapianDb::Config#language})

In a Rails app, you can configure XapianDb using a config file. See the README for the details

   # File lib/xapian_db/config.rb
28 def setup(&block)
29   @config ||= Config.new
30   yield @config if block_given?
31 end
sidekiq_queue() click to toggle source
   # File lib/xapian_db/config.rb
51 def sidekiq_queue
52   @config.instance_variable_get("@_sidekiq_queue") || 'xapian_db'
53 end
sidekiq_retry() click to toggle source
   # File lib/xapian_db/config.rb
63 def sidekiq_retry
64   @config.instance_variable_get("@_sidekiq_retry") || false
65 end
term_min_length() click to toggle source
   # File lib/xapian_db/config.rb
55 def term_min_length
56   @config.instance_variable_get("@_term_min_length") || 1
57 end
term_splitter_count() click to toggle source
   # File lib/xapian_db/config.rb
67 def term_splitter_count
68   @config.instance_variable_get("@_term_splitter_count") || 0
69 end

Public Instance Methods

adapter(type) click to toggle source

Set the adapter @param [Symbol] type The adapter type; the following adapters are available:

- :generic ({XapianDb::Adapters::GenericAdapter})
- :active_record ({XapianDb::Adapters::ActiveRecordAdapter})
- :datamapper ({XapianDb::Adapters::DatamapperAdapter})
    # File lib/xapian_db/config.rb
116 def adapter(type)
117   begin
118     @_adapter = XapianDb::Adapters.const_get("#{camelize(type.to_s)}Adapter")
119   rescue NameError
120     require File.dirname(__FILE__) + "/adapters/#{type}_adapter"
121     @_adapter = XapianDb::Adapters.const_get("#{camelize(type.to_s)}Adapter")
122   end
123 end
beanstalk_daemon_url(url) click to toggle source

Set the url and port of the beanstalk daemon @param [Symbol] url The url of the beanstalk daemon; defaults to localhost:11300

    # File lib/xapian_db/config.rb
144 def beanstalk_daemon_url(url)
145   @_beanstalk_daemon_url = url
146 end
database(path) click to toggle source

Set the global database to use @param [String] path The path to the database. Either apply a file sytem path or :memory

for an in memory database
    # File lib/xapian_db/config.rb
 91 def database(path)
 92 
 93   # If the current database is a persistent database, we must release the
 94   # database and run the garbage collector to remove the write lock
 95   if @_database.is_a?(XapianDb::PersistentDatabase)
 96     @_database = nil
 97     GC.start
 98   end
 99 
100   if path.to_sym == :memory
101     @_database = XapianDb.create_db
102   else
103     begin
104       @_database = XapianDb.open_db :path => path
105     rescue IOError
106       @_database = XapianDb.create_db :path => path
107     end
108   end
109 end
disable_query_flag(flag) click to toggle source
    # File lib/xapian_db/config.rb
201 def disable_query_flag(flag)
202   @_enabled_query_flags ||= []
203   @_enabled_query_flags.delete flag
204 end
enable_query_flag(flag) click to toggle source
    # File lib/xapian_db/config.rb
195 def enable_query_flag(flag)
196   @_enabled_query_flags ||= []
197   @_enabled_query_flags << flag
198   @_enabled_query_flags.uniq!
199 end
indexer_preprocess_callback(method) click to toggle source

Set the indexer preprocess callback. @param [Method] method a class method; needs to take one parameter and return a string. @example

class Util
  def self.strip_accents(terms)
    terms.gsub(/[éèêëÉÈÊË]/, "e")
  end
end

XapianDb::Config.setup do |config|
  config.indexer_preprocess_callback Util.method(:strip_accents)
end
    # File lib/xapian_db/config.rb
218 def indexer_preprocess_callback(method)
219   @_preprocess_terms = method
220 end
language(lang) click to toggle source

Set the language. @param [Symbol] lang The language; apply the two letter ISO639 code for the language @example

XapianDb::Config.setup do |config|
  config.language :de
end

see {LANGUAGE_MAP} for supported languages

    # File lib/xapian_db/config.rb
179 def language(lang)
180   lang ||= :none
181   @_stemmer = XapianDb::Repositories::Stemmer.stemmer_for lang
182   @_stopper = lang == :none ? nil : XapianDb::Repositories::Stopper.stopper_for(lang)
183 end
resque_queue(name) click to toggle source

Set the name of the resque queue @param [String] name The name of the resque queue

    # File lib/xapian_db/config.rb
150 def resque_queue(name)
151   @_resque_queue = name
152 end
set_max_expansion(value) click to toggle source

Set the value for the max_expansion setting. @param [Integer] value The value to set for the set_max_expansion setting.

    # File lib/xapian_db/config.rb
162 def set_max_expansion(value)
163   @_set_max_expansion = value
164 end
sidekiq_queue(name) click to toggle source

Set the name of the sidekiq queue @param [String] name The name of the sidekiq queue

    # File lib/xapian_db/config.rb
156 def sidekiq_queue(name)
157   @_sidekiq_queue = name
158 end
sidekiq_retry(value) click to toggle source

Set the value for the Sidekiq retry setting. @param [Boolean, Numeric] value The value to set for the Sidekiq retry setting.

    # File lib/xapian_db/config.rb
168 def sidekiq_retry(value)
169   @_sidekiq_retry = value
170 end
term_min_length(length) click to toggle source

Set minimum length a term must have to get indexed; 2 is a good value to start @param [Integer] length The minimum length

    # File lib/xapian_db/config.rb
187 def term_min_length(length)
188   @_term_min_length = length
189 end
term_splitter_count(count) click to toggle source
    # File lib/xapian_db/config.rb
191 def term_splitter_count(count)
192   @_term_splitter_count = count
193 end
writer(type) click to toggle source

Set the index writer @param [Symbol] type The writer type; the following adapters are available:

- :direct ({XapianDb::IndexWriters::DirectWriter})
- :beanstalk ({XapianDb::IndexWriters::BeanstalkWriter})
- :resque ({XapianDb::IndexWriters::ResqueWriter})
- :sidekiq ({XapianDb::IndexWriters::SidekiqWriter})
    # File lib/xapian_db/config.rb
131 def writer(type)
132   # We try to guess the writer name
133   begin
134     require File.dirname(__FILE__) + "/index_writers/#{type}_writer"
135     @_writer = XapianDb::IndexWriters.const_get("#{camelize(type.to_s)}Writer")
136   rescue LoadError
137     puts "XapianDb: cannot load #{type} writer; see README for supported writers and how to install neccessary queue infrastructure"
138     raise
139   end
140 end