Sha256: bdb36334c156c7af683d775fccd53154b1323c5e36edd4232cd7af97d9c5a4af

Contents?: true

Size: 1.71 KB

Versions: 4

Compression:

Stored size: 1.71 KB

Contents

module Zena
  module Use
    module MLIndex
      module ModelMethods
        def self.included(base)
          base.alias_method_chain :rebuild_index!, :multi_lingual
        end

        def rebuild_index_with_multi_lingual!
          visible_versions.each do |version|
            # 1. for each visible version
            self.version = version
            @properties  = version.prop
            # rebuild for each lang
            @index_langs = nil
            # Forces a to skip multi lingual indices
            # @index_langs = []

            # Build std index
            rebuild_index_for_version(version)
            rebuild_index_without_multi_lingual!
            # 2. PropEval::rebuild_index!
            # 3. Fulltext::rebuild_index!
            # 4. Properties::rebuild_index!
          end
        end

        def rebuild_index_for_version(v)
          # noop (method chaining in PropEval, Fulltext, etc)
        end


        # Hash used to read current values
        def index_reader(group_name)
          if group_name =~ /^ml_/
            return nil if index_langs.empty?
            super.merge(:with => {'lang' => index_langs})
          else
            super
          end
        end

        private
          # Return the list of languages for which the current version is returned.
          def index_langs
            @index_langs ||= begin
              v_id     = version.id
              ref_lang = self.ref_lang
              read     = vhash['w'].merge(vhash['r'])
              current_site.lang_list.select do |lang|
                (read[lang] || read[ref_lang] || read.values.first) == v_id
              end
            end
          end
      end # ModelMethods
    end # MLIndex
  end # Use
end # Zena

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
zena-1.1.1 lib/zena/use/ml_index.rb
zena-1.1.0 lib/zena/use/ml_index.rb
zena-1.0.0 lib/zena/use/ml_index.rb
zena-1.0.0.rc3 lib/zena/use/ml_index.rb