[Search] Changed variable names

Because of the async funtion, changed
variable names in serach2 to make more clear.
This commit is contained in:
shale 2015-07-13 17:05:23 -07:00
parent b994b2a862
commit 75ce5cd0e9

View File

@ -29,7 +29,8 @@ define(function () {
// JSLint doesn't like underscore-prefixed properties, // JSLint doesn't like underscore-prefixed properties,
// so hide them here. // so hide them here.
var ID = "_id"; var ID = "_id",
SOURCE = "_source";
function SearchController($scope, $http, objectService, queryService, ROOT) { function SearchController($scope, $http, objectService, queryService, ROOT) {
@ -77,7 +78,7 @@ define(function () {
var term = document.getElementById("searchinput").value; var term = document.getElementById("searchinput").value;
// Get the data... // Get the data...
$http({ $scope.results = $http({
method: "GET", method: "GET",
url: ROOT + "/_search", url: ROOT + "/_search",
data: { data: {
@ -87,38 +88,38 @@ define(function () {
} }
} }
} }
}).then(function (raw) { }).then(function (rawResults) {
// ...then process the data // ...then process the data
var output = raw.data.hits.hits, var results = rawResults.data.hits.hits,
outputLength = output.length, resultsLength = results.length,
output,
id, id,
i; i;
console.log('raw', raw); console.log('raw', rawResults);
console.log('output, pre', output); console.log('results, pre', results);
for (i = 0; i < outputLength; i++) { for (i = 0; i < resultsLength; i++) {
// Get the object's ID // Get the object's ID
output[i] = output[i][ID]; results[i] = results[i][ID];
console.log('output [', i, ']', output[i]); console.log('output [', i, ']', output[i]);
// Get the object itself from its ID // Get the object itself from its ID
objectService.getObjects([ output[i] ]).then(function (obj) { objectService.getObjects([ results[i] ]).then(function (obj) {
output[i] = obj;
// Manually get the member name to get to the actual object // Manually get the member name to get to the actual object
for (var prop in output[i]) { for (var prop in obj) {
console.log('prop [', i, ']', output[i][prop]); console.log('prop [', i, ']', obj[prop]);
output[i] = output[i][prop]; output.push(obj[prop]);
debugger; debugger;
} }
}); });
console.log('results [', i, ']', results[i]);
console.log('output [', i, ']', output[i]); console.log('output [', i, ']', output[i]);
} }
console.log('results, post', results);
console.log('output, post', output); console.log('output, post', output);
// Don't need to return, just set scope's version return output;
$scope.results = output;
}); });
} }