Class: LucidWorks::Field

Inherits:
Base
  • Object
show all
Defined in:
lib/lucid_works/field.rb

Constant Summary collapse

INDEXING_OPTIONS =
[
  'document_only',
  'document_termfreq',
  'document_termfreq_termpos'
]
BOOST_VALUES =
[
  'none',
  'moderate',
  'high'
]

Constants included from Utils::BoolConverter

Utils::BoolConverter::FALSE_VALUES, Utils::BoolConverter::TRUE_VALUES

Instance Attribute Summary

Attributes inherited from Base

#attributes, #id, #parent, #persisted, #raw_response, #response_data

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

all, collection_url, #collection_url, create, #destroy, extract_parent_from_options, find, first, human_attribute_value, #human_attribute_value, #inspect, last, #member_url, #persisted?, #read_attribute_for_validation, #save, schema, singleton_name, to_select

Methods included from SimpleNaming

#model_name

Methods included from Utils::BoolConverter

#to_bool

Constructor Details

#initialize(options) ⇒ Field

Returns a new instance of Field.



75
76
77
# File 'lib/lucid_works/field.rb', line 75

def initialize(options)
  super(options.reverse_merge(:omit_tf => false, :short_field_boost => 'high'))
end

Class Method Details

.t_field_type(type) ⇒ Object



87
88
89
# File 'lib/lucid_works/field.rb', line 87

def self.t_field_type(type)
  I18n.translate(type, :scope => 'activemodel.models.lucid_works.collection.field.field_type')
end

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.



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/lucid_works/field.rb', line 119

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

#dynamically_generated?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/lucid_works/field.rb', line 79

def dynamically_generated?
  !dynamic_base.blank?
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


101
102
103
104
105
106
107
108
# File 'lib/lucid_works/field.rb', line 101

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.



113
114
115
# File 'lib/lucid_works/field.rb', line 113

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

#t_field_typeObject



83
84
85
# File 'lib/lucid_works/field.rb', line 83

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

#update_attributes(attrs) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/lucid_works/field.rb', line 142

def update_attributes(attrs)
  attrs = attrs.with_indifferent_access
  if [false, '0'].include?(attrs[:stored]) 
    attrs[:include_in_results] ||= false
    attrs[:highlight] ||= false
  end
  if [false, '0'].include?(attrs[:indexed])
    attrs[:facet] ||= false
    attrs[:synonym_expansion] ||= false
    attrs[:omit_tf] ||= false 
    attrs[:omit_positions] ||= false
    attrs[:short_field_boost] ||= 'high'
    attrs[:search_by_default] ||= false
    attrs[:use_in_find_similar] ||= false
    attrs[:query_time_stopword_handling] ||= false
  end
  super(attrs)
end