Created
July 22, 2016 10:55
-
-
Save hadrienl/a5c254727f7ea68421d0071916a865b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
// First let's define the usual configuration variables for our index | |
var applicationId = 'latency'; | |
var apiKey = '249078a3d4337a8231f1665ec5a44966'; | |
var index = 'bestbuy'; | |
// Define the `AgoliaSearchHelper` module | |
angular.module('AlgoliaSearchHelper', ['ngSanitize']). | |
factory('Search', function() { | |
return new algoliasearch(applicationId, apiKey).initIndex(index); | |
}). | |
value('datastore', {}). | |
// Define the search-box | |
component('searchBox', { | |
template: '<input placeholder="Search.." class="search-box" ng-keyup="search()" ng-model="query"/>', | |
controller: function SearchBoxController($scope, Search, datastore) { | |
$scope.query = ''; | |
$scope.initRun = true; | |
$scope.search = function(e) { | |
Search.search($scope.query, function(success, content) { | |
console.log('newval', datastore); | |
datastore.hits = content.hits; | |
if ($scope.initRun) { | |
$scope.$apply(); | |
$scope.initRun = false; | |
} | |
}); | |
}; | |
$scope.search(); | |
} | |
}). | |
// Define the search-facets | |
component('searchFacets', { | |
template: '<div class="facet-list"></div>', | |
controller: function SearchFacetsController() {} | |
}). | |
// Define the search-results | |
component('searchResult', { | |
template: '<div class="hit results"><span ng-repeat="hit in datastore.hits"><div ng-bind-html="hit._highlightResult.name.value"></div></span></div>', | |
controller: function SearchResultController($scope, datastore) { | |
$scope.datastore = datastore; | |
} | |
}). | |
// Define the search-pagination | |
component('searchPagination', { | |
template: '<div class="pager">' + | |
'<button class="previous">previous</button>' + | |
'<span class="current-page"></span>' + | |
'<button class="next">Next</button>' + | |
'</div>', | |
controller: function SearchPaginationController() {} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment