0
0

added prefix search to beer-search example app

This commit is contained in:
Marty Schoch 2014-08-07 13:46:34 -04:00
parent 292af78b9e
commit a3ac85c0de
4 changed files with 45 additions and 0 deletions

View File

@ -39,6 +39,7 @@
<li><a href="/search/syntax/">Syntax Search</a></li>
<li><a href="/search/numeric_range/">Numeric Range Search</a></li>
<li><a href="/search/date_range/">Date Range Search</a></li>
<li><a href="/search/prefix/">Prefix Search</a></li>
<li><a href="/search/debug/">Debug</a></li>
</ul>
</div>

View File

@ -19,6 +19,7 @@ config(['$routeProvider', '$locationProvider', function($routeProvider, $locatio
$routeProvider.when('/search/syntax/', {templateUrl: '/static/partials/search/syntax.html', controller: 'SearchCtrl'});
$routeProvider.when('/search/numeric_range/', {templateUrl: '/static/partials/search/numeric_range.html', controller: 'SearchCtrl'});
$routeProvider.when('/search/date_range/', {templateUrl: '/static/partials/search/date_range.html', controller: 'SearchCtrl'});
$routeProvider.when('/search/prefix/', {templateUrl: '/static/partials/search/prefix.html', controller: 'SearchCtrl'});
$routeProvider.when('/search/debug/', {templateUrl: '/static/partials/debug.html', controller: 'DebugCtrl'});
$routeProvider.otherwise({redirectTo: '/overview'});
$locationProvider.html5Mode(true);

View File

@ -53,6 +53,24 @@ function SearchCtrl($scope, $http, $routeParams, $log, $sce) {
});
};
$scope.searchPrefix = function() {
$http.post('/api/search', {
"size": 10,
"explain": true,
"highlight":{},
"query": {
"prefix": $scope.prefix,
"field": $scope.field,
}
}).
success(function(data) {
$scope.processResults(data);
}).
error(function(data, code) {
});
};
$scope.searchNumericRange = function() {
$http.post('/api/search', {
"size": 10,

View File

@ -0,0 +1,25 @@
<h1 class="page-header">Prefix Search</h1>
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="inputField" class="col-sm-2 control-label">Field</label>
<div class="col-sm-10">
<select ng-model="field" id="inputField" class="form-control">
<option ng-repeat="fn in fieldNames">{{fn}}</option>
</select>
</div>
</div>
<div class="form-group">
<label for="inputPrefix" class="col-sm-2 control-label">Prefix</label>
<div class="col-sm-10">
<input ng-model="prefix" type="text" class="form-control" id="inputPrefix" placeholder="Prefix">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary" ng-click="searchPrefix()">Search</button>
</div>
</div>
</form>
<div ng-show="results" ng-include src="'/static/partials/search/results.html'">