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 708 lines of code (exceeds 250 allowed). Consider refactoring.
Open

begin
  require 'xapian'
  $acts_as_xapian_bindings_available = true
rescue LoadError
  STDERR.puts "acts_as_xapian: No Ruby bindings for Xapian installed"
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 45 (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)
            if not if_value
    Severity: Minor
    Found in lib/acts_as_xapian/acts_as_xapian.rb - About 6 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 34 (exceeds 5 allowed). Consider refactoring.
    Open

        def initialize_query(options)
          #raise options.to_yaml
    
          self.runtime += Benchmark::realtime {
            offset = options[:offset] || 0; offset = offset.to_i
    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 xapian_index has 82 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)
            if not if_value
    Severity: Major
    Found in lib/acts_as_xapian/acts_as_xapian.rb - About 3 hrs to fix

      Method rebuild_index has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.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 _rebuild_index_safely has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

        def self._rebuild_index_safely(model_classes, verbose, terms, values, texts)
          batch_size = 1000
          for model_class in model_classes
            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 results has 46 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def results
            # If they've already pulled out the results, just return them.
            if !self.cached_results.nil?
              return self.cached_results
            end
      Severity: Minor
      Found in lib/acts_as_xapian/acts_as_xapian.rb - About 1 hr to fix

        Method rebuild_index has 46 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def self.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 1 hr to fix

          Method initialize_query has 45 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; offset = offset.to_i
          Severity: Minor
          Found in lib/acts_as_xapian/acts_as_xapian.rb - About 1 hr to fix

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

                def xapian_value(field, type = nil, index_translations = false)
                  if index_translations && self.respond_to?("translations")
                    if type == :date or 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 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_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|
                  raise "Value index '#{index}' must be an Integer, is #{index.class}" unless index.is_a? Integer
                  if @@values_by_number.include?(index) && @@values_by_number[index] != prefix
                    raise "Already have value index '#{index}' in another model " \
            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 update_index has a Cognitive Complexity of 12 (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 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 = self.send(field.to_sym) || self[field]
                  if type == :date
                    if value.kind_of?(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_terms has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

              def self.init_terms(terms)
                terms.each do |method, term_code, prefix|
                  raise "Use a single capital letter for term code" if not term_code.match(/^[A-Z]$/)
                  raise "M and I are reserved for use as the model/id term" if term_code == "M" || term_code == "I"
                  raise "model and modelid are reserved for use as the model/id prefixes" if prefix == "model" || prefix == "modelid"
            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 _rebuild_index_safely has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def self._rebuild_index_safely(model_classes, verbose, terms, values, texts)
                batch_size = 1000
                for model_class in model_classes
                  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 results has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                  def results
                    # If they've already pulled out the results, just return them.
                    if !self.cached_results.nil?
                      return self.cached_results
                    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 10 (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

              Avoid deeply nested control flow statements.
              Open

                          elsif texts
                            doc.remove_term(existing_term.term) # it's text and we've been asked to reindex it
              Severity: Major
              Found in lib/acts_as_xapian/acts_as_xapian.rb - About 45 mins to fix

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

                  def self.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

                  Avoid deeply nested control flow statements.
                  Open

                                if term_prefixes_to_index.include?(first_letter) # it's a value that we've been asked to index
                                  doc.remove_term(existing_term.term)
                                end
                  Severity: Major
                  Found in lib/acts_as_xapian/acts_as_xapian.rb - About 45 mins to fix

                    Method initialize has a Cognitive Complexity of 8 (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
                          for model_class in model_classes
                    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 _rebuild_index_safely has 5 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                      def self._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 has_normal_search_terms? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                      Open

                          def has_normal_search_terms?
                            ret = false
                            #x = ''
                            for t in self.query.terms
                              term = t.term
                      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)
                          STDOUT.puts("ActsAsXapian.update_index #{job.action} #{job.model} #{job.model_id.to_s} #{Time.now.to_s}") if verbose
                      
                          begin
                            if job.action == 'update'
                      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

                      There are no issues that match your filters.

                      Category
                      Status