<commit_before>var Backbone = require('backbone');
var ReleaseModel = require('../models/release-model');
var _  = require('underscore');
_.str = require('underscore.string');


var Releases = Backbone.Collection.extend({

	model: ReleaseModel,
	currentSort: 'release_date',
	comparator: function(model1, model2){
		return model1.get('momented') > model2.get('momented') ? -1 : 1;
	},
	search : function(letters){
		if(letters == "") return this;
 
		var pattern = new RegExp(letters,"gi");
		var years = [];
		var releases = this.filter(function(item) {

			var searchString = item.getSearchData();
		  	var hit = pattern.test(searchString);
		  	
		  	if (hit) {
		  		var year = item.get('momented').year();
		  		if (years.lastIndexOf(year) === -1) {
		  			years.push(year);
		  		};
		  	};

		  	// should not be doing it like this
		  	item.set('visible', hit);
		});

		
	},
	getSimilarByTag: function(tags, ignore){
		var hits = [];

		if (tags && tags instanceof Array) {

			this.filter(function(item){

				if (item.get('cat') === ignore){
					return; // it is this release, no need to include
				};

				var itemTags = item.get('tags');
				var result = _.intersection(tags, itemTags);

				if (result.length) {
					// calc levenshtein distance between the intersection and the search array
					var dist = _.str.levenshtein(result.join(' '), tags.join(' '));
					if (Math.log(dist) < 1.5) { // this value needs tuning
						hits.push(item.toJSON());	
					} else {
						// console.log('nuhuh',Math.log(dist));
					}
				};
			});
		}

		return hits;
	},
	searchByTag: function(tags){
		var years = [];
		this.filter(function(item){
			var itemTags = item.get('tags');
			var result = _.intersection(tags, itemTags);

			var hit = result.length === tags.length;

			if (hit) {
		  		var year = item.get('momented').year();
		  		if (years.lastIndexOf(year) === -1) {
		  			years.push(year);
		  		};
		  	};

		  	// should return array of hits, not interact directly on the model
			item.set('visible',hit);
		});

		
	},
	getTags: function(){
		return _.unique(_.flatten(this.pluck('tags'))).sort();
	},
	getCountries: function(){
		return _.unique(_.flatten(this.pluck('country'))).sort();
	},
	getArtists: function(){
		return _.unique(this.pluck('artist')).sort(function(a,b){
			return a.toLowerCase() > b.toLowerCase() ? -1 : 1;
		});	
	},
	getByTag: function(tag){
		return  _(this.filter(function(data){
			return !!~(data.get('tags').indexOf(tag));
		}));
	}
});

module.exports = Releases;<commit_msg>maintain interface on collection search methods<commit_after>var Backbone = require('backbone');
var ReleaseModel = require('../models/release-model');
var _  = require('underscore');
_.str = require('underscore.string');


var Releases = Backbone.Collection.extend({

	model: ReleaseModel,
	currentSort: 'release_date',
	comparator: function(model1, model2){
		return model1.get('momented') > model2.get('momented') ? -1 : 1;
	},
	search : function(letters){
		if(letters == "") return this;
 
		var pattern = new RegExp(letters,"gi");
		var releases = this.filter(function(item) {

			var searchString = item.getSearchData();
		  	return pattern.test(searchString);
		  	
		});
		return new Releases(releases);
		
	},
	getSimilarByTag: function(tags, ignore){
		var hits = new Releases();

		if (tags && tags instanceof Array) {

			var releases = this.filter(function(item){

				if (item.get('cat') === ignore){
					return; // it is this release, no need to include
				};

				var itemTags = item.get('tags');
				var result = _.intersection(tags, itemTags);

				if (result.length) {
					// calc levenshtein distance between the intersection and the search array
					var dist = _.str.levenshtein(result.join(' '), tags.join(' '));
					if (Math.log(dist) < 1.5) { // this value needs tuning
						// hits.push(item.toJSON());	
						return true;
					} else {
						return false;
						// console.log('nuhuh',Math.log(dist));
					}
				};
			});
			hits.reset(releases);
		}

		return hits;

		
	},
	searchByTag: function(tags){
		var years = [];
		this.filter(function(item){
			var itemTags = item.get('tags');
			var result = _.intersection(tags, itemTags);

			var hit = result.length === tags.length;

			if (hit) {
		  		var year = item.get('momented').year();
		  		if (years.lastIndexOf(year) === -1) {
		  			years.push(year);
		  		};
		  	};

		  	// should return array of hits, not interact directly on the model
			item.set('visible',hit);
		});

		
	},
	getTags: function(){
		return _.unique(_.flatten(this.pluck('tags'))).sort();
	},
	getCountries: function(){
		return _.unique(_.flatten(this.pluck('country'))).sort();
	},
	getArtists: function(){
		return _.unique(this.pluck('artist')).sort(function(a,b){
			return a.toLowerCase() > b.toLowerCase() ? -1 : 1;
		});	
	},
	getByTag: function(tag){
		var hits = _(this.filter(function(data){
			return !!~(data.get('tags').indexOf(tag));
		})).value();

	return new Releases(hits);

	}
});

module.exports = Releases;
{'fraction_non_alphanumeric': 0.1749850864983098, 'fraction_numerical': 0.00457347385166037, 'mean_word_length': 3.2447257383966246, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '1848887', 'n_tokens_mistral': 1998, 'n_tokens_neox': 1669, 'n_words': 366}