mysociety/alaveteli

View on GitHub
lib/acts_as_xapian/acts_as_xapian.rb

Summary

Maintainability
F
1 wk
Test Coverage

File acts_as_xapian.rb has 822 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'English'
begin
  require 'xapian'
  $acts_as_xapian_bindings_available = true

Severity: Major
Found in lib/acts_as_xapian/acts_as_xapian.rb - About 1 day to fix

    Method xapian_index has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
    Open

        def xapian_index(terms = true, values = true, texts = true)
          # if we have a conditional function for indexing, call it and destroy object if failed
          if self.class.xapian_options.include?(:if)
            if_value = xapian_value(self.class.xapian_options[:if], :boolean)
            unless if_value
    Severity: Minor
    Found in lib/acts_as_xapian/acts_as_xapian.rb - About 5 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method initialize_query has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
    Open

        def initialize_query(options)
          #raise options.to_yaml
    
          self.runtime += Benchmark.realtime {
            offset = options[:offset] || 0
    Severity: Minor
    Found in lib/acts_as_xapian/acts_as_xapian.rb - About 5 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method destroy_and_rebuild_index has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

      def self.destroy_and_rebuild_index(model_classes, verbose = false, terms = true, values = true, texts = true, safe_rebuild = true)
        #raise "when rebuilding all, please call as first and only thing done in process / task" if not ActsAsXapian.writable_db.nil?
        prepare_environment
    
        update_existing = !(terms == true && values == true && texts == true)
    Severity: Minor
    Found in lib/acts_as_xapian/acts_as_xapian.rb - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method xapian_index has 85 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def xapian_index(terms = true, values = true, texts = true)
          # if we have a conditional function for indexing, call it and destroy object if failed
          if self.class.xapian_options.include?(:if)
            if_value = xapian_value(self.class.xapian_options[:if], :boolean)
            unless if_value
    Severity: Major
    Found in lib/acts_as_xapian/acts_as_xapian.rb - About 3 hrs to fix

      Method _destroy_and_rebuild_index_safely has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

        def self._destroy_and_rebuild_index_safely(model_classes, verbose, terms, values, texts)
          batch_size = 1000
          model_classes.each do |model_class|
            model_class_count = model_class.count
            0.step(model_class_count, batch_size) do |i|
      Severity: Minor
      Found in lib/acts_as_xapian/acts_as_xapian.rb - About 2 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method initialize_query has 54 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def initialize_query(options)
            #raise options.to_yaml
      
            self.runtime += Benchmark.realtime {
              offset = options[:offset] || 0
      Severity: Major
      Found in lib/acts_as_xapian/acts_as_xapian.rb - About 2 hrs to fix

        Method destroy_and_rebuild_index has 50 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def self.destroy_and_rebuild_index(model_classes, verbose = false, terms = true, values = true, texts = true, safe_rebuild = true)
            #raise "when rebuilding all, please call as first and only thing done in process / task" if not ActsAsXapian.writable_db.nil?
            prepare_environment
        
            update_existing = !(terms == true && values == true && texts == true)
        Severity: Minor
        Found in lib/acts_as_xapian/acts_as_xapian.rb - About 2 hrs to fix

          Method results has 44 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def results
                # If they've already pulled out the results, just return them.
                return cached_results unless cached_results.nil?
          
                docs = []
          Severity: Minor
          Found in lib/acts_as_xapian/acts_as_xapian.rb - About 1 hr to fix

            Method words_to_highlight has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                def words_to_highlight(opts = {})
                  default_opts = { include_original: false, regex: false }
                  opts = default_opts.merge(opts)
            
                  # Reject all prefixes other than Z, which we know is reserved for stems
            Severity: Minor
            Found in lib/acts_as_xapian/acts_as_xapian.rb - About 1 hr to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Method init_terms has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

              def self.init_terms(terms)
                terms.each do |_method, term_code, prefix|
                  unless term_code.match(/^[A-Z]$/)
                    raise "Use a single capital letter for term code"
                  end
            Severity: Minor
            Found in lib/acts_as_xapian/acts_as_xapian.rb - About 1 hr to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Method single_xapian_value has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                def single_xapian_value(field, type = nil)
                  value = send(field.to_sym) || self[field]
                  if type == :date
                    if value.is_a?(Time)
                      value.utc.strftime("%Y%m%d")
            Severity: Minor
            Found in lib/acts_as_xapian/acts_as_xapian.rb - About 1 hr to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Method init_values has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

              def self.init_values(values)
                values.each do |_method, index, prefix, value_type|
                  unless index.is_a? Integer
                    raise "Value index '#{index}' must be an Integer, is #{index.class}"
                  end
            Severity: Minor
            Found in lib/acts_as_xapian/acts_as_xapian.rb - About 1 hr to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Method prepare_environment has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

              def self.prepare_environment
                return unless @@db_path.nil?
            
                # barf if we can't figure out the environment
                environment = (ENV['RAILS_ENV'] or Rails.env)
            Severity: Minor
            Found in lib/acts_as_xapian/acts_as_xapian.rb - About 1 hr to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Method xapian_value has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

                def xapian_value(field, type = nil, index_translations = false)
                  if index_translations && respond_to?("translations")
                    if (type == :date) || (type == :boolean)
                      value = single_xapian_value(field, type = type)
                    else
            Severity: Minor
            Found in lib/acts_as_xapian/acts_as_xapian.rb - About 1 hr to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Method _destroy_and_rebuild_index_safely has 30 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def self._destroy_and_rebuild_index_safely(model_classes, verbose, terms, values, texts)
                batch_size = 1000
                model_classes.each do |model_class|
                  model_class_count = model_class.count
                  0.step(model_class_count, batch_size) do |i|
            Severity: Minor
            Found in lib/acts_as_xapian/acts_as_xapian.rb - About 1 hr to fix

              Method update_index has 28 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def self.update_index(flush = false, verbose = false)
                  # STDOUT.puts("start of ActsAsXapian.update_index") if verbose
              
                  # Before calling writable_init we have to make sure every model class has been initialized.
                  # i.e. has had its class code loaded, so acts_as_xapian has been called inside it, and
              Severity: Minor
              Found in lib/acts_as_xapian/acts_as_xapian.rb - About 1 hr to fix

                Method update_index has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                  def self.update_index(flush = false, verbose = false)
                    # STDOUT.puts("start of ActsAsXapian.update_index") if verbose
                
                    # Before calling writable_init we have to make sure every model class has been initialized.
                    # i.e. has had its class code loaded, so acts_as_xapian has been called inside it, and
                Severity: Minor
                Found in lib/acts_as_xapian/acts_as_xapian.rb - About 45 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Method destroy_and_rebuild_index has 6 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                  def self.destroy_and_rebuild_index(model_classes, verbose = false, terms = true, values = true, texts = true, safe_rebuild = true)
                Severity: Minor
                Found in lib/acts_as_xapian/acts_as_xapian.rb - About 45 mins to fix

                  Method _destroy_and_rebuild_index_safely has 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                    def self._destroy_and_rebuild_index_safely(model_classes, verbose, terms, values, texts)
                  Severity: Minor
                  Found in lib/acts_as_xapian/acts_as_xapian.rb - About 35 mins to fix

                    Method initialize has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def initialize(model_classes, query_string, options = {}, user_query = nil)
                          # Check parameters, convert to actual array of model classes
                          new_model_classes = []
                          model_classes = [model_classes] if model_classes.class != Array
                          model_classes.each do |model_class|
                    Severity: Minor
                    Found in lib/acts_as_xapian/acts_as_xapian.rb - About 35 mins to fix

                    Cognitive Complexity

                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                    A method's cognitive complexity is based on a few simple rules:

                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                    • Code is considered more complex for each "break in the linear flow of the code"
                    • Code is considered more complex when "flow breaking structures are nested"

                    Further reading

                    Method results has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def results
                          # If they've already pulled out the results, just return them.
                          return cached_results unless cached_results.nil?
                    
                          docs = []
                    Severity: Minor
                    Found in lib/acts_as_xapian/acts_as_xapian.rb - About 35 mins to fix

                    Cognitive Complexity

                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                    A method's cognitive complexity is based on a few simple rules:

                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                    • Code is considered more complex for each "break in the linear flow of the code"
                    • Code is considered more complex when "flow breaking structures are nested"

                    Further reading

                    Method run_job has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def self.run_job(job, flush, verbose)
                        if verbose
                          STDOUT.puts("ActsAsXapian.update_index #{job.action} #{job.model} #{job.model_id} #{Time.now}")
                        end
                    
                    
                    Severity: Minor
                    Found in lib/acts_as_xapian/acts_as_xapian.rb - About 35 mins to fix

                    Cognitive Complexity

                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                    A method's cognitive complexity is based on a few simple rules:

                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                    • Code is considered more complex for each "break in the linear flow of the code"
                    • Code is considered more complex when "flow breaking structures are nested"

                    Further reading

                    Method readable_init has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def self.readable_init
                        unless ActsAsXapian.bindings_available
                          raise NoXapianRubyBindingsError, "Xapian Ruby bindings not installed"
                        end
                        if @@init_values.empty?
                    Severity: Minor
                    Found in lib/acts_as_xapian/acts_as_xapian.rb - About 25 mins to fix

                    Cognitive Complexity

                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                    A method's cognitive complexity is based on a few simple rules:

                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                    • Code is considered more complex for each "break in the linear flow of the code"
                    • Code is considered more complex when "flow breaking structures are nested"

                    Further reading

                    There are no issues that match your filters.

                    Category
                    Status