artsy/mongoid_fulltext

View on GitHub

Showing 12 of 14 total issues

Method update_ngram_index has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring.
Open

  def update_ngram_index
    mongoid_fulltext_config.each_pair do |index_name, fulltext_config|
      if condition = fulltext_config[:update_if]
        case condition
        when Symbol then  next unless send condition
Severity: Minor
Found in lib/mongoid/full_text_search.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 all_ngrams has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
Open

    def all_ngrams(str, config, bound_number_returned = true)
      return {} if str.nil?

      if config[:remove_accents]
        if defined?(UnicodeUtils)
Severity: Minor
Found in lib/mongoid/full_text_search.rb - About 4 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

File full_text_search.rb has 293 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'mongoid'
require 'mongoid/compatibility'

if Mongoid::Compatibility::Version.mongoid3?
  require 'mongoid/full_text_search/indexes'
Severity: Minor
Found in lib/mongoid/full_text_search.rb - About 3 hrs to fix

    Method fulltext_search_ensure_indexes has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

        def fulltext_search_ensure_indexes(index_name, config)
          db = collection.database
          coll = db[index_name]
    
          # The order of filters matters when the same index is used from two or more collections.
    Severity: Minor
    Found in lib/mongoid/full_text_search.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 fulltext_search has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

        def fulltext_search(query_string, options = {})
          max_results = options.key?(:max_results) ? options.delete(:max_results) : 10
          return_scores = options.key?(:return_scores) ? options.delete(:return_scores) : false
          if mongoid_fulltext_config.count > 1 && !options.key?(:index)
            error_message = '%s is indexed by multiple full-text indexes. You must specify one by passing an :index_name parameter'
    Severity: Minor
    Found in lib/mongoid/full_text_search.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 all_ngrams has 50 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def all_ngrams(str, config, bound_number_returned = true)
          return {} if str.nil?
    
          if config[:remove_accents]
            if defined?(UnicodeUtils)
    Severity: Minor
    Found in lib/mongoid/full_text_search.rb - About 2 hrs to fix

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

          def fulltext_search(query_string, options = {})
            max_results = options.key?(:max_results) ? options.delete(:max_results) : 10
            return_scores = options.key?(:return_scores) ? options.delete(:return_scores) : false
            if mongoid_fulltext_config.count > 1 && !options.key?(:index)
              error_message = '%s is indexed by multiple full-text indexes. You must specify one by passing an :index_name parameter'
      Severity: Minor
      Found in lib/mongoid/full_text_search.rb - About 1 hr to fix

        Method fulltext_search_in has 39 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def fulltext_search_in(*args)
              self.mongoid_fulltext_config = {} if mongoid_fulltext_config.nil?
              options = args.last.is_a?(Hash) ? args.pop : {}
              index_name = if options.key?(:index_name)
                             options[:index_name]
        Severity: Minor
        Found in lib/mongoid/full_text_search.rb - About 1 hr to fix

          Method update_ngram_index has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def update_ngram_index
              mongoid_fulltext_config.each_pair do |index_name, fulltext_config|
                if condition = fulltext_config[:update_if]
                  case condition
                  when Symbol then  next unless send condition
          Severity: Minor
          Found in lib/mongoid/full_text_search.rb - About 1 hr to fix

            Method fulltext_search_ensure_indexes has 36 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def fulltext_search_ensure_indexes(index_name, config)
                  db = collection.database
                  coll = db[index_name]
            
                  # The order of filters matters when the same index is used from two or more collections.
            Severity: Minor
            Found in lib/mongoid/full_text_search.rb - About 1 hr to fix

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

                  def fulltext_search_in(*args)
                    self.mongoid_fulltext_config = {} if mongoid_fulltext_config.nil?
                    options = args.last.is_a?(Hash) ? args.pop : {}
                    index_name = if options.key?(:index_name)
                                   options[:index_name]
              Severity: Minor
              Found in lib/mongoid/full_text_search.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 map_query_filters has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  def map_query_filters(filters)
                    Hash[filters.map do |key, value|
                      case value
                      when Hash then
                        if value.key? :any then format_query_filter('$in', key, value[:any])
              Severity: Minor
              Found in lib/mongoid/full_text_search.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

              Severity
              Category
              Status
              Source
              Language