app/js/invertedIndex.js
/**
   * Searches the index
   * @function
   * @param {String} phrase string containing word(s) to be searched for
   * @param {Object} filename name of an indexed file or All.
   * @return {Object} search result with eachword and number of documents.
   */
Searches the index
@function
@param {String} phrase string containing word(s) to be searched for
@param {Object} filename name of an indexed file or All.
@return {Object} search result with eachword and number of documents.
Searches the index @function @param { String } phrase string containing word ( s ) to be searched for @param { Object } filename name of an indexed file or All . @return { Object } search result with eachword and number of documents .
searchIndex(phrase, filename) {
    const result = {};
    const files = (filename === 'All') ? this.filenames : [filename];
    files.forEach((file) => {
      const storedIndex = this.getIndex(file);
      const searchWords = InvertedIndex.tokenize(phrase);
      const search = {
        eachWord: {},
        count: storedIndex.count
      };
      searchWords.forEach((word) => {
        if (storedIndex.eachWord[word]) {
          if (!(search.eachWord[word] in search)) {
            search.eachWord[word] = storedIndex.eachWord[word];
          }
        } else search.eachWord[word] = [];
      });
      result[file] = search;
    });
    return result;
  }
searchIndex ( phrase , filename ) { const result = { } ; const files = ( filename === 'All' ) ? this . filenames : [ filename ] ; files . forEach ( ( file ) => { const storedIndex = this . getIndex ( file ) ; const searchWords = InvertedIndex . tokenize ( phrase ) ; const search = { eachWord : { } , count : storedIndex . count } ; searchWords . forEach ( ( word ) => { if ( storedIndex . eachWord [ word ] ) { if ( ! ( search . eachWord [ word ] in search ) ) { search . eachWord [ word ] = storedIndex . eachWord [ word ] ; } } else search . eachWord [ word ] = [ ] ; } ) ; result [ file ] = search ; } ) ; return result ; }
Searches the index
 @function
 @param {String} phrase string containing word(s) to be searched for
 @param {Object} filename name of an indexed file or All.
Searches the index @function @param { String } phrase string containing word ( s ) to be searched for @param { Object } filename name of an indexed file or All .