Skip to content

Instantly share code, notes, and snippets.

View geraldhumphries's full-sized avatar
🏎️

Gerald Humphries geraldhumphries

🏎️
View GitHub Profile
@geraldhumphries
geraldhumphries / Entity.java
Created November 11, 2016 22:56
Elasticsearch autocomplete impementation in JHipster
@Document(indexName = "entity")
@Setting(settingPath = "/config/elasticsearch/setting/autocomplete.json")
public class Entity implements Serializable {
@Column(name = "name")
@MultiField(
mainField = @Field(type = FieldType.String),
otherFields = {
@NestedField(
@geraldhumphries
geraldhumphries / entities.html
Created January 25, 2016 00:35
Query param pagination without resolve
<form name="searchForm" class="form-inline">
<div class="form-group">
<div class="input-group">
<input type="text" class="form-control" ng-model="searchQuery" id="searchQuery" placeholder="query">
<span class="input-group-btn">
<button class="btn btn-info" ng-click="search(searchQuery)">
<span class="glyphicon glyphicon-search"></span>
</button>
</span>
<span class="input-group-btn">
@geraldhumphries
geraldhumphries / entities.html
Last active July 3, 2017 07:15
Query param pagination with resolve
<form name="searchForm" class="form-inline">
<div class="form-group">
<div class="input-group">
<input type="text" class="form-control" ng-model="searchQuery" id="searchQuery" placeholder="query">
<span class="input-group-btn">
<button class="btn btn-info" ng-click="search(searchQuery)">
<span class="glyphicon glyphicon-search"></span>
</button>
</span>
<span class="input-group-btn">
@geraldhumphries
geraldhumphries / entity-dialog.controller.js
Created December 19, 2015 18:26
JHipster autocomplete combobox
$scope.loadOtherEntities = function(searchQuery) {
if (searchQuery){
OtherEntitySearch.query({query: '*' + searchQuery + '*'}, function(result) {
$scope.otherEntities = result;
}, function(response) {
if(response.status === 404) {
$scope.otherEntities = OtherEntity.query({isActive: true});
}
});
} else {
@geraldhumphries
geraldhumphries / ElasticsearchIndexResource.java
Last active January 4, 2016 14:42
Elasticsearch Reindexer
package [package].web.rest;
import com.codahale.metrics.annotation.Timed;
import [package].security.AuthoritiesConstants;
import [package].security.SecurityUtils;
import [package].service.ElasticsearchIndexService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
@And({@Spec(path = "field1", spec = In.class),
@Spec(path = "field2", spec = In.class),
@Spec(path = "fetch", spec = FetchSpecification.class, constVal = {"lazyRelationship1", "lazyRelationship2"})})
Specification<Entity> entitySpec,
@geraldhumphries
geraldhumphries / EntityResource.java
Last active January 15, 2016 05:26
JHipster search pagination
/**
* SEARCH /_search/entities/:query -> search for the entity corresponding
* to the query.
*/
@RequestMapping(value = "/_search/entities/{query}",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public ResponseEntity<List<Entity>> searchEntities(@PathVariable String query, Pageable pageable) throws URISyntaxException {
Page<Entity> page = truckSearchRepository.search(queryStringQuery(query), pageable);
@geraldhumphries
geraldhumphries / entities.html
Last active November 11, 2015 15:46
sort directive
<tr jh-sort="predicate" ascending="reverse" callback="loadAll">
<th jh-sort-by="id" translate="global.field.id">ID</th>
<th jh-sort-by="testField" translate="jhipsterApp.test123.testField">TestField</th>
<th jh-sort-by="point.id" translate="jhipsterApp.test123.point">point</th>
<th jh-sort-by="address.id" translate="jhipsterApp.test123.address">address</th>
<th></th>
</tr>
$scope.predicate = 'id';
$scope.reverse = true;
$scope.loadAll = function() {
Client.query({page: $scope.page, size: 20, sort: $scope.predicate + ',' + ($scope.reverse ? 'asc' : 'desc')}, function(result, headers) {
$scope.links = ParseLinks.parse(headers('link'));
$scope.clients = result;
});
};