<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

module.exports = function (mongoInstance) {
  var mongoosastic = require("mongoosastic"),
    mongooseValidator = require("mongoose-validator"),
    env = require("../environment"),
    validate = mongooseValidator.validate,
    url = require("url"),
    Mongoose = mongoInstance,
    elasticSearchURL = env.get("FOUNDELASTICSEARCH_URL") ||
    env.get("BONSAI_URL") ||
    env.get("ELASTIC_SEARCH_URL");

  elasticSearchURL = url.parse(elasticSearchURL);

  // This is a copy of https://github.com/chriso/node-validator/blob/master/lib/validators.js#L29-L32 which
  // is used for "isUrl" with mongoose-validator. Modified to accept underscores in the hostname.
  var urlregex = new RegExp("^(?!mailto:)(?:(?:https?|ftp):\/\/)?(?:\S+(?::\S*)" +
    "?@)?(?:(?:(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[" +
    "0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\_\u00a1-" +
    "\uffff0-9]+-?)*[a-z\_\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*" +
    "[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))|localhost)(?::\d" +
    "{2,5})?(?:\/[^\s]*)?(?:\?\S*)?$/", "i"
  );

  mongooseValidator.extend("isURL", function () {
    var str = this.str;
    return str.length < 2083 && str.match(urlregex);
  });

  var Timestamp = {
      type: Number,
      es_type: "long",
      es_indexed: true,
      es_index: "not_analyzed"
    },

    reportSchema = new Mongoose.Schema({
      userId: Number
    }),

    likeSchema = new Mongoose.Schema({
      userId: Number
    });

  // Schema
  var schema = new Mongoose.Schema({
    url: {
      type: String,<commit_msg>double escape the regex string<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

module.exports = function (mongoInstance) {
  var mongoosastic = require("mongoosastic"),
    mongooseValidator = require("mongoose-validator"),
    env = require("../environment"),
    validate = mongooseValidator.validate,
    url = require("url"),
    Mongoose = mongoInstance,
    elasticSearchURL = env.get("FOUNDELASTICSEARCH_URL") ||
    env.get("BONSAI_URL") ||
    env.get("ELASTIC_SEARCH_URL");

  elasticSearchURL = url.parse(elasticSearchURL);

  // This is a copy of https://github.com/chriso/node-validator/blob/master/lib/validators.js#L29-L32 which
  // is used for "isUrl" with mongoose-validator. Modified to accept underscores in the hostname.
  var urlregex = new RegExp("^(?!mailto:)(?:(?:https?|ftp):\\/\\/)?(?:\\S+(?::\\S*)" +
    "?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[" +
    "0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\_\\u00a1-" +
    "\\uffff0-9]+-?)*[a-z\\_\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*" +
    "[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d" +
    "{2,5})?(?:\\/[^\\s]*)?(?:\\?\\S*)?$", "i"
  );

  mongooseValidator.extend("isURL", function () {
    var str = this.str;
    return str.length < 2083 && str.match(urlregex);
  });

  var Timestamp = {
      type: Number,
      es_type: "long",
      es_indexed: true,
      es_index: "not_analyzed"
    },

    reportSchema = new Mongoose.Schema({
      userId: Number
    }),

    likeSchema = new Mongoose.Schema({
      userId: Number
    });

  // Schema
  var schema = new Mongoose.Schema({
    url: {
      type: String,
{'fraction_non_alphanumeric': 0.23959172710179963, 'fraction_numerical': 0.037066881547139406, 'mean_word_length': 3.069945355191257, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '1412063', 'n_tokens_mistral': 1515, 'n_tokens_neox': 1471, 'n_words': 251}