-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsearchResults.js
39 lines (37 loc) · 1.18 KB
/
searchResults.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict';
angular.module('solrAngularDemoApp')
.directive('searchResults', function () {
return {
scope: {
solrUrl: '=',
displayField: '=',
query: '&',
results: '&'
},
restrict: 'E',
controller: function($scope, $http) {
console.log('Searching for ' + $scope.query + ' at ' + $scope.solrUrl);
$scope.$watch('query', function() {
$http(
{method: 'JSONP',
url: $scope.solrUrl,
params:{'json.wrf': 'JSON_CALLBACK',
'q': $scope.query,
'fl': $scope.displayField}
})
.success(function(data) {
var docs = data.response.docs;
console.log('search success!');
$scope.results.docs = docs;
}).error(function() {
console.log('Search failed!');
});
});
},
template: '<input ng-model="query" name="Search"></input>' +
'<h2>Search Results for {{query}}</h2>' +
'<span ng-repeat="doc in results.docs">' +
' <p>{{doc[displayField]}}</p>' +
'</span>'
};
});