Skip to content

Commit

Permalink
#672 added path filter
Browse files Browse the repository at this point in the history
  • Loading branch information
limouri committed Sep 26, 2016
1 parent 4d2e7c1 commit da3bf7c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
Expand Down Expand Up @@ -84,9 +85,10 @@ public SearchResource(String elasticSearchConnectionUrl)
*
* @return The search results
*/
@RequestMapping(value = "/api/search/**/_search")
@RequestMapping(value = {"/api/search/**/_search","/api/search/**/_mget"})
@Timed
public ResponseEntity<String> search(@RequestBody String body, HttpMethod method,
public ResponseEntity<String> search(@RequestParam("filter_path") String filter,
@RequestBody String body, HttpMethod method,
@RequestHeader MultiValueMap<String, String> headers, HttpServletRequest request)
throws RestClientException, URISyntaxException {
headers.remove("authorization");
Expand All @@ -103,7 +105,7 @@ public ResponseEntity<String> search(@RequestBody String body, HttpMethod method

String completePath =
(String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
String path = completePath.replaceFirst("/api/search", "");
String path = completePath.replaceFirst("/api/search", "") + "?filter_path=" + filter;
ResponseEntity<String> response = restTemplate.exchange(connectionUrl + path, method,
new HttpEntity<>(body, headers), String.class);
return response;
Expand Down
115 changes: 55 additions & 60 deletions src/main/webapp/scripts/searchmanagement/services/search.dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,70 +6,65 @@ angular.module('metadatamanagementApp').service('SearchDao',
return {
search: function(queryterm, pageNumber, currentProject,
elasticsearchType, pageSize) {
var query = {};
var projectFilter;
query.index = 'metadata_' + Language.getCurrentInstantly();
query.type = elasticsearchType;
query.body = {};

//a query term
if (!CleanJSObjectService.isNullOrEmpty(queryterm)) {
query.body.query = {
'bool': {
'must': [{
'match': {
'allStringsAsNgrams': {
'query': queryterm,
'type': 'boolean',
'operator': 'AND',
'minimum_should_match': '100%',
'zero_terms_query': 'NONE'
}
}
}]
var query = {};
var projectFilter;
query.index = 'metadata_' + Language.getCurrentInstantly();
query.filterPath = '';
query.type = elasticsearchType;
query.body = {};
//a query term
if (!CleanJSObjectService.isNullOrEmpty(queryterm)) {
query.body.query = {
'bool': {
'must': [{
'match': {
'allStringsAsNgrams': {
'query': queryterm,
'type': 'boolean',
'operator': 'AND',
'minimum_should_match': '100%',
'zero_terms_query': 'NONE'
}
};

//no query term
} else {
query.body.query = {
'bool': {
'must': [
{'match_all': {}}
],
}
}]
}
};
//no query term
} else {
query.body.query = {
'bool': {
'must': [
{'match_all': {}}
],
}
};
}
//define from
query.body.from = (pageNumber - 1) * pageSize;
//define size
query.body.size = pageSize;
//aggregations if user is on the all tab
if (CleanJSObjectService.isNullOrEmpty(elasticsearchType)) {
//define aggregations
query.body.aggs = {
'countByType': {
'terms': {
'field': '_type'
}
};
}

//define from
query.body.from = (pageNumber - 1) * pageSize;

//define size
query.body.size = pageSize;

//aggregations if user is on the all tab
if (CleanJSObjectService.isNullOrEmpty(elasticsearchType)) {
//define aggregations
query.body.aggs = {
'countByType': {
'terms': {
'field': '_type'
}
}
};
}

//filter by projectId
if (!CleanJSObjectService.isNullOrEmpty(currentProject)) {
projectFilter = {
'term': {'dataAcquisitionProjectId': currentProject.id}
};
if (!query.body.query.bool.filter) {
query.body.query.bool.filter = [];
}
query.body.query.bool.filter.push(projectFilter);
};
}
//filter by projectId
if (!CleanJSObjectService.isNullOrEmpty(currentProject)) {
projectFilter = {
'term': {'dataAcquisitionProjectId': currentProject.id}
};
if (!query.body.query.bool.filter) {
query.body.query.bool.filter = [];
}
return ElasticSearchClient.search(query);
query.body.query.bool.filter.push(projectFilter);
}
return ElasticSearchClient.search(query);
}
};
});

0 comments on commit da3bf7c

Please sign in to comment.