mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-01 20:00:13 +02:00
[0.9 api] use collection for search
This commit is contained in:
@@ -250,7 +250,7 @@ Tomahawk.Resolver = Tomahawk.extend(TomahawkResolver, {
|
|||||||
_convertUrls: function(results) {
|
_convertUrls: function(results) {
|
||||||
var that = this;
|
var that = this;
|
||||||
return results.map(function(r){
|
return results.map(function(r){
|
||||||
if(r.url) {
|
if(r && r.url) {
|
||||||
r.url = that._urlProtocol + '://' + r.url;
|
r.url = that._urlProtocol + '://' + r.url;
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
@@ -295,10 +295,22 @@ Tomahawk.Resolver = Tomahawk.extend(TomahawkResolver, {
|
|||||||
_adapter_search: function (qid, query)
|
_adapter_search: function (qid, query)
|
||||||
{
|
{
|
||||||
var that = this;
|
var that = this;
|
||||||
Promise.resolve(this.search({query:query})).then(function(results){
|
var collectionPromises = [];
|
||||||
Tomahawk.addTrackResults({
|
Tomahawk.collections.forEach(function(col) {
|
||||||
'qid': qid,
|
if(col.search)
|
||||||
'results': that._convertUrls(results)
|
collectionPromises.push(col.search({query: query}));
|
||||||
|
});
|
||||||
|
Promise.all(collectionPromises).then(function(collectionResults){
|
||||||
|
var merged = [];
|
||||||
|
return merged.concat.apply(merged,collectionResults);
|
||||||
|
}).then(function(collectionResults) {
|
||||||
|
Promise.resolve(that.search({query:query})).then(function(results){
|
||||||
|
Tomahawk.log(JSON.stringify(results));
|
||||||
|
Tomahawk.log(JSON.stringify(collectionResults));
|
||||||
|
Tomahawk.addTrackResults({
|
||||||
|
'qid': qid,
|
||||||
|
'results': that._convertUrls(results.concat(collectionResults))
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -1260,28 +1272,34 @@ Tomahawk.Collection = {
|
|||||||
for (var i = 0; i < that.statements.length; ++i)
|
for (var i = 0; i < that.statements.length; ++i)
|
||||||
{
|
{
|
||||||
var stmt = that.statements[i];
|
var stmt = that.statements[i];
|
||||||
var originalI = i;
|
|
||||||
tx.executeSql(stmt.statement, stmt.args,
|
tx.executeSql(stmt.statement, stmt.args,
|
||||||
function (tx, results) {
|
(function () {
|
||||||
that.stmtsToResolve--;
|
//A function returning a function to
|
||||||
if (typeof that.statements[originalI].map !== 'undefined')
|
//capture value of i
|
||||||
{
|
var originalI = i;
|
||||||
var map = that.statements[originalI].map;
|
return function (tx, results) {
|
||||||
that.results[originalI] = [];
|
if (typeof that.statements[originalI].map !== 'undefined')
|
||||||
for (var ii = 0; ii < results.rows.length; ii++) {
|
{
|
||||||
that.results[originalI].push(map(
|
var map = that.statements[originalI].map;
|
||||||
results.rows.item(ii)
|
that.results[originalI] = [];
|
||||||
));
|
Tomahawk.log('originalI ' + originalI);
|
||||||
|
for (var ii = 0; ii < results.rows.length; ii++) {
|
||||||
|
that.results[originalI].push(map(
|
||||||
|
results.rows.item(ii)
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
else
|
that.results[originalI] = results;
|
||||||
that.results[originalI] = results;
|
that.stmtsToResolve--;
|
||||||
if(that.stmtsToResolve == 0)
|
if(that.stmtsToResolve == 0)
|
||||||
{
|
{
|
||||||
that.statements = [];
|
that.statements = [];
|
||||||
resolve(that.results);
|
Tomahawk.log(JSON.stringify(that.results));
|
||||||
}
|
resolve(that.results);
|
||||||
}, function (tx, error) {
|
}
|
||||||
|
};
|
||||||
|
})(), function (tx, error) {
|
||||||
Tomahawk.log("Error in tx.executeSql: " + error.code + " - "
|
Tomahawk.log("Error in tx.executeSql: " + error.code + " - "
|
||||||
+ error.message);
|
+ error.message);
|
||||||
that.statements = [];
|
that.statements = [];
|
||||||
@@ -1570,12 +1588,10 @@ Tomahawk.Collection = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
resolve: function(params) {
|
_fuzzyIndexIdsToTracks: function(resultIds, id) {
|
||||||
var id = params.id;
|
var that = this;
|
||||||
if(typeof id === 'undefined')
|
if(typeof id === 'undefined')
|
||||||
id = this.settings.id;
|
id = this.settings.id;
|
||||||
Tomahawk.log('called resolve');
|
|
||||||
var resultIds = Tomahawk.resolveFromFuzzyIndex(params.artist, params.album, params.track);
|
|
||||||
var t = new Tomahawk.Collection.Transaction(this, id);
|
var t = new Tomahawk.Collection.Transaction(this, id);
|
||||||
return t.beginTransaction().then(function () {
|
return t.beginTransaction().then(function () {
|
||||||
var mapFn = function(row) {
|
var mapFn = function(row) {
|
||||||
@@ -1619,12 +1635,22 @@ Tomahawk.Collection = {
|
|||||||
return e[0];
|
return e[0];
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
return this.tracks({});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
search: function() {
|
resolve: function(params) {
|
||||||
//TODO
|
var id = params.id;
|
||||||
Tomahawk.log('called search');
|
if(typeof id === 'undefined')
|
||||||
|
id = this.settings.id;
|
||||||
|
var resultIds = Tomahawk.resolveFromFuzzyIndex(params.artist, params.album, params.track);
|
||||||
|
return this._fuzzyIndexIdsToTracks(resultIds);
|
||||||
|
},
|
||||||
|
|
||||||
|
search: function(params) {
|
||||||
|
var id = params.id;
|
||||||
|
if(typeof id === 'undefined')
|
||||||
|
id = this.settings.id;
|
||||||
|
var resultIds = Tomahawk.searchFuzzyIndex(params.query);
|
||||||
|
return this._fuzzyIndexIdsToTracks(resultIds);
|
||||||
},
|
},
|
||||||
|
|
||||||
tracks: function (params, where) {
|
tracks: function (params, where) {
|
||||||
|
Reference in New Issue
Block a user