Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add term size config #852

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions backend/src/main/java/uk/ac/ebi/spot/ols/config/WebConfig.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -53,6 +63,14 @@ public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/api/**").allowedOrigins("*").allowedHeaders("*").allowedMethods("GET");
}

@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
PageableHandlerMethodArgumentResolver resolver = new PageableHandlerMethodArgumentResolver();
resolver.setFallbackPageable(PageRequest.of(0, maxPageSize));
resolver.setMaxPageSize(maxPageSize);
argumentResolvers.add(resolver);
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<String,Object> getCoreStatus() throws IOException {
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 4 additions & 1 deletion backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
Loading