<commit_before>/**
 * Middleware permettant de centraliser toutes les actions sur les coherences.
 * Source des middleware de coherence : ../coherences/<coherence-name>
 * 
 * @author : Kaenn
 */

var Q = require('q');
var ElasticsearchClient = require('../../Elasticsearch/ElasticsearchClient');
var ElasticsearchParser = require('../../Elasticsearch/ElasticsearchParser');

var method = ConsistencyManager.prototype;

/**
 * Constructeur
 */
function ConsistencyManager(name) {
	this._params=require("../consistency/"+name+"/params");
}





/**
 * Search incoherence
 * @param coherence
 * @param blacklist
 * @param justOne
 * @returns
 */
var getIncoherences=function(name,blacklist,justOne){
	var size=config.maxIncoherences;
	if(justOne) size=1;
	
	return ElasticsearchClient.search({
		"index" : name,
		"type" : "consistency",
		"body" : {
			"query" : {
				"match_all" : {}
			},
			"filter" : {
				"not" : {
					"terms" : { "id" : blacklist }
				}
			},
			"sort" : [
				{ "label" : "asc" }       
            ],
			"fields" : ["id","label"]
		},
		"size" : size
	}).then(function(body){
		return ElasticsearchParser.loadFromBodyFields(body);
	});
}

/**
 * Search responses of one elem
 */
var getResponses=function(name,id,label){
	return ElasticsearchClient.search({
		"index" : name,
		"type" : "consistency_responses",
		"body" : {
			"query" : {
				"or" : [
					{"term" : { "target.label" : label }},
					{"term" : { "target.id" : id }},
					{"term" : { "target.all" : true }}
				]
			},
			"sort" : [
				{ "label" : "asc" }    
	        ],
			"fields" :  ["response_id","response_label"]
		},
		"size" : 9999
	}).then(function(body){
		console.log(ElasticsearchParser.loadFromBodyFields(body));
	})
}

/**
 * Search all responses
 */
var getAllResponses=function(name){
	return ElasticsearchClient.search({
		"index" : name,
		"type" : "consistency_responses",
		"body" : {
			"query" : {
				"match_all" : {}
			},
			"sort" : [
				{ "label" : "asc" }    
	        ],
			"fields" : ["response_id","response_label"]
		},
		"size" : 9999
	}).then(function(body){
		console.log(ElasticsearchParser.loadFromBodyFields(body));
	})
}

/**
 * Search suggestion of one elem
 */
var getSuggestions=function(name,id,label){
	return ElasticsearchClient.search({
		"index" : name,
		"type" : "consistency_suggestions",
		"body" : {
			"query" : {
				"or" : [
					{"term" : { "target.label" : label }},
					{"term" : { "target.id" : id }},
					{"term" : { "target.all" : true }}
				]<commit_msg>GIN  correction erreur dans inversion<commit_after>/**
 * Middleware permettant de centraliser toutes les actions sur les coherences.
 * Source des middleware de coherence : ../coherences/<coherence-name>
 * 
 * @author : Kaenn
 */

var Q = require('q');
var ElasticsearchClient = require('../../Elasticsearch/ElasticsearchClient');
var ElasticsearchParser = require('../../Elasticsearch/ElasticsearchParser');

var method = ConsistencyManager.prototype;

/**
 * Constructeur
 */
function ConsistencyManager(name) {
	this._params=require("../consistency/"+name+"/params");
}





/**
 * Search incoherence
 * @param coherence
 * @param blacklist
 * @param justOne
 * @returns
 */
var getIncoherences=function(name,blacklist,justOne){
	var size=config.maxIncoherences;
	if(justOne) size=1;
	
	return ElasticsearchClient.search({
		"index" : "consistency_"+name,
		"type" : "consistency",
		"body" : {
			"query" : {
				"match_all" : {}
			},
			"filter" : {
				"not" : {
					"terms" : { "id" : blacklist }
				}
			},
			"sort" : [
				{ "label" : "asc" }       
            ],
			"fields" : ["id","label"]
		},
		"size" : size
	}).then(function(body){
		return ElasticsearchParser.loadFromBodyFields(body);
	});
}

/**
 * Search responses of one elem
 */
var getResponses=function(name,id,label){
	return ElasticsearchClient.search({
		"index" : "consistency_"+name,
		"type" : "consistency_responses",
		"body" : {
			"query" : {
				"or" : [
					{"term" : { "target.label" : label }},
					{"term" : { "target.id" : id }},
					{"term" : { "target.all" : true }}
				]
			},
			"sort" : [
				{ "label" : "asc" }    
	        ],
			"fields" :  ["response_id","response_label"]
		},
		"size" : 9999
	}).then(function(body){
		console.log(ElasticsearchParser.loadFromBodyFields(body));
	})
}

/**
 * Search all responses
 */
var getAllResponses=function(name){
	return ElasticsearchClient.search({
		"index" : "consistency_"+name,
		"type" : "consistency_responses",
		"body" : {
			"query" : {
				"match_all" : {}
			},
			"sort" : [
				{ "label" : "asc" }    
	        ],
			"fields" : ["response_id","response_label"]
		},
		"size" : 9999
	}).then(function(body){
		console.log(ElasticsearchParser.loadFromBodyFields(body));
	})
}

/**
 * Search suggestion of one elem
 */
var getSuggestions=function(name,id,label){
	return ElasticsearchClient.search({
		"index" : "consistency_"+name,
		"type" : "consistency_suggestions",
		"body" : {
			"query" : {
				"or" : [
					{"term" : { "target.label" : label }},
					{"term" : { "target.id" : id }},
					{"term" : { "target.all" : true }}
				]
{'fraction_non_alphanumeric': 0.188671875, 'fraction_numerical': 0.003515625, 'mean_word_length': 3.1975409836065576, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6605374', 'n_tokens_mistral': 2071, 'n_tokens_neox': 1807, 'n_words': 316}