<commit_before>// Build inverted index

var invertedIndex = {};

console.log("Constructing inverted index...");

var numTrigrams = 0;
Texts.find().forEach( function(doc) {
  var docId = doc._id;
  var text = doc.text;
  var docLength = doc.text.length;
  for (var i = 0; i < docLength - 2; i++) {
    var trigram = text.substring(i, i + 3);
    if (trigram in invertedIndex) {
      invertedIndex[trigram].push(docId);
    } else {
      invertedIndex[trigram] = [docId];
      numTrigrams += 1;
    }
  }
  console.log("Processed doc. Trigrams: ", numTrigrams);
});

console.log("Found", Object.keys(invertedIndex).length, "trigrams in", Texts.find().count(), "docs.");

// Takes in query sent by client and narrows down number of docs in the inverted index to search.<commit_msg>Log inverted index progress (fixed)<commit_after>// Build inverted index

var invertedIndex = {};

console.log("Constructing inverted index...");

var numTrigrams = 0,
  docNum = 0;
Texts.find().forEach( function(doc) {
  var docId = doc._id;
  var text = doc.text;
  var docLength = doc.text.length;
  for (var i = 0; i < docLength - 2; i++) {
    var trigram = text.substring(i, i + 3);
    if (trigram in invertedIndex) {
      invertedIndex[trigram].push(docId);
    } else {
      invertedIndex[trigram] = [docId];
      numTrigrams += 1;
    }
  }
  docNum += 1;
  console.log("Processed doc", docNum, ". Trigrams: ", numTrigrams);
});

console.log("Found", Object.keys(invertedIndex).length, "trigrams in", Texts.find().count(), "docs.");

// Takes in query sent by client and narrows down number of docs in the inverted index to search.
{'fraction_non_alphanumeric': 0.15076923076923077, 'fraction_numerical': 0.0073846153846153844, 'mean_word_length': 3.479338842975207, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3279183', 'n_tokens_mistral': 585, 'n_tokens_neox': 538, 'n_words': 156}