gerlowskija commented on code in PR #3915: URL: https://github.com/apache/solr/pull/3915#discussion_r2599220033
########## solr/solr-ref-guide/modules/query-guide/examples/PaginationRefGuideExamplesTest.java: ########## @@ -0,0 +1,123 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.solr.client.ref_guide_examples; + +import static org.apache.solr.client.ref_guide_examples.ExpectedOutputVerifier.clear; +import static org.apache.solr.client.ref_guide_examples.ExpectedOutputVerifier.ensureNoLeftoverOutputExpectations; +import static org.apache.solr.client.ref_guide_examples.ExpectedOutputVerifier.expectLine; +import static org.apache.solr.client.ref_guide_examples.ExpectedOutputVerifier.print; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.request.CollectionAdminRequest; +import org.apache.solr.client.solrj.request.SolrQuery; +import org.apache.solr.client.solrj.response.QueryResponse; +import org.apache.solr.cloud.SolrCloudTestCase; +import org.apache.solr.common.SolrDocument; +import org.apache.solr.common.SolrInputDocument; +import org.apache.solr.common.params.CursorMarkParams; +import org.apache.solr.util.ExternalPaths; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Example Cursormark usage in SolrJ. + * + * <p>Snippets surrounded by "tag" and "end" comments are extracted and used in the Solr Reference + * Guide. + */ +public class PaginationRefGuideExamplesTest extends SolrCloudTestCase { + private static final int NUM_INDEXED_DOCUMENTS = 9; + private static final int BATCH_SIZE = 1; + private static final String COLLECTION_NAME = "techproducts"; + private static final String CONFIG_NAME = "techproducts_config"; + + @BeforeClass + public static void setupCluster() throws Exception { + configureCluster(1).addConfig(CONFIG_NAME, ExternalPaths.TECHPRODUCTS_CONFIGSET).configure(); + + CollectionAdminRequest.createCollection(COLLECTION_NAME, CONFIG_NAME, 1, 1) + .process(cluster.getSolrClient()); + } + + @Before + @Override + public void setUp() throws Exception { + super.setUp(); + + clear(); + indexSampleData(); + } + + @After + @Override + public void tearDown() throws Exception { + super.tearDown(); + ensureNoLeftoverOutputExpectations(); + } + + @Test + public void testCursormarkWithSolrJExample() throws Exception { + for (int i = 0; i < NUM_INDEXED_DOCUMENTS; i++) { + expectLine("ID: " + i + "; Name: Fitbit Model " + i); + } + + // tag::cursormark-query[] + SolrQuery q = + (new SolrQuery("*:*")).setRows(BATCH_SIZE).setSort(SolrQuery.SortClause.asc("id")); Review Comment: [Q] What's the purpose of the paranthesis around `new SolrQuery("*:*")`...I thought it was casting at first but not on a second look... ########## solr/solr-ref-guide/modules/query-guide/examples/PaginationRefGuideExamplesTest.java: ########## @@ -0,0 +1,123 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.solr.client.ref_guide_examples; + +import static org.apache.solr.client.ref_guide_examples.ExpectedOutputVerifier.clear; +import static org.apache.solr.client.ref_guide_examples.ExpectedOutputVerifier.ensureNoLeftoverOutputExpectations; +import static org.apache.solr.client.ref_guide_examples.ExpectedOutputVerifier.expectLine; +import static org.apache.solr.client.ref_guide_examples.ExpectedOutputVerifier.print; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.request.CollectionAdminRequest; +import org.apache.solr.client.solrj.request.SolrQuery; +import org.apache.solr.client.solrj.response.QueryResponse; +import org.apache.solr.cloud.SolrCloudTestCase; +import org.apache.solr.common.SolrDocument; +import org.apache.solr.common.SolrInputDocument; +import org.apache.solr.common.params.CursorMarkParams; +import org.apache.solr.util.ExternalPaths; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Example Cursormark usage in SolrJ. + * + * <p>Snippets surrounded by "tag" and "end" comments are extracted and used in the Solr Reference + * Guide. + */ +public class PaginationRefGuideExamplesTest extends SolrCloudTestCase { + private static final int NUM_INDEXED_DOCUMENTS = 9; + private static final int BATCH_SIZE = 1; + private static final String COLLECTION_NAME = "techproducts"; + private static final String CONFIG_NAME = "techproducts_config"; + + @BeforeClass + public static void setupCluster() throws Exception { + configureCluster(1).addConfig(CONFIG_NAME, ExternalPaths.TECHPRODUCTS_CONFIGSET).configure(); + + CollectionAdminRequest.createCollection(COLLECTION_NAME, CONFIG_NAME, 1, 1) + .process(cluster.getSolrClient()); + } + + @Before + @Override + public void setUp() throws Exception { + super.setUp(); + + clear(); + indexSampleData(); + } + + @After + @Override + public void tearDown() throws Exception { + super.tearDown(); + ensureNoLeftoverOutputExpectations(); + } + + @Test + public void testCursormarkWithSolrJExample() throws Exception { + for (int i = 0; i < NUM_INDEXED_DOCUMENTS; i++) { + expectLine("ID: " + i + "; Name: Fitbit Model " + i); + } + + // tag::cursormark-query[] + SolrQuery q = Review Comment: [0] It's subjective, I know, but I'd tweak the line-breaks and indentation to be a bit more readable since it's user-facing in the docs, e.g.: ``` SolrQuery q = new SolrQuery("*:*") .setRows(BATCH_SIZE) .setSort(SolrQuery.SortClause.asc("id")); ``` ########## solr/solr-ref-guide/modules/query-guide/examples/PaginationRefGuideExamplesTest.java: ########## @@ -0,0 +1,123 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.solr.client.ref_guide_examples; + +import static org.apache.solr.client.ref_guide_examples.ExpectedOutputVerifier.clear; +import static org.apache.solr.client.ref_guide_examples.ExpectedOutputVerifier.ensureNoLeftoverOutputExpectations; +import static org.apache.solr.client.ref_guide_examples.ExpectedOutputVerifier.expectLine; +import static org.apache.solr.client.ref_guide_examples.ExpectedOutputVerifier.print; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.request.CollectionAdminRequest; +import org.apache.solr.client.solrj.request.SolrQuery; +import org.apache.solr.client.solrj.response.QueryResponse; +import org.apache.solr.cloud.SolrCloudTestCase; +import org.apache.solr.common.SolrDocument; +import org.apache.solr.common.SolrInputDocument; +import org.apache.solr.common.params.CursorMarkParams; +import org.apache.solr.util.ExternalPaths; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Example Cursormark usage in SolrJ. + * + * <p>Snippets surrounded by "tag" and "end" comments are extracted and used in the Solr Reference + * Guide. + */ +public class PaginationRefGuideExamplesTest extends SolrCloudTestCase { + private static final int NUM_INDEXED_DOCUMENTS = 9; + private static final int BATCH_SIZE = 1; + private static final String COLLECTION_NAME = "techproducts"; + private static final String CONFIG_NAME = "techproducts_config"; + + @BeforeClass + public static void setupCluster() throws Exception { + configureCluster(1).addConfig(CONFIG_NAME, ExternalPaths.TECHPRODUCTS_CONFIGSET).configure(); + + CollectionAdminRequest.createCollection(COLLECTION_NAME, CONFIG_NAME, 1, 1) + .process(cluster.getSolrClient()); + } + + @Before + @Override + public void setUp() throws Exception { + super.setUp(); + + clear(); + indexSampleData(); + } + + @After + @Override + public void tearDown() throws Exception { + super.tearDown(); + ensureNoLeftoverOutputExpectations(); + } + + @Test + public void testCursormarkWithSolrJExample() throws Exception { + for (int i = 0; i < NUM_INDEXED_DOCUMENTS; i++) { + expectLine("ID: " + i + "; Name: Fitbit Model " + i); + } + + // tag::cursormark-query[] + SolrQuery q = + (new SolrQuery("*:*")).setRows(BATCH_SIZE).setSort(SolrQuery.SortClause.asc("id")); + String cursorMark = CursorMarkParams.CURSOR_MARK_START; + boolean done = false; + + while (!done) { + q.set(CursorMarkParams.CURSOR_MARK_PARAM, cursorMark); + QueryResponse rsp = cluster.getSolrClient().query(COLLECTION_NAME, q); + String nextCursorMark = rsp.getNextCursorMark(); + for (SolrDocument doc : rsp.getResults()) { + final String docOutput = Review Comment: [0] This would be waay more readable for users if we replaced the 6 line `String.format` call with [the built-in template support Java has starting in 21](https://docs.oracle.com/en/java/javase/21/language/string-templates.html) Maybe that'd be too new and confusing for readers, but it would do wonders for making this snippet more concise 🤷 e.g. ``` final var docOutput = STR."ID: \{doc.getFieldValue("id")\}; Name: \{doc.getFieldValue("name")\}" ``` -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
