Implements a search
This commit is contained in:
@@ -108,3 +108,15 @@ body > .container-fluid {
|
|||||||
.album .album-ellipsis p:last-child{
|
.album .album-ellipsis p:last-child{
|
||||||
margin-bottom: 15px;
|
margin-bottom: 15px;
|
||||||
}
|
}
|
||||||
|
.search-result {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
.search-score {
|
||||||
|
position:absolute;
|
||||||
|
right:15px;
|
||||||
|
top:0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-result > h4 {
|
||||||
|
padding-top: 15px;
|
||||||
|
}
|
||||||
@@ -49,6 +49,7 @@
|
|||||||
<script src="/bower_components/angular/angular.min.js"></script>
|
<script src="/bower_components/angular/angular.min.js"></script>
|
||||||
<script src="/bower_components/angular-animate/angular-animate.min.js"></script>
|
<script src="/bower_components/angular-animate/angular-animate.min.js"></script>
|
||||||
<script src="/bower_components/angular-route/angular-route.min.js"></script>
|
<script src="/bower_components/angular-route/angular-route.min.js"></script>
|
||||||
|
<script src="/bower_components/angular-sanitize/angular-sanitize.min.js"></script>
|
||||||
<script src="/bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js"></script>
|
<script src="/bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js"></script>
|
||||||
<script src="/bower_components/angular-inview/angular-inview.js"></script>
|
<script src="/bower_components/angular-inview/angular-inview.js"></script>
|
||||||
<!-- inject:js -->
|
<!-- inject:js -->
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
<div responsive-ratio="$ctrl.ratio" ng-if="$ctrl.ratio > 0">
|
<div responsive-ratio="$ctrl.ratio" ng-if="$ctrl.ratio > 0">
|
||||||
<img class="img-responsive img-rounded" alt="{{$ctrl.album.titleDisplay}}" ng-src="{{$ctrl.album.CoverURL}}"/>
|
<img class="img-responsive img-rounded" alt="{{$ctrl.album.titleDisplay}}" ng-src="{{$ctrl.album.CoverURL}}"/>
|
||||||
<div class="over-img-rating">
|
<div class="over-img-rating">
|
||||||
<uib-rating ng-if="$ctrl.render" ng-model="$ctrl.album.Note" readonly="true"></uib-rating>
|
<uib-rating class="hidden-xs" ng-if="$ctrl.render" ng-model="$ctrl.album.Note" readonly="true"></uib-rating>
|
||||||
|
<p class="visible-xs" style="margin-bottom:0;"> {{$ctrl.album.Note}}/5.0 </p>
|
||||||
</div>
|
</div>
|
||||||
<div class="over-img-ref">{{$ctrl.album.ref}}</div>
|
<div class="over-img-ref">{{$ctrl.album.ref}}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -35,12 +35,41 @@ services.factory('albumService',['$http','$log','$q', function($http,$log,$q) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function search(terms) {
|
var keywordRegexp = /(\s+)|$/g;
|
||||||
var defer = $q.defer();
|
|
||||||
defer.reject('Search is not implemented');
|
function fuzzifyTerms(terms) {
|
||||||
return defer.promise;
|
return terms.replace(keywordRegexp,"~2 ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function processResult(res, timeOffset) {
|
||||||
|
res.took += timeOffset;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
function search(terms,from,fuzzify, previousTime) {
|
||||||
|
if (typeof fuzzify == 'undefined' ) {
|
||||||
|
fuzzify = true;
|
||||||
|
}
|
||||||
|
if (typeof previousTime == 'undefined' ) {
|
||||||
|
previousTime = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $http.post('/api/search', {
|
||||||
|
"size" : 10,
|
||||||
|
"from": from || 0,
|
||||||
|
"explain": false,
|
||||||
|
"highlight":{},
|
||||||
|
"fields": ["ID","série","collection","titre","éditeur","ref","description","Note"],
|
||||||
|
"query": {
|
||||||
|
"query": terms
|
||||||
|
}
|
||||||
|
}).then(function(response) {
|
||||||
|
if ( fuzzify == true && response.data.total_hits == 0) {
|
||||||
|
return search(fuzzifyTerms(terms),from,false,response.data.took);
|
||||||
|
}
|
||||||
|
return processResult(response.data,previousTime);
|
||||||
|
});
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
get: get,
|
get: get,
|
||||||
search: search
|
search: search
|
||||||
|
|||||||
@@ -1,2 +1,23 @@
|
|||||||
<h1> Votre recherche de '{{ terms }}' n'a pas abouti</h1>
|
<h3 class="text-center"> Votre recherche '{{terms}}' à donné {{response.total_hits}} résultats en {{inSecond(response.took)}} s</h3>
|
||||||
<h3>C'est toujours pas implémenté, couillon</h3>
|
|
||||||
|
<div class="row" ng-repeat="h in allHits">
|
||||||
|
<div class="col-xs-5 col-sm-3 album" >
|
||||||
|
<album album-id="h.id" ratio="0.95"> </album>
|
||||||
|
</div>
|
||||||
|
<div class="col-xs-7 col-sm-9 search-result">
|
||||||
|
<div class="search-score"> {{h.fields['ref']}} <span class="badge">Score: {{round4Dec(h.score)}} </span></div>
|
||||||
|
<h4> {{h.fields['série']}} - {{h.fields['titre']}} </h4>
|
||||||
|
<hr/>
|
||||||
|
<ul class="hidden-xs">
|
||||||
|
<li ng-repeat="(field,fragments) in h.fragments"><label>{{field}}</label>:
|
||||||
|
<ul>
|
||||||
|
<li ng-repeat="f in fragments" ng-bind-html="trustedFragment(f)"></li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row text-center" in-view="$inview&&loadMore()" ng-if="scrollMore">
|
||||||
|
Chargement ...
|
||||||
|
</div>
|
||||||
|
|||||||
@@ -1,12 +1,56 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('satbd.satellite.bar.views.search',[
|
angular.module('satbd.satellite.bar.views.search',[
|
||||||
'ngRoute'
|
'ngRoute',
|
||||||
|
'ngSanitize',
|
||||||
|
'satbd.satellite.bar.services',
|
||||||
|
'satbd.satellite.bar.components.album',
|
||||||
|
'angular-inview'
|
||||||
]).config(function($routeProvider) {
|
]).config(function($routeProvider) {
|
||||||
$routeProvider.when('/search', {
|
$routeProvider.when('/search', {
|
||||||
templateUrl: 'js/views/search/search.html',
|
templateUrl: 'js/views/search/search.html',
|
||||||
controller: 'SearchCtrl'
|
controller: 'SearchCtrl'
|
||||||
});
|
});
|
||||||
}).controller('SearchCtrl', function($scope,$routeParams) {
|
}).controller('SearchCtrl', function($scope,$routeParams,$log,$sce,albumService) {
|
||||||
$scope.terms=$routeParams.q;
|
$scope.terms=$routeParams.q;
|
||||||
|
$scope.scrollMore = false;
|
||||||
|
$scope.allHits = [];
|
||||||
|
|
||||||
|
$scope.pushHits = function (response) {
|
||||||
|
for ( var i = 0; i < response.hits.length; i++ ) {
|
||||||
|
$scope.allHits.push(response.hits[i]);
|
||||||
|
}
|
||||||
|
// stop scrolling if we have all hits
|
||||||
|
$scope.scrollMore = $scope.allHits.length < response.total_hits;
|
||||||
|
};
|
||||||
|
|
||||||
|
albumService.search($scope.terms).then( function(data) {
|
||||||
|
$scope.response = data;
|
||||||
|
$scope.pushHits(data);
|
||||||
|
});
|
||||||
|
|
||||||
|
$scope.loadMore = function () {
|
||||||
|
if ( !$scope.scrollMore || $scope.allHits.length >= $scope.response.total_hits) {
|
||||||
|
$scope.scrollMore = false;
|
||||||
|
$log.info('Done scrolling results');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$log.info('Scrolling more results');
|
||||||
|
|
||||||
|
albumService.search($scope.terms,$scope.allHits.length).then( function(data) {
|
||||||
|
$scope.pushHits(data);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.inSecond= function(bleveValue) {
|
||||||
|
return bleveValue / 1e6;
|
||||||
|
}
|
||||||
|
|
||||||
|
$scope.trustedFragment = function(f) {
|
||||||
|
return $sce.trustAsHtml(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
$scope.round4Dec = function(value) {
|
||||||
|
return Math.round(value * 10000) / 10000;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user