Module: LucidWorks::FieldCommons

Extended by:
ActiveSupport::Concern
Included in:
Dynamicfield, Field
Defined in:
lib/lucid_works/field_commons.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#convert_indexing_options_to_term_freq_and_posObject

Convert indexing_options to the correct values for omit_tf and omit_positions. Delete indexing_options from attributes so it is not saved.



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/lucid_works/field_commons.rb', line 101

def convert_indexing_options_to_term_freq_and_pos
  i_opt = @attributes.delete(:indexing_options)
  if indexed? && i_opt
    case i_opt.to_sym
    when :document_only
      self.omit_tf = true
      self.omit_positions = true
    when :document_termfreq
      self.omit_tf = false
      self.omit_positions = true
    when :document_termfreq_termpos
      self.omit_tf = false
      self.omit_positions = false
    else
      raise "Unknown indexing option: '#{i_opt}'. Allowed values are: #{INDEXING_OPTIONS.join(', ')}"
    end
  else # !indexed?
    self.omit_tf = true
    self.omit_positions = true
  end
  true
end

#indexing_optionsObject

Indexing_options is a fake attribute that wraps the omit_tf and omit_positions combinations. Translations are:

INDEXED?     indexing_options                    omit_tf         omit_positions

false           -                                 true              true
true            :document_only                    true              true
true            :document_termfreq                false             true
true            :documents_termfreq_termpos       false             false


83
84
85
86
87
88
89
90
# File 'lib/lucid_works/field_commons.rb', line 83

def indexing_options
  @attributes[:indexing_options] ||=
    if !indexed? || omit_tf?
      :document_only
    else
      omit_positions? ? :document_termfreq : :document_termfreq_termpos
    end
end

#indexing_options=(new_value) ⇒ Object

We have to remember the caller’s choice of indexing_options, as we can’t determine the correct omit_tf/omit_positions settins until we also know whether ‘indexed’ is set or not. So we keep it as an attribute for now, and remove it in a before_save.



95
96
97
# File 'lib/lucid_works/field_commons.rb', line 95

def indexing_options=(new_value)
  @attributes[:indexing_options] = new_value
end

#initialize(options) ⇒ Object



65
66
67
# File 'lib/lucid_works/field_commons.rb', line 65

def initialize(options)
  super(options.reverse_merge(:omit_tf => false))
end

#t_field_typeObject



69
70
71
# File 'lib/lucid_works/field_commons.rb', line 69

def t_field_type
  self.class.t_field_type(self.field_type)
end

#update_attributes(attrs) ⇒ Object



124
125
126
127
128
129
130
131
# File 'lib/lucid_works/field_commons.rb', line 124

def update_attributes(attrs)
  attrs = attrs.with_indifferent_access
  if [false, '0'].include?(attrs[:indexed])
    attrs[:omit_positions] ||= false
    attrs[:omit_tf] ||= false 
  end
  super(attrs)
end