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

search query start page from 1 (configured as a variable and can be #379

Merged
merged 3 commits into from
Jun 18, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import eu.europeana.annotation.client.model.result.AnnotationSearchResults;
import eu.europeana.annotation.client.model.result.WhitelistOperationResponse;
import eu.europeana.annotation.definitions.model.Annotation;
import eu.europeana.annotation.definitions.model.search.Query;
import eu.europeana.annotation.definitions.model.search.SearchProfiles;
import eu.europeana.annotation.definitions.model.search.result.AnnotationPage;
import eu.europeana.annotation.definitions.model.vocabulary.WebAnnotationFields;
Expand Down Expand Up @@ -668,13 +669,13 @@ private String buildUrl(String query, String qf, String sort, String sortOrder,
if (StringUtils.isNotEmpty(page)) {
url += "&page=" + page;
} else {
url += "&page=0";
url += "&page=" + Query.DEFAULT_PAGE;
}

if (StringUtils.isNotEmpty(pageSize)) {
url += "&pageSize=" + pageSize;
} else {
url += "&pageSize=10";
url += "&pageSize=" + Query.DEFAULT_PAGE_SIZE;
}

if (StringUtils.isNotEmpty(language)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import eu.europeana.annotation.client.config.ClientConfiguration;
import eu.europeana.annotation.client.integration.webanno.BaseWebAnnotationDataSetTest;
import eu.europeana.annotation.definitions.model.Annotation;
import eu.europeana.annotation.definitions.model.search.Query;
import eu.europeana.annotation.definitions.model.search.SearchProfiles;
import eu.europeana.annotation.definitions.model.search.result.AnnotationPage;
import eu.europeana.annotation.definitions.model.vocabulary.WebAnnotationFields;
Expand Down Expand Up @@ -76,10 +77,10 @@ public void testSearchAnnotationPaging() throws Exception {
assertNotNull(annPg, "AnnotationPage must not be null");
//there might be old annotations of failing tests in the database
assertTrue(TOTAL_IN_COLLECTION <= annPg.getTotalInCollection());
assertEquals(annPg.getCurrentPage(), 0);
assertEquals(annPg.getCurrentPage(), Query.DEFAULT_PAGE);
assertEquals(TOTAL_IN_PAGE, annPg.getTotalInPage());
assertEquals(TOTAL_IN_PAGE, annPg.getItems().getResultSize());
assertNextPageNumber(annPg, 1);
assertNextPageNumber(annPg, Query.DEFAULT_PAGE + 1);

// second page
String npUri = annPg.getNextPageUri();
Expand All @@ -93,13 +94,13 @@ public void testSearchAnnotationPaging() throws Exception {
String nextCurrentPageUri = secondAnnoPg.getNextPageUri();
log.debug("nextCurrentPageUri" + nextCurrentPageUri);
assertNotNull(secondAnnoPg);
assertEquals(secondAnnoPg.getCurrentPage(), 1);
assertNextPageNumber(secondAnnoPg, 2);
assertEquals(secondAnnoPg.getCurrentPage(), Query.DEFAULT_PAGE + 1);
assertNextPageNumber(secondAnnoPg, Query.DEFAULT_PAGE + 2);
assertEquals(TOTAL_IN_PAGE, secondAnnoPg.getTotalInPage());
assertEquals(TOTAL_IN_PAGE, secondAnnoPg.getItems().getResultSize());

// last page
int lastPageNum = (int)Math.ceil((TOTAL_IN_COLLECTION - 1) / TOTAL_IN_PAGE);
int lastPageNum = (int)Math.ceil(1.0 * TOTAL_IN_COLLECTION / TOTAL_IN_PAGE) + Query.DEFAULT_PAGE - 1;
AnnotationPage lastPage = annSearchApi.searchAnnotations(VALUE_ALL, Integer.toString(lastPageNum), Integer.toString(TOTAL_IN_PAGE), null, null);
assertEquals(lastPage.getCurrentPage(), lastPageNum);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import eu.europeana.annotation.definitions.model.Annotation;
import eu.europeana.annotation.definitions.model.agent.impl.EdmAgent;
import eu.europeana.annotation.definitions.model.body.impl.EdmAgentBody;
import eu.europeana.annotation.definitions.model.search.Query;
import eu.europeana.annotation.definitions.model.search.SearchProfiles;
import eu.europeana.annotation.definitions.model.search.result.AnnotationPage;
import eu.europeana.annotation.definitions.model.vocabulary.MotivationTypes;
Expand Down Expand Up @@ -133,7 +134,7 @@ public void testSearchDereferencedAnnotation() throws Exception {
assertNotNull(annPg, "AnnotationPage must not be null");
//there must be annotations in database after initial insert in this test class
assertTrue(0 <= annPg.getTotalInCollection());
assertEquals(annPg.getCurrentPage(), 0);
assertEquals(annPg.getCurrentPage(), Query.DEFAULT_PAGE);
for (Annotation foundAnnotation : annPg.getAnnotations()) {
log.info(foundAnnotation.getIdentifier());
log.info(foundAnnotation.getBody().getHttpUri());
Expand All @@ -156,7 +157,7 @@ public void testSearchDereferencedAnnotationMultiLanguage() throws Exception {
assertNotNull(annPg, "AnnotationPage must not be null");
//there must be annotations in database after initial insert in this test class
assertTrue(0 <= annPg.getTotalInCollection());
assertEquals(annPg.getCurrentPage(), 0);
assertEquals(annPg.getCurrentPage(), Query.DEFAULT_PAGE);
for (Annotation foundAnnotation : annPg.getAnnotations()) {
log.info(foundAnnotation.getIdentifier());
log.info(foundAnnotation.getBody().getHttpUri());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public interface Query {
/**
* Default start parameter for Solr
*/
public static final int DEFAULT_PAGE = 0;
public static final int DEFAULT_PAGE = 1;
/**
* Default number of items in the SERP
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,15 @@ protected SolrQuery toSolrQuery(Query searchQuery) {
solrQuery.setFacetMinCount(1);
solrQuery.setFacetLimit(SolrAnnotationConstants.DEFAULT_FACET_LIMIT);
}

if (searchQuery.getSort() != null) {
solrQuery.setSort(searchQuery.getSort(), SolrQuery.ORDER.valueOf(searchQuery.getSortOrder()));
}

solrQuery.setFields(searchQuery.getViewFields());
solrQuery.setSort(searchQuery.getSort(), SolrQuery.ORDER.valueOf(searchQuery.getSortOrder()));
}

// searchQuery.setStart(page>0? page -1: page);
// searchQuery.setRows(Math.min(rows, Query.MAX_PAGE_SIZE));
solrQuery.setStart(searchQuery.getPageNr() * searchQuery.getPageSize());
solrQuery.setFields(searchQuery.getViewFields());

final int solrPageNr = searchQuery.getPageNr() - Query.DEFAULT_PAGE;
solrQuery.setStart(solrPageNr * searchQuery.getPageSize());
solrQuery.setRows(searchQuery.getPageSize());

return solrQuery;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import eu.europeana.annotation.definitions.model.Annotation;
import eu.europeana.annotation.definitions.model.search.Query;
import eu.europeana.annotation.definitions.model.search.result.AnnotationPage;
import eu.europeana.annotation.definitions.model.vocabulary.MotivationTypes;
import eu.europeana.annotation.definitions.model.vocabulary.WebAnnotationFields;
Expand Down Expand Up @@ -242,13 +243,13 @@ public static String buildUrl(String query, String[] qf, String[] facets, String
if (StringUtils.isNotEmpty(page)) {
url += "&page=" + page;
} else {
url += "&page=0";
url += "&page=" + Query.DEFAULT_PAGE;
}

if (StringUtils.isNotEmpty(pageSize)) {
url += "&pageSize=" + pageSize;
} else {
url += "&pageSize=10";
url += "&pageSize=" + Query.DEFAULT_PAGE_SIZE;
}

if (StringUtils.isNotEmpty(language)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import eu.europeana.annotation.definitions.model.body.impl.TextBody;
import eu.europeana.annotation.definitions.model.entity.impl.EdmPlace;
import eu.europeana.annotation.definitions.model.graph.Graph;
import eu.europeana.annotation.definitions.model.search.Query;
import eu.europeana.annotation.definitions.model.search.SearchProfiles;
import eu.europeana.annotation.definitions.model.search.result.AnnotationPage;
import eu.europeana.annotation.definitions.model.target.Target;
Expand Down Expand Up @@ -108,10 +109,10 @@ public void testSearchAnnotationPaging() throws Exception {
assertNotNull(annPg, "AnnotationPage must not be null");
// there might be old annotations of failing tests in the database
assertTrue(TOTAL_IN_COLLECTION <= annPg.getTotalInCollection());
assertEquals(annPg.getCurrentPage(), 0);
assertEquals(annPg.getCurrentPage(), Query.DEFAULT_PAGE);
assertEquals(TOTAL_IN_PAGE, annPg.getTotalInPage());
assertEquals(TOTAL_IN_PAGE, annPg.getItems().getResultSize());
assertNextPageNumber(annPg, 1);
assertNextPageNumber(annPg, Query.DEFAULT_PAGE+1);

// second page
String npUri = annPg.getNextPageUri();
Expand All @@ -128,13 +129,13 @@ public void testSearchAnnotationPaging() throws Exception {
String nextCurrentPageUri = secondAnnoPg.getNextPageUri();
log.debug("nextCurrentPageUri" + nextCurrentPageUri);
assertNotNull(secondAnnoPg);
assertEquals(secondAnnoPg.getCurrentPage(), 1);
assertNextPageNumber(secondAnnoPg, 2);
assertEquals(secondAnnoPg.getCurrentPage(), Query.DEFAULT_PAGE+1);
assertNextPageNumber(secondAnnoPg, Query.DEFAULT_PAGE+2);
assertEquals(TOTAL_IN_PAGE, secondAnnoPg.getTotalInPage());
assertEquals(TOTAL_IN_PAGE, secondAnnoPg.getItems().getResultSize());

// last page
int lastPageNum = (int) Math.ceil((TOTAL_IN_COLLECTION - 1) / TOTAL_IN_PAGE);
int lastPageNum = ((int) Math.ceil(1.0 * TOTAL_IN_COLLECTION / TOTAL_IN_PAGE)) + Query.DEFAULT_PAGE - 1;
AnnotationPage lastPage = searchAnnotationsAddQueryField(query, Integer.toString(lastPageNum),
Integer.toString(TOTAL_IN_PAGE), null, null, SearchProfiles.STANDARD.toString(), null);
assertEquals(lastPage.getCurrentPage(), lastPageNum);
Expand All @@ -161,7 +162,7 @@ public void testSearchAnyAnnotation() throws Exception {
// SearchProfiles.STANDARD);
assertNotNull(annPg, "AnnotationPage must not be null");
// there might be old annotations of failing tests in the database
assertEquals(annPg.getCurrentPage(), 0);
assertEquals(annPg.getCurrentPage(), Query.DEFAULT_PAGE);

List<? extends Annotation> annos = annPg.getAnnotations();

Expand Down Expand Up @@ -1032,7 +1033,7 @@ public void testSearchDereferencedAnnotation() throws Exception {
assertNotNull(annPg, "AnnotationPage must not be null");
// there must be annotations in database after initial insert in this test class
assertTrue(0 <= annPg.getTotalInCollection());
assertEquals(annPg.getCurrentPage(), 0);
assertEquals(annPg.getCurrentPage(), Query.DEFAULT_PAGE);
for (Annotation foundAnnotation : annPg.getAnnotations()) {
log.info(foundAnnotation.getIdentifier());
log.info(foundAnnotation.getBody().getHttpUri());
Expand Down Expand Up @@ -1060,7 +1061,7 @@ public void testSearchDereferencedAnnotationMultiLanguage() throws Exception {
assertNotNull(annPg, "AnnotationPage must not be null");
// there must be annotations in database after initial insert in this test class
assertTrue(0 <= annPg.getTotalInCollection());
assertEquals(annPg.getCurrentPage(), 0);
assertEquals(annPg.getCurrentPage(), Query.DEFAULT_PAGE);
for (Annotation foundAnnotation : annPg.getAnnotations()) {
log.info(foundAnnotation.getIdentifier());
log.info(foundAnnotation.getBody().getHttpUri());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,14 @@ public AnnotationPage search(Query query, HttpServletRequest request) throws Htt
String currentPageUrl = buildPageUrl(collectionUrl, currentPage, query.getPageSize());
protocol.setCurrentPageUri(currentPageUrl);

if (currentPage > 0) {
if (currentPage > Query.DEFAULT_PAGE) {
String prevPage = buildPageUrl(collectionUrl, currentPage - 1, query.getPageSize());
protocol.setPrevPageUri(prevPage);
}

// if current page is not the last one
boolean isLastPage = protocol.getTotalInCollection() <= (currentPage + 1) * query.getPageSize();
final int nextPageStartIndex = (currentPage - Query.DEFAULT_PAGE + 1) * query.getPageSize();
boolean isLastPage = protocol.getTotalInCollection() <= nextPageStartIndex;
if (!isLastPage) {
String nextPage = buildPageUrl(collectionUrl, currentPage + 1, query.getPageSize());
protocol.setNextPageUri(nextPage);
Expand Down Expand Up @@ -147,18 +148,10 @@ private String buildCollectionUrl(Query query, HttpServletRequest request) {
queryString +=
("&" + WebAnnotationFields.PARAM_PROFILE + "=" + query.getSearchProfile().toString());

String result = configuration.getAnnoApiEndpoint() + "/search?";
String url = configuration.getAnnoApiEndpoint() + "/search?";
url += queryString;

// try {
// result += URLEncoder.encode(queryString, StandardCharsets.UTF_8.toString());
// } catch (UnsupportedEncodingException e) {
// logger.log(Level.ERROR, "The UnsupportedEncodingException during the URL encoding of the
// string.", e);
// result += queryString;
// }
result += queryString;

return result;
return url;
}

protected String removeParam(final String queryParam, String queryParams) {
Expand Down Expand Up @@ -187,7 +180,7 @@ public Query buildSearchQuery(String queryString, String[] filters, String[] fac

Query searchQuery = new QueryImpl();
searchQuery.setQuery(queryString);
if (pageNr < 0)
if (pageNr < Query.DEFAULT_PAGE)
searchQuery.setPageNr(Query.DEFAULT_PAGE);
else
searchQuery.setPageNr(pageNr);
Expand Down
Loading