Uploaded image for project: 'Spring Data for Apache Solr'
  1. Spring Data for Apache Solr
  2. DATASOLR-229

SimpleQuery sort fields grow unexpectedly whilst iterating through paginated result

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Trivial
    • Resolution: Unresolved
    • Affects Version/s: 1.3.2 (Evans SR2)
    • Fix Version/s: None
    • Component/s: Core
    • Labels:
    • Environment:
      OSX 10.10.2
      java version "1.8.0_25"
      Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
      Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

      Description

      When I add a sort and paginate through search results like below:

      final Sort s = new Sort(Sort.Direction.DESC, "PRICE");
      search.addSort(s);
      Pageable request = new PageRequest(0, 500);
      search.setPageRequest(request);
      while (request != null) {
      	final Page<UkCore> page = template.queryForPage(search, UkCore.class);
      	page.forEach(core -> {
      		System.out.println(String.format("id=%s, dist=%s price=%,d", core.id, core.distance,
      				core.price));
      	});
      	request = page.nextPageable();
      	if (request != null) {
      		search.setPageRequest(request);
      	}
      }
      

      Then the sort fields are unexpectedly grown. The culprit appears to be the method setPagerequest in SimpleQuery which adds the sort parameter from the pageable.

      @Override
      public final <T extends Query> T setPageRequest(Pageable pageable) {
      	Assert.notNull(pageable);
      	this.offset = pageable.getOffset();
      	this.rows = pageable.getPageSize();
      	return this.addSort(pageable.getSort());
      }
      

      Now, I don't know whether this is really a bug, but the behaviour is a bit unexpected and counterintuitive to me. The simple workaround is to set the next pageable like this

      request = page.nextPageable();
      if (request != null) {
      	search.setPageRequest(new PageRequest(request.getPageNumber(), request.getPageSize()));
      }
      

      Which is not a very elegant way of doing this but now the behaviour is as expected.

        Attachments

          Activity

            People

            Assignee:
            cstrobl Christoph Strobl
            Reporter:
            nguba Nico Guba
            Last updater:
            Francisco Spaeth
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: