Class: ThinkingSphinx::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/thinking_sphinx/index.rb,
lib/thinking_sphinx/index/builder.rb,
lib/thinking_sphinx/index/faux_column.rb

Overview

The Index class is a ruby representation of a Sphinx source (not a Sphinx index - yes, I know it’s a little confusing. You’ll manage). This is another ‘internal’ Thinking Sphinx class - if you’re using it directly, you either know what you’re doing, or messing with things beyond your ken. Enjoy.

Defined Under Namespace

Classes: Builder, FauxColumn

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, &block) ⇒ Index

Create a new index instance by passing in the model it is tied to, and a block to build it with (optional but recommended). For documentation on the syntax for inside the block, the Builder class is what you want.

Quick Example:

Index.new(User) do
  indexes , email

  has created_at

  set_property :delta => true
end


28
29
30
31
32
33
# File 'lib/thinking_sphinx/index.rb', line 28

def initialize(model, &block)
  @model        = model
  @sources      = []
  @options      = {}
  @delta_object = nil
end

Instance Attribute Details

#delta_objectObject

Returns the value of attribute delta_object.



12
13
14
# File 'lib/thinking_sphinx/index.rb', line 12

def delta_object
  @delta_object
end

#modelObject

Returns the value of attribute model.



12
13
14
# File 'lib/thinking_sphinx/index.rb', line 12

def model
  @model
end

#sourcesObject

Returns the value of attribute sources.



12
13
14
# File 'lib/thinking_sphinx/index.rb', line 12

def sources
  @sources
end

Class Method Details

.name(model) ⇒ Object



47
48
49
# File 'lib/thinking_sphinx/index.rb', line 47

def self.name(model)
  model.name.underscore.tr(':/\\', '_')
end

Instance Method Details

#attributesObject



39
40
41
# File 'lib/thinking_sphinx/index.rb', line 39

def attributes
  @sources.collect { |source| source.attributes }.flatten
end

#delta?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/thinking_sphinx/index.rb', line 72

def delta?
  !@delta_object.nil?
end

#fieldsObject



35
36
37
# File 'lib/thinking_sphinx/index.rb', line 35

def fields
  @sources.collect { |source| source.fields }.flatten
end

#infix_fieldsObject



55
56
57
# File 'lib/thinking_sphinx/index.rb', line 55

def infix_fields
  fields.select { |field| field.infixes }
end

#local_optionsObject



59
60
61
# File 'lib/thinking_sphinx/index.rb', line 59

def local_options
  @options
end

#nameObject



43
44
45
# File 'lib/thinking_sphinx/index.rb', line 43

def name
  self.class.name(@model)
end

#optionsObject



63
64
65
66
67
68
69
70
# File 'lib/thinking_sphinx/index.rb', line 63

def options
  all_index_options = ThinkingSphinx::Configuration.instance.index_options.clone
  @options.keys.select { |key|
    ThinkingSphinx::Configuration::IndexOptions.include?(key.to_s) ||
    ThinkingSphinx::Configuration::CustomOptions.include?(key.to_s)
  }.each { |key| all_index_options[key.to_sym] = @options[key] }
  all_index_options
end

#prefix_fieldsObject



51
52
53
# File 'lib/thinking_sphinx/index.rb', line 51

def prefix_fields
  fields.select { |field| field.prefixes }
end