artsy/mongoid_fulltext

View on GitHub

Showing 14 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

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                  def remove_from_ngram_index
                    mongoid_fulltext_config.each_pair do |index_name, _fulltext_config|
                      coll = collection.database[index_name]
                      if Mongoid::Compatibility::Version.mongoid5_or_newer?
                        coll.find('class' => name).delete_many
              Severity: Minor
              Found in lib/mongoid/full_text_search.rb and 1 other location - About 25 mins to fix
              lib/mongoid/full_text_search.rb on lines 365..371

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 29.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                def remove_from_ngram_index
                  mongoid_fulltext_config.each_pair do |index_name, _fulltext_config|
                    coll = collection.database[index_name]
                    if Mongoid::Compatibility::Version.mongoid5_or_newer?
                      coll.find('document_id' => _id).delete_many
              Severity: Minor
              Found in lib/mongoid/full_text_search.rb and 1 other location - About 25 mins to fix
              lib/mongoid/full_text_search.rb on lines 281..287

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 29.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Severity
              Category
              Status
              Source
              Language