Commit a31eb318 authored by Jean-Baptiste Nizet's avatar Jean-Baptiste Nizet
Browse files

refactor: rename agg parameter to aggregate

parent 208e9709
...@@ -41,7 +41,7 @@ public class SearchController { ...@@ -41,7 +41,7 @@ public class SearchController {
* Searches for the given query, and returns an aggregated page of results * Searches for the given query, and returns an aggregated page of results
* @param query the query (mandatory parameter) * @param query the query (mandatory parameter)
* @param page the requested page number, starting at 0. Defaults to 0 if not passed. * @param page the requested page number, starting at 0. Defaults to 0 if not passed.
* @param agg if true, the aggregated page's aggregations will be a non-empty array containing all the terms * @param aggregate if true, the aggregated page's aggregations will be a non-empty array containing all the terms
* aggregations allowing to refine the query. If false or omitted, the aggregations won't be loaded and the * aggregations allowing to refine the query. If false or omitted, the aggregations won't be loaded and the
* aggregations array in the result will be empty * aggregations array in the result will be empty
* @param parameters all the parameters, containing the refinements based on the aggregations. The names * @param parameters all the parameters, containing the refinements based on the aggregations. The names
...@@ -52,15 +52,14 @@ public class SearchController { ...@@ -52,15 +52,14 @@ public class SearchController {
*/ */
@GetMapping @GetMapping
public AggregatedPageDTO<GeneticResource> search(@RequestParam("query") String query, public AggregatedPageDTO<GeneticResource> search(@RequestParam("query") String query,
@RequestParam("agg") Optional<Boolean> agg, @RequestParam("aggregate") Optional<Boolean> aggregate,
@RequestParam("highlight") Optional<Boolean> highlight, @RequestParam("highlight") Optional<Boolean> highlight,
@RequestParam("page") Optional<Integer> page, @RequestParam("page") Optional<Integer> page,
@RequestParam MultiValueMap<String, String> parameters) { @RequestParam MultiValueMap<String, String> parameters) {
boolean aggregate = agg.orElse(false);
int requestedPage = page.orElse(0); int requestedPage = page.orElse(0);
validatePage(requestedPage); validatePage(requestedPage);
return AggregatedPageDTO.fromPage(geneticResourceDao.search(query, return AggregatedPageDTO.fromPage(geneticResourceDao.search(query,
aggregate, aggregate.orElse(false),
highlight.orElse(false), highlight.orElse(false),
createRefinementsFromParameters(parameters), createRefinementsFromParameters(parameters),
PageRequest.of(page.orElse(0), PAGE_SIZE))); PageRequest.of(page.orElse(0), PAGE_SIZE)));
......
...@@ -88,7 +88,7 @@ class SearchControllerTest { ...@@ -88,7 +88,7 @@ class SearchControllerTest {
mockMvc.perform(get("/api/genetic-resources") mockMvc.perform(get("/api/genetic-resources")
.param("query", query) .param("query", query)
.param("agg", "true")) .param("aggregate", "true"))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.number").value(0)) .andExpect(jsonPath("$.number").value(0))
.andExpect(jsonPath("$.content[0].identifier").value(resource.getId())) .andExpect(jsonPath("$.content[0].identifier").value(resource.getId()))
......
...@@ -41,7 +41,7 @@ describe('SearchService', () => { ...@@ -41,7 +41,7 @@ describe('SearchService', () => {
const aggregation = toAggregation('coo', ['France', 'Italy']); const aggregation = toAggregation('coo', ['France', 'Italy']);
const expectedResults = toSinglePage([resource], [aggregation]); const expectedResults = toSinglePage([resource], [aggregation]);
http.expectOne('/api/genetic-resources?query=Bacteria&page=0&highlight=true&agg=true').flush(expectedResults); http.expectOne('/api/genetic-resources?query=Bacteria&page=0&highlight=true&aggregate=true').flush(expectedResults);
expect(actualResults).toEqual(expectedResults); expect(actualResults).toEqual(expectedResults);
}); });
...@@ -70,7 +70,7 @@ describe('SearchService', () => { ...@@ -70,7 +70,7 @@ describe('SearchService', () => {
const aggregation = toAggregation('coo', ['France', 'Italy']); const aggregation = toAggregation('coo', ['France', 'Italy']);
const expectedResults = toSinglePage([resource], [aggregation]); const expectedResults = toSinglePage([resource], [aggregation]);
http.expectOne('/api/genetic-resources?query=Bacteria&page=0&highlight=true&agg=true&coo=France&coo=Italy&domain=Forest').flush(expectedResults); http.expectOne('/api/genetic-resources?query=Bacteria&page=0&highlight=true&aggregate=true&coo=France&coo=Italy&domain=Forest').flush(expectedResults);
expect(actualResults).toEqual(expectedResults); expect(actualResults).toEqual(expectedResults);
}); });
......
...@@ -27,7 +27,7 @@ export class SearchService { ...@@ -27,7 +27,7 @@ export class SearchService {
const params: { [key: string]: string | Array<string> } = { query, page, highlight: 'true' }; const params: { [key: string]: string | Array<string> } = { query, page, highlight: 'true' };
// if we need to fetch the aggregation, add the `agg` parameter // if we need to fetch the aggregation, add the `agg` parameter
if (aggregate) { if (aggregate) {
params.agg = 'true'; params.aggregate = 'true';
} }
// if we have aggregation values, add them as domain=Plantae&domain=... // if we have aggregation values, add them as domain=Plantae&domain=...
if (aggregationCriteria) { if (aggregationCriteria) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment