Class: Kiosk::Indexer::Adapter::ThinkingSphinxAdapter::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/kiosk/indexer/adapter/thinking_sphinx_adapter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, name) ⇒ Index

Returns a new instance of Index.



194
195
196
197
198
199
# File 'lib/kiosk/indexer/adapter/thinking_sphinx_adapter.rb', line 194

def initialize(model, name)
  @model = model
  @name = name

  @fields = []
end

Instance Attribute Details

#modeObject (readonly)

Returns the value of attribute mode.



192
193
194
# File 'lib/kiosk/indexer/adapter/thinking_sphinx_adapter.rb', line 192

def mode
  @mode
end

#nameObject (readonly)

Returns the value of attribute name.



192
193
194
# File 'lib/kiosk/indexer/adapter/thinking_sphinx_adapter.rb', line 192

def name
  @name
end

Instance Method Details

#configObject



205
206
207
# File 'lib/kiosk/indexer/adapter/thinking_sphinx_adapter.rb', line 205

def config
  @config ||= ThinkingSphinx::Configuration.instance
end

#indexes(*fields) ⇒ Object



201
202
203
# File 'lib/kiosk/indexer/adapter/thinking_sphinx_adapter.rb', line 201

def indexes(*fields)
  @fields += fields.collect { |field| Field.new(field) }
end

#to_riddleObject



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/kiosk/indexer/adapter/thinking_sphinx_adapter.rb', line 209

def to_riddle
  index = Riddle::Configuration::Index.new(@name)
  index.path = File.join(config.searchd_file_path, index.name)

  config.index_options.each do |key,value|
    method = "#{key}=".to_sym
    index.send(method, value) if index.respond_to?(method)
  end

  source = Riddle::Configuration::XMLSource.new("#{@name}_source", :xmlpipe2)
  source.xmlpipe_command = rake("kiosk:index[#{name}]")

  index.sources << source

  [index]
end

#write_xml_to(io) ⇒ Object



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/kiosk/indexer/adapter/thinking_sphinx_adapter.rb', line 226

def write_xml_to(io)
  xm = Builder::XmlMarkup.new(:target => io)

  xm.instruct!
  xm.sphinx :docset, 'xmlns:sphinx' => 'http://sphinxsearch.com' do
    xm.sphinx :schema do
      @fields.each { |field| field.to_xml(xm) }
    end

    @model.all.each do |resource|
      xm.sphinx :document, :id => resource.id do
        @fields.each do |field|
          xm.tag!(field.name, resource.send(field.name))
        end
      end
    end
  end
end