diff --git a/server/djrandom/frontend/api_views.py b/server/djrandom/frontend/api_views.py index 80eb5f03632adc120b90f30fb7d88f9abdac0ee5..7b19685aacda620f0357838abf76f1a4203cbdb1 100644 --- a/server/djrandom/frontend/api_views.py +++ b/server/djrandom/frontend/api_views.py @@ -160,9 +160,10 @@ def search_json(): @require_auth def more_like_these_json(): hashes = request.form.get('h', '').split(',') + n = int(request.form.get('n', 5)) results = [] if hashes: - results = svcs['searcher'].more_like_these(hashes) + results = svcs['searcher'].more_like_these(hashes, n) return jsonify(results=results) diff --git a/server/djrandom/frontend/search.py b/server/djrandom/frontend/search.py index 720b631c185a21fcbdc57148edfd4637800eb3e2..9f96651b332fc103de39c6f522eb0ac57aaadba2 100644 --- a/server/djrandom/frontend/search.py +++ b/server/djrandom/frontend/search.py @@ -14,11 +14,11 @@ class Searcher(object): for doc in results.results: yield doc['score'], doc['id'] - def more_like_these(self, hashes): + def more_like_these(self, hashes, n=5): """Return a set of hashes that are related to the ones provided.""" query_str = ' OR '.join('(id:%s)' % x for x in hashes) results = self.solr.select( - q=query_str, fields='score,id', + q=query_str, fields='score,id', rows=n, mlt='true', mlt_fl='text', mlt_mindf=1, mlt_mintf=1) # Parse and uniq-ify the results. diff --git a/server/djrandom/frontend/static/js/djr/backend.js b/server/djrandom/frontend/static/js/djr/backend.js index 490f28bb0ff9e0113dd51280dcc168cad280cf43..a499b25bc1a1aa88db9d12905862879e20db6979 100644 --- a/server/djrandom/frontend/static/js/djr/backend.js +++ b/server/djrandom/frontend/static/js/djr/backend.js @@ -65,10 +65,10 @@ djr.Backend.prototype.search = function(query, callback, ctx) { * @param {function} callback Callback function. * @param {Object} ctx Callback context. */ -djr.Backend.prototype.moreLikeThese = function(uuids, callback, ctx) { +djr.Backend.prototype.moreLikeThese = function(n, uuids, callback, ctx) { wrap_with_loader( {url: '/json/morelikethese', - data: {'h': uuids.join(',')}, + data: {'h': uuids.join(','), 'n': n}, dataType: 'json', type: 'POST', context: ctx || this, diff --git a/server/djrandom/frontend/static/js/djr/player.js b/server/djrandom/frontend/static/js/djr/player.js index 534b445a66d554d4c375c099afc54d999411cb7d..b463d74962acf010c09a788432f7dfaeaa0d0a7a 100644 --- a/server/djrandom/frontend/static/js/djr/player.js +++ b/server/djrandom/frontend/static/js/djr/player.js @@ -175,7 +175,7 @@ djr.Player.prototype.extendCurrentPlaylist = function() { var player = this; var cur_songs = this.playlist.allSongs(); - this.backend.moreLikeThese(cur_songs, function(results) { + this.backend.moreLikeThese(5, cur_songs, function(results) { player.createChunk(results, 'suggestions'); }); }; @@ -198,7 +198,7 @@ djr.Player.prototype.moreLikeThis = function(sha1) { var player = this; var songs = [sha1]; - this.backend.moreLikeThese(songs, function(results) { + this.backend.moreLikeThese(10, songs, function(results) { player.createChunk(results, 'like that'); }); };