diff --git a/backend/src/main/java/uk/ac/ebi/spot/ols/config/WebConfig.java b/backend/src/main/java/uk/ac/ebi/spot/ols/config/WebConfig.java index c67a52c02..ac29bff15 100644 --- a/backend/src/main/java/uk/ac/ebi/spot/ols/config/WebConfig.java +++ b/backend/src/main/java/uk/ac/ebi/spot/ols/config/WebConfig.java @@ -1,15 +1,21 @@ package uk.ac.ebi.spot.ols.config; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.web.PageableHandlerMethodArgumentResolver; import org.springframework.http.MediaType; import org.springframework.web.filter.CharacterEncodingFilter; +import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.servlet.config.annotation.*; import org.springframework.web.util.UrlPathHelper; +import java.util.List; + /** * @author Simon Jupp * @date 25/06/2015 @@ -25,6 +31,10 @@ public class WebConfig extends WebMvcConfigurerAdapter { * * @param configurer */ + + @Value("${ols.solr.max-rows:1000}") + private int maxPageSize; + @Override public void configurePathMatch(PathMatchConfigurer configurer) { // UrlPathHelper urlPathHelper = new UrlPathHelper(); @@ -53,6 +63,14 @@ public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/api/**").allowedOrigins("*").allowedHeaders("*").allowedMethods("GET"); } + @Override + public void addArgumentResolvers(List argumentResolvers) { + PageableHandlerMethodArgumentResolver resolver = new PageableHandlerMethodArgumentResolver(); + resolver.setFallbackPageable(PageRequest.of(0, maxPageSize)); + resolver.setMaxPageSize(maxPageSize); + argumentResolvers.add(resolver); + } + } diff --git a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/solr/OlsSolrClient.java b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/solr/OlsSolrClient.java index a1cb659e4..ad76dc067 100644 --- a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/solr/OlsSolrClient.java +++ b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/solr/OlsSolrClient.java @@ -17,6 +17,7 @@ import org.apache.solr.common.SolrDocument; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Component; @@ -33,14 +34,16 @@ public class OlsSolrClient { @NotNull - @org.springframework.beans.factory.annotation.Value("${ols.solr.host:http://localhost:8999}") - public String host = "http://localhost:8999"; + @org.springframework.beans.factory.annotation.Value("${ols.solr.host:http://localhost:8983}") + public String host = "http://localhost:8983"; private Gson gson = new Gson(); private static final Logger logger = LoggerFactory.getLogger(OlsSolrClient.class); - public static final int MAX_ROWS = 1000; + + @Value("${ols.solr.max-rows:1000}") + private int maxRows; public Map getCoreStatus() throws IOException { try (CloseableHttpClient httpClient = HttpClients.createDefault()) { @@ -113,7 +116,7 @@ public QueryResponse runSolrQuery(SolrQuery query, Pageable pageable) { if(pageable != null) { query.setStart((int)pageable.getOffset()); - query.setRows(pageable.getPageSize() > MAX_ROWS ? MAX_ROWS : pageable.getPageSize()); + query.setRows(pageable.getPageSize() > maxRows ? maxRows : pageable.getPageSize()); } logger.debug("solr rows: {} ", query.getRows()); @@ -143,7 +146,7 @@ public QueryResponse runSolrQuery(SolrQuery query, Pageable pageable) { public QueryResponse dispatchSearch(SolrQuery query, String core) throws IOException, SolrServerException { org.apache.solr.client.solrj.SolrClient mySolrClient = new HttpSolrClient.Builder(host + "/solr/" + core).build(); - final int rows = query.getRows().intValue() > MAX_ROWS ? MAX_ROWS : query.getRows().intValue(); + final int rows = query.getRows().intValue() > maxRows ? maxRows : query.getRows().intValue(); query.setRows(rows); QueryResponse qr = mySolrClient.query(query); mySolrClient.close(); diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index 6e85d0e17..03726d711 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -7,4 +7,7 @@ springdoc.swagger-ui.disable-swagger-default-url=true spring.mvc.throw-exception-if-no-handler-found=true spring.web.resources.add-mappings=false -server.error.whitelabel.enabled=false \ No newline at end of file +server.error.whitelabel.enabled=false + +# this is optional. This property will determine the size of result you get back from solr. By default its 1000 rows +ols.solr.max-rows=1000 \ No newline at end of file