fair-search/fairsearch-elasticsearch-plugin

View on GitHub

Showing 42 of 42 total issues

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

        if(response.status === 500){
            res.status(404);
            res.send();
        }else{
            for(var i=0; i<response.hits.hits.length; i++){
Severity: Major
Found in demo/server/server.js and 1 other location - About 4 hrs to fix
demo/server/server.js on lines 64..75

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 122.

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

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

        if(response.hits.hits.length === 0){
            res.status(404);
            res.send();
        }else{
        for(var i=0; i<response.hits.hits.length; i++){
Severity: Major
Found in demo/server/server.js and 1 other location - About 4 hrs to fix
demo/server/server.js on lines 136..146

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 122.

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

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

    public MTableFailProbPair adjustAlpha() {
        double aMin = 0;
        double aMax = alpha;
        double aMid = (aMin + aMax) / 2;

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 fairTopK has 79 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public TopDocs fairTopK(List<ScoreDoc> npQueue, List<ScoreDoc> pQueue, int k, float p, float alpha) {

        FairScorer scorer = new FairScorer(k);

        int [] m = fairnessLookup.fairnessAsTable(k, p, alpha);
Severity: Major
Found in src/main/java/com/purbon/search/fair/lib/FairTopKImpl.java - About 3 hrs to fix

    Method rescore has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

            @Override
            public TopDocs rescore(TopDocs topDocs, IndexSearcher searcher, RescoreContext rescoreContext) throws IOException {
    
                FairRescoreContext context = (FairRescoreContext)rescoreContext;
                FairSearchConfig config = context.getConfig();
    Severity: Minor
    Found in src/main/java/com/purbon/search/fair/query/FairRescoreBuilder.java - 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 fairTopK has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

        public TopDocs fairTopK(List<ScoreDoc> npQueue, List<ScoreDoc> pQueue, int k, float p, float alpha) {
    
            FairScorer scorer = new FairScorer(k);
    
            int [] m = fairnessLookup.fairnessAsTable(k, p, alpha);
    Severity: Minor
    Found in src/main/java/com/purbon/search/fair/lib/FairTopKImpl.java - 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

    File FairRescoreBuilder.java has 269 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    package com.purbon.search.fair.query;
    
    import com.purbon.search.fair.ModelStore;
    import com.purbon.search.fair.lib.FairTopK;
    import com.purbon.search.fair.lib.FairTopKImpl;
    Severity: Minor
    Found in src/main/java/com/purbon/search/fair/query/FairRescoreBuilder.java - About 2 hrs to fix

      FairSearchConfig has 21 methods (exceeds 20 allowed). Consider refactoring.
      Open

      public class FairSearchConfig {
      
      
          private static Logger logger = ESLoggerFactory.getLogger(FairSearchConfig.class);
      
      
      Severity: Minor
      Found in src/main/java/com/purbon/search/fair/query/FairSearchConfig.java - About 2 hrs to fix

        Method rescore has 52 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                @Override
                public TopDocs rescore(TopDocs topDocs, IndexSearcher searcher, RescoreContext rescoreContext) throws IOException {
        
                    FairRescoreContext context = (FairRescoreContext)rescoreContext;
                    FairSearchConfig config = context.getConfig();
        Severity: Major
        Found in src/main/java/com/purbon/search/fair/query/FairRescoreBuilder.java - About 2 hrs to fix

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

              }else{
                  client.index({
                  index: 'test',
                  type: 'test',
                  id: ""+data[i].id,
          Severity: Major
          Found in demo/server/server-ini.js and 1 other location - About 1 hr to fix
          demo/server/server-ini.js on lines 44..54

          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 74.

          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

              if(data[i].id >= 1000){
                  client.index({
                  index: 'test',
                  type: 'test',
                  id: ""+data[i].id,
          Severity: Major
          Found in demo/server/server-ini.js and 1 other location - About 1 hr to fix
          demo/server/server-ini.js on lines 54..64

          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 74.

          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

          Method resolveNullEntries has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

              public void resolveNullEntries() {
                  if (col1.size() == 0 && col2.size() == 0){
                      return;
                  }
                  col1.set(0, 0);
          Severity: Minor
          Found in src/main/java/com/purbon/search/fair/utils/DataFrame.java - 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 adjustAlpha has 43 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public MTableFailProbPair adjustAlpha() {
                  double aMin = 0;
                  double aMax = alpha;
                  double aMid = (aMin + aMax) / 2;
          
          

            Method computeFailureProbability has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public double computeFailureProbability() {
                    if (mTable[mTable.length - 1] == 0) {
                        return 0;
                    }
                    DataFrame auxMTable = this.mTableGenerator.computeAuxTMTable();
            Severity: Minor
            Found in src/main/java/com/purbon/search/fair/utils/AlphaAdjuster.java - About 1 hr to fix

              Identical blocks of code found in 3 locations. Consider refactoring.
              Open

                              if (pQueue.get(tp).score >= npQueue.get(tn).score) {
                                  doc = pQueue.get(tp);
                                  doc.score = scorer.score(doc);
                                  t[i] = doc;
                                  i = i + 1;
              Severity: Major
              Found in src/main/java/com/purbon/search/fair/lib/FairTopKImpl.java and 2 other locations - About 1 hr to fix
              src/main/java/com/purbon/search/fair/lib/FairTopKImpl.java on lines 55..62
              src/main/java/com/purbon/search/fair/lib/FairTopKImpl.java on lines 48..55

              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 76.

              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

              Identical blocks of code found in 3 locations. Consider refactoring.
              Open

                          } else if (countProtected < m[tp+tn]) { // protected candidates
                              doc = pQueue.get(tp);
                              doc.score = scorer.score(doc);
                              t[i] = doc;
                              i = i + 1;
              Severity: Major
              Found in src/main/java/com/purbon/search/fair/lib/FairTopKImpl.java and 2 other locations - About 1 hr to fix
              src/main/java/com/purbon/search/fair/lib/FairTopKImpl.java on lines 63..70
              src/main/java/com/purbon/search/fair/lib/FairTopKImpl.java on lines 48..55

              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 76.

              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

              Identical blocks of code found in 3 locations. Consider refactoring.
              Open

                          } else if (tn >= npSize) { // no more non protected candidates, take protected instead.
                              doc = pQueue.get(tp);
                              doc.score = scorer.score(doc);
                              t[i] = doc;
                              i = i + 1;
              Severity: Major
              Found in src/main/java/com/purbon/search/fair/lib/FairTopKImpl.java and 2 other locations - About 1 hr to fix
              src/main/java/com/purbon/search/fair/lib/FairTopKImpl.java on lines 63..70
              src/main/java/com/purbon/search/fair/lib/FairTopKImpl.java on lines 55..62

              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 76.

              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

              Method computeFailureProbability has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                  public double computeFailureProbability() {
                      if (mTable[mTable.length - 1] == 0) {
                          return 0;
                      }
                      DataFrame auxMTable = this.mTableGenerator.computeAuxTMTable();
              Severity: Minor
              Found in src/main/java/com/purbon/search/fair/utils/AlphaAdjuster.java - 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

              Function createMtableAndExecuteQuery has 26 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function createMtableAndExecuteQuery(k ,p, alpha, query, req, res){
                      var xhr = new XMLHttpRequest();
                      var data = JSON.stringify({"from" : 0, "size" : k,"query": {"match": {"body": query}}});
                      xhr.addEventListener("readystatechange", function() {
                      if (this.readyState === 4) {
              Severity: Minor
              Found in demo/server/server.js - About 1 hr to fix

                Method generateMtable has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    private int[] generateMtable(int k, float p, float a, String id) {
                        //check if the index exists
                        boolean mTableStoreExists = client
                                .admin().indices().prepareExists(ModelStore.STORE_NAME)
                                .get().isExists();
                  Severity
                  Category
                  Status
                  Source
                  Language