/* eslint-disable no-unused-vars*/
/**
 * @class InvertedIndex
 */
class InvertedIndex {
  /**
   * @constructor
   */
  constructor() {
    this.indices = [];
    this.allBooks = [];
  }

  /**
   * A tokenizer method
   * @param {String} string
   * @returns{any} void
   */
  static tokenizer(string) {
    if (string && string.trim().length !== 0) {
      return string.replace(/[^a-z\d\s]/ig, ' ').trim().toLowerCase().split(/\s+/);
    }
  }

  /**
   * A createIndex method
   * It takes in the filePath and the contents of the filePath
   * @param {String} filePath
   * @param {Object} content
   * @returns {Object} Returns object containing index
   */
  createIndex(filePath, content) {
    const result = {};
    // store all json files uploaded in an array which is this.allBooks
    if (!filePath) {
      content = this.allBooks;
    }
    content.forEach((book, doc) => {
      Object.keys(book).forEach((key) => {
        InvertedIndex.tokenizer(book[key]).forEach((word) => {
          if (!Object.prototype.hasOwnProperty.call(result, word)) {
            result[word] = [];
          }
          if (result[word].indexOf(doc + 1) > -1) {
            return;
          }
          result[word].push(doc + 1);
        });
      });
    });

    const returnResult = {
      terms: result,
      count: content.length,
      filePath
    };

    if (filePath) {
      this.indices[filePath] = returnResult;
    }
  }

  /**
   * GetIndex
   * Gets the index of the files uploaded
   * @param {String} filePath
   * @returns {any} void
   */
  getIndex(filePath) {
    return this.indices[filePath];
  }

  /**
   * searchIndex method
   * @param {String} filePath uploaded valid JSON file
   * @param {String} query word(s) or terms to search for
   * @returns {Object} Returns result of searched index.
   */
  searchIndex(filePath, query) {
    const results = [];
    const result = {};
    let indices = {};
    if (this.getIndex(filePath)) {
      indices[filePath] = this.getIndex(filePath);
    } else {
      indices = this.indices;
    }
    Object.keys(indices).forEach((book) => {
      InvertedIndex.tokenizer(query).forEach((word) => {
        if (Object.prototype.hasOwnProperty.call(indices[book].terms, word)) {
          if (!Object.prototype.hasOwnProperty.call(result, book)) {
            result[book] = {
              terms: {},
              count: indices[book].count,
              filePath: indices[book].filePath
            };
          }
          result[book].terms[word] = indices[book].terms[word];
        }
      });
      results.push(result[book]);
    });
    return results;
  }

  /**
   * validateFile a method to validate json file
   * @param {Object} content
   * @returns {Object} Returns message in Json format.
   */
  validateFile(content) {
    if (typeof content !== 'object' || content.length === 0) {
      return false;
    }
    let isValid = false;
    try {
      content.forEach((book) => {
        const bookTitle = Object.hasOwnProperty.call(book, 'title');
        const bookText = Object.hasOwnProperty.call(book, 'text');

        if ((bookTitle && bookText)) {
          isValid = true;
        }
      });

      return isValid;
    } catch (err) {
      return false;
    }
  }
}

@@ -499,20 +499,20 @@
 the file
-Path
+Name
  and the
@@ -528,28 +528,28 @@
  of the file
-Path
+Name
 %0A   * @param
@@ -558,28 +558,28 @@
 String%7D file
-Path
+Name
 %0A   * @param
@@ -580,33 +580,37 @@
 @param %7BObject%7D 
-c
+fileC
 ontent%0A   * @ret
@@ -683,15 +683,19 @@
 file
-Path, c
+Name, fileC
 onte
@@ -804,28 +804,28 @@
    if (!file
-Path
+Name
 ) %7B%0A      co
@@ -818,25 +818,29 @@
 me) %7B%0A      
-c
+fileC
 ontent = thi
@@ -857,25 +857,29 @@
 ;%0A    %7D%0A    
-c
+fileC
 ontent.forEa
@@ -1330,17 +1330,21 @@
  count: 
-c
+fileC
 ontent.l
@@ -1356,28 +1356,28 @@
 ,%0A      file
-Path
+Name
 %0A    %7D;%0A%0A   
@@ -1381,28 +1381,28 @@
     if (file
-Path
+Name
 ) %7B%0A      th
@@ -1412,28 +1412,28 @@
 indices%5Bfile
-Path
+Name
 %5D = returnRe
@@ -1532,28 +1532,28 @@
 String%7D file
-Path
+Name
 %0A   * @retur
@@ -1587,20 +1587,20 @@
 dex(file
-Path
+Name
 ) %7B%0A    
@@ -1623,20 +1623,20 @@
 ces%5Bfile
-Path
+Name
 %5D;%0A  %7D%0A%0A
@@ -1690,20 +1690,20 @@
 ng%7D file
-Path
+Name
  uploade
@@ -1859,20 +1859,20 @@
 dex(file
-Path
+Name
 , query)
@@ -1969,20 +1969,20 @@
 dex(file
-Path
+Name
 )) %7B%0A   
@@ -1996,20 +1996,20 @@
 ces%5Bfile
-Path
+Name
 %5D = this
@@ -2022,20 +2022,20 @@
 dex(file
-Path
+Name
 );%0A    %7D
@@ -2442,20 +2442,20 @@
     file
-Path
+Name
 : indice
@@ -2470,12 +2470,12 @@
 file
-Path
+Name
 %0A   
@@ -2725,17 +2725,21 @@
 Object%7D 
-c
+fileC
 ontent%0A 
@@ -2800,16 +2800,23 @@
    */%0A  
+static 
 validate
@@ -2820,17 +2820,21 @@
 ateFile(
-c
+fileC
 ontent) 
@@ -2831,24 +2831,61 @@
 eContent) %7B%0A
+    console.log(fileContent.length);%0A
     if (type
@@ -2887,17 +2887,21 @@
 (typeof 
-c
+fileC
 ontent !
@@ -2915,17 +2915,21 @@
 ect' %7C%7C 
-c
+fileC
 ontent.l
@@ -2965,24 +2965,25 @@
 alse;%0A    %7D%0A
+%0A
     let isVa
@@ -3011,17 +3011,21 @@
 %7B%0A      
-c
+fileC
 ontent.f

use the accurate identifiers and parameters