addOccurrences(hash, occurrences) {
    if (occurrences.length < 1) {
      return Promise.resolve(0);
    }

    return new Promise((resolve, reject) => {
      const client = this._client;
      const stringsTotal = occurrences.length;
      const matchingStrings = occurrences
        .filter(entry => entry.length > 0).length;

      if (stringsTotal < matchingStrings) {
        return reject(new Error(
          `Found ${matchingStrings}/${stringsTotal} in ${hash}`
        ));
      }

      let batch = client.batch()
        .incr(FILES_SEEN)
        .hset(STRING_TOTAL, hash, stringsTotal)
        .hset(STRING_MATCHING, hash, matchingStrings);

      for (const [name, score] of scoreGrammars(occurrences)) {
        batch = batch.zincrby(SAW_GRAMMAR, score, name)
          .sadd(`grammar:${name}`, hash);
      }

      batch.exec(err => {
        if (err) reject(err);
        else resolve();
      });
    });
  }
/**
   * Add a single occurrence of a grammar at the given index in the file..
   */
Add a single occurrence of a grammar at the given index in the file
Add a single occurrence of a grammar at the given index in the file
addOccurrences(hash, occurrences) {
    if (occurrences.length < 1) {
      return Promise.resolve(0);
    }
    return new Promise((resolve, reject) => {
      const client = this._client;
      const stringsTotal = occurrences.length;
      const matchingStrings = occurrences
        .filter(entry => entry.length > 0).length;
      if (stringsTotal < matchingStrings) {
        return reject(new Error(
          `Found ${matchingStrings}/${stringsTotal} in ${hash}`
        ));
      }
      let batch = client.batch()
        .incr(FILES_SEEN)
        .hset(STRING_TOTAL, hash, stringsTotal)
        .hset(STRING_MATCHING, hash, matchingStrings);
      for (const [name, score] of scoreGrammars(occurrences)) {
        batch = batch.zincrby(SAW_GRAMMAR, score, name)
          .sadd(`grammar:${name}`, hash);
      }
      batch.exec(err => {
        if (err) reject(err);
        else resolve();
      });
    });
  }
addOccurrences ( hash , occurrences ) { if ( occurrences . length < 1 ) { return Promise . resolve ( 0 ) ; } return new Promise ( ( resolve , reject ) => { const client = this . _client ; const stringsTotal = occurrences . length ; const matchingStrings = occurrences . filter ( entry => entry . length > 0 ) . length ; if ( stringsTotal < matchingStrings ) { return reject ( new Error ( ` ${ matchingStrings } ${ stringsTotal } ${ hash } ` ) ) ; } let batch = client . batch ( ) . incr ( FILES_SEEN ) . hset ( STRING_TOTAL , hash , stringsTotal ) . hset ( STRING_MATCHING , hash , matchingStrings ) ; for ( const [ name , score ] of scoreGrammars ( occurrences ) ) { batch = batch . zincrby ( SAW_GRAMMAR , score , name ) . sadd ( ` ${ name } ` , hash ) ; } batch . exec ( err => { if ( err ) reject ( err ) ; else resolve ( ) ; } ) ; } ) ; }
Add a single occurrence of a grammar at the given index in the file..
Add a single occurrence of a grammar at the given index in the file ..