<commit_before>"use strict";

/**

 * Module dependencies

 */

var models  = require('../models');

var Sequelize = require("sequelize");
var env       = process.env.NODE_ENV || "development";
var config    = require(__dirname + '/../config/sequelize.json')[env];
var sequelize = new Sequelize(config.database, config.username, config.password, { "username": "postgres",
   "password": "<PASSWORD>",
   "database": "comet",
   "host": "127.0.0.1",
   "dialect": "postgres",
   "define": {
     "updatedAt": "updatedAt",
     "createdAt": "createdAt"},
     "pool": {
        "max": 10,
        "min": 1,
        "idle": 10000
      }
    });

/**
 * query to search for Project's Users
 * @type {String}
 */
var user_search_query = 'SELECT "U".id, "U".alias, "U"."firstName", "U"."lastName", "U".email, "U"."profilePicture"' +
                        ' FROM "Users" AS "U"' +
                        ' WHERE "U".id IN (' +
	                      '  SELECT "PU"."UserId" FROM "ProjectUsers" AS "PU" WHERE "PU"."ProjectId"= ? AND "PU".active = true' +
	                      ' )' +
                        ' AND "U".active = true' +
                        ' AND to_tsvector("firstName"||\' \'||"email"||\' \'||"alias"||\' \'||"lastName") @@ to_tsquery(?)';

/**
 * query to search for messages at common Channels
 * @type {String}
 */
var messages_search_common_channel_query = 'SELECT "M".id, "M".content, "M"."sentDateTimeUTC", "M"."UserId", "M"."MessageTypeId", "M"."ChannelId"' +
                            ' FROM "Messages" AS "M"' +
                            ' WHERE "M"."ChannelId" IN (:channel_ids) ' +
                            ' AND "M"."MessageTypeId" = 1 ' +
                            ' AND to_tsvector(\'spanish\', content) @@ to_tsquery(\'spanish\', :text) ' +
                            ' ORDER BY "M"."sentDateTimeUTC" DESC';

/**
 * query to search for messages at direct Channels
 * @type {String}
 */
var messages_search_direct_channel_query = 'SELECT "PM".id, "PM".content, "PM".channel, "PM"."sentDateTimeUTC", "PM"."ProjectId", ' +
                            '"PM"."OriginUserId", "PM"."DestinationUserId", "PM"."MessageTypeId"' +
                            ' FROM "PrivateMessages" AS "PM"' +
                            ' WHERE "PM"."MessageTypeId" = 1' +
                            ' AND "PM"."ProjectId" = :project_id' +
                            ' AND ("PM"."OriginUserId" = :origin_user_id OR "PM"."DestinationUserId" = :destination_user_id)' +
                            ' AND to_tsvector(\'spanish\', content) @@ to_tsquery(\'spanish\', :text)' +
                            ' ORDER BY "PM"."sentDateTimeUTC" DESC';

/**
 * query to search for messages at a single direct Channels
 * @type {String}<commit_msg>Buscador: actualizo query de busqueda de usuarios para trabajar con el nuevo campo "searcheable_text"<commit_after>"use strict";

/**

 * Module dependencies

 */

var models  = require('../models');

var Sequelize = require("sequelize");
var env       = process.env.NODE_ENV || "development";
var config    = require(__dirname + '/../config/sequelize.json')[env];
var sequelize = new Sequelize(config.database, config.username, config.password, { "username": "postgres",
   "password": "<PASSWORD>",
   "database": "comet",
   "host": "127.0.0.1",
   "dialect": "postgres",
   "define": {
     "updatedAt": "updatedAt",
     "createdAt": "createdAt"},
     "pool": {
        "max": 10,
        "min": 1,
        "idle": 10000
      }
    });

/**
 * query to search for Project's Users
 * @type {String}
 */
var user_search_query = 'SELECT "U".id, "U".alias, "U"."firstName", "U"."lastName", "U".email, "U"."profilePicture"' +
                        ' FROM "Users" AS "U"' +
                        ' WHERE "U".id IN (' +
	                      '  SELECT "PU"."UserId" FROM "ProjectUsers" AS "PU" WHERE "PU"."ProjectId"= ? AND "PU".active = true' +
	                      ' )' +
                        ' AND "U".active = true' +
                        ' AND to_tsvector("searchable_text") @@ to_tsquery(?)';

/**
 * query to search for messages at common Channels
 * @type {String}
 */
var messages_search_common_channel_query = 'SELECT "M".id, "M".content, "M"."sentDateTimeUTC", "M"."UserId", "M"."MessageTypeId", "M"."ChannelId"' +
                            ' FROM "Messages" AS "M"' +
                            ' WHERE "M"."ChannelId" IN (:channel_ids) ' +
                            ' AND "M"."MessageTypeId" = 1 ' +
                            ' AND to_tsvector(\'spanish\', content) @@ to_tsquery(\'spanish\', :text) ' +
                            ' ORDER BY "M"."sentDateTimeUTC" DESC';

/**
 * query to search for messages at direct Channels
 * @type {String}
 */
var messages_search_direct_channel_query = 'SELECT "PM".id, "PM".content, "PM".channel, "PM"."sentDateTimeUTC", "PM"."ProjectId", ' +
                            '"PM"."OriginUserId", "PM"."DestinationUserId", "PM"."MessageTypeId"' +
                            ' FROM "PrivateMessages" AS "PM"' +
                            ' WHERE "PM"."MessageTypeId" = 1' +
                            ' AND "PM"."ProjectId" = :project_id' +
                            ' AND ("PM"."OriginUserId" = :origin_user_id OR "PM"."DestinationUserId" = :destination_user_id)' +
                            ' AND to_tsvector(\'spanish\', content) @@ to_tsquery(\'spanish\', :text)' +
                            ' ORDER BY "PM"."sentDateTimeUTC" DESC';

/**
 * query to search for messages at a single direct Channels
 * @type {String}
{'fraction_non_alphanumeric': 0.1763646189875698, 'fraction_numerical': 0.005764727076202486, 'mean_word_length': 2.012479652740098, 'pattern_counts': {'":': 24, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1328384', 'n_tokens_mistral': 1760, 'n_tokens_neox': 1649, 'n_words': 383}