diegoceccarelli commented on a change in pull request #636: SOLR-10409 - Added
support for rows=x in /export to limit number of docs exported (With unit tests)
URL: https://github.com/apache/lucene-solr/pull/636#discussion_r274357188
##########
File path:
solr/core/src/test/org/apache/solr/handler/export/TestExportWriter.java
##########
@@ -347,7 +347,288 @@ public void testIndexOrder() throws Exception {
assertJsonEquals(s, expectedResult);
}
+
+ @Test
+ public void testRowLimitWithManyDocs() throws Exception {
+ //rows < total matches - this is the primary usecase.
+ testRowLimitWithGivenDocs(51, 100) ;
+ testRowLimitWithGivenDocs(151, 100) ;
+ testRowLimitWithGivenDocs(100, 100) ;
+ testRowLimitWithGivenDocs(9, 10) ;
+ testRowLimitWithGivenDocs(11, 10) ;
+
+ }
+
+ private void testRowLimitWithGivenDocs(int rows, int maxDocs) throws
Exception {
+ clearIndex();
+ for (int i = 0 ; i < maxDocs ; i++) {
+ assertU(adoc("id", Integer.toString(i), "stringdv","a", "intdv",
Integer.toString(maxDocs-i)));
+ }
+ assertU(commit());
+
+ int expRows= Math.min(rows, maxDocs);
+
+ //in indexing order
+ String resultPrefix = "{\n" +
+ " \"responseHeader\":{\"status\":0},\n" +
+ " \"response\":{\n" +
+ " \"numFound\":" + maxDocs+ ",\n" +
+ " \"docs\":[";
+
+ String ascExpectedResult = resultPrefix;
+ for(int i=0; i<expRows-1; i++) {
+ ascExpectedResult+= "{\n\"id\":\"" + i + "\"}\n" ;
+ }
+ ascExpectedResult+= "{\n\"id\":\"" + (expRows-1) + "\"}]}}" ;
+
+ //in indexing order
+ String s = h.query(req("q", "*:*", "qt", "/export", "fl", "id", "sort",
"stringdv asc", "rows", Integer.toString(rows)));
+ assertJsonEquals(s, ascExpectedResult);
+
+ //in reverse indexing order
+ String descExpectedResult = resultPrefix;
+ int id = maxDocs;
+ for(int i=expRows-1; i>0; i--) {
+ descExpectedResult+= "{\n\"id\":\"" + --id + "\"}\n" ;
+ }
+ descExpectedResult+= "{\n\"id\":\"" + --id + "\"}]}}" ;
+
+ //in reverse indexing order
+ String s2 = h.query(req("q", "*:*", "qt", "/export", "fl", "id", "sort",
"intdv asc", "rows", Integer.toString(rows)));
+ assertJsonEquals(s2, descExpectedResult);
Review comment:
This `assertJsonEquals` just do a String comparison, and it has been
introduced by the exporter tests, can i suggest instead to use `assertJQ`
instead?
examples:
https://github.com/apache/lucene-solr/blob/0bd1911db6de9f38f74fc61398bd1fc3f42037a2/solr/core/src/test/org/apache/solr/update/processor/TestDocBasedVersionConstraints.java#L65
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]