diff --git a/solr/core/src/java/org/apache/solr/handler/component/SearchComponent.java b/solr/core/src/java/org/apache/solr/handler/component/SearchComponent.java index bdd121a8c97..b7de8aa620a 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/SearchComponent.java +++ b/solr/core/src/java/org/apache/solr/handler/component/SearchComponent.java @@ -109,7 +109,7 @@ public void initializeMetrics(SolrMetricsContext parentContext, String scope) { // By default, don't register any metrics - but prepare a child context this.solrMetricsContext = parentContext.getChildContext(this); } - + public static final Map> STANDARD_COMPONENTS; static { diff --git a/solr/core/src/java/org/apache/solr/handler/component/UBIComponent.java b/solr/core/src/java/org/apache/solr/handler/component/UBIComponent.java index 0a944221f67..fc5756f24bb 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/UBIComponent.java +++ b/solr/core/src/java/org/apache/solr/handler/component/UBIComponent.java @@ -16,6 +16,8 @@ */ package org.apache.solr.handler.component; +import static org.apache.solr.handler.RequestHandlerBase.isInternalShardRequest; + import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; @@ -63,8 +65,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.apache.solr.handler.RequestHandlerBase.isInternalShardRequest; - /** * User Behavior Insights (UBI) is an open standard for gathering query and event data from users * and storing it in a structured format. UBI can be used for in session personalization, implicit @@ -303,9 +303,9 @@ private static UBIQuery getUbiQuery(ResponseBuilder rb) { ubiQuery.setApplication(params.get(APPLICATION)); if (ubiQuery.getApplication() == null) { ubiQuery.setApplication( - rb.isDistrib - ? rb.req.getCloudDescriptor().getCollectionName() - : searcher.getCore().getName()); + rb.isDistrib + ? rb.req.getCloudDescriptor().getCollectionName() + : searcher.getCore().getName()); } String queryAttributes = params.get(QUERY_ATTRIBUTES); @@ -334,8 +334,8 @@ public void doDistribStuff(ResponseBuilder rb) throws IOException { // the same component run twice? UBIQuery ubiQuery = getUbiQuery(rb); if (ubiQuery == null) return; - //String docIds = extractDocIds(docs, searcher); - String docIds =String.join(",", rb.resultIds.keySet().stream().map(Object::toString).toList()); + // String docIds = extractDocIds(docs, searcher); + String docIds = String.join(",", rb.resultIds.keySet().stream().map(Object::toString).toList()); ubiQuery.setDocIds(docIds); addUserBehaviorInsightsToResponse(ubiQuery, rb); diff --git a/solr/core/src/test/org/apache/solr/handler/component/UBIComponentDistrQueriesTest.java b/solr/core/src/test/org/apache/solr/handler/component/UBIComponentDistrQueriesTest.java index 00395be1d76..c87b8f5c268 100644 --- a/solr/core/src/test/org/apache/solr/handler/component/UBIComponentDistrQueriesTest.java +++ b/solr/core/src/test/org/apache/solr/handler/component/UBIComponentDistrQueriesTest.java @@ -16,15 +16,9 @@ */ package org.apache.solr.handler.component; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.commons.io.input.ReversedLinesFileReader; +import java.util.List; +import java.util.Map; import org.apache.lucene.tests.util.LuceneTestCase; -import org.apache.solr.client.solrj.io.SolrClientCache; -import org.apache.solr.client.solrj.io.Tuple; -import org.apache.solr.client.solrj.io.stream.*; -import org.apache.solr.client.solrj.io.stream.expr.StreamExpression; -import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionParser; -import org.apache.solr.client.solrj.io.stream.expr.StreamFactory; import org.apache.solr.client.solrj.request.CollectionAdminRequest; import org.apache.solr.client.solrj.request.UpdateRequest; import org.apache.solr.client.solrj.response.QueryResponse; @@ -33,20 +27,10 @@ import org.apache.solr.cluster.api.SimpleMap; import org.apache.solr.common.SolrInputDocument; import org.apache.solr.common.params.MapSolrParams; -import org.apache.solr.common.params.SolrParams; -import org.apache.solr.core.SolrCore; -import org.apache.solr.embedded.JettySolrRunner; -import org.apache.solr.handler.LoggingStream; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Path; -import java.time.Instant; -import java.util.*; - @LuceneTestCase.SuppressCodecs({"Lucene3x", "Lucene40", "Lucene41", "Lucene42", "Lucene45"}) public class UBIComponentDistrQueriesTest extends SolrCloudTestCase { @@ -59,12 +43,11 @@ public class UBIComponentDistrQueriesTest extends SolrCloudTestCase { @BeforeClass public static void setupCluster() throws Exception { configureCluster(4) - .addConfig( - "conf", TEST_PATH().resolve("configsets").resolve("ubi-enabled").resolve("conf")) + .addConfig("conf", TEST_PATH().resolve("configsets").resolve("ubi-enabled").resolve("conf")) .configure(); String collection; - useAlias = false; //random().nextBoolean(); + useAlias = false; // random().nextBoolean(); if (useAlias) { collection = COLLECTIONORALIAS + "_collection"; } else { @@ -85,14 +68,17 @@ public static void setupCluster() throws Exception { // ------------------- - CollectionAdminRequest.createCollection("ubi_queries",// it seems like a hardcoded name why? - "_default", 1, 1) - .process(cluster.getSolrClient()); + CollectionAdminRequest.createCollection( + "ubi_queries", // it seems like a hardcoded name why? + "_default", + 1, + 1) + .process(cluster.getSolrClient()); cluster.waitForActiveCollection("ubi_queries", 1, 1); AbstractDistribZkTestBase.waitForRecoveriesToFinish( - "ubi_queries", cluster.getZkStateReader(), false, true, TIMEOUT); + "ubi_queries", cluster.getZkStateReader(), false, true, TIMEOUT); } @Before @@ -102,22 +88,33 @@ public void cleanIndex() throws Exception { @Test public void testUBIQueryStream() throws Exception { - cluster.getSolrClient(COLLECTIONORALIAS).add(List.of(new SolrInputDocument("id", "1", "subject", "aa"), - new SolrInputDocument("id", "2" /*"two"*/, "subject", "aa"), - new SolrInputDocument("id", "3", "subject", "aa"))); + cluster + .getSolrClient(COLLECTIONORALIAS) + .add( + List.of( + new SolrInputDocument("id", "1", "subject", "aa"), + new SolrInputDocument("id", "2" /*"two"*/, "subject", "aa"), + new SolrInputDocument("id", "3", "subject", "aa"))); cluster.getSolrClient(COLLECTIONORALIAS).commit(true, true); - QueryResponse queryResponse = cluster.getSolrClient(COLLECTIONORALIAS).query(new MapSolrParams( - Map.of("q", "aa", "df","subject", "rows", "2", "ubi", "true" - ))); + QueryResponse queryResponse = + cluster + .getSolrClient(COLLECTIONORALIAS) + .query( + new MapSolrParams(Map.of("q", "aa", "df", "subject", "rows", "2", "ubi", "true"))); String qid = (String) ((SimpleMap) queryResponse.getResponse().get("ubi")).get("query_id"); - assertTrue(qid.length()>10); + assertTrue(qid.length() > 10); Thread.sleep(10000); // I know what you think of // TODO check that ids were recorded - QueryResponse queryCheck = cluster.getSolrClient("ubi_queries").query(new MapSolrParams( - Map.of("q", "id:"+qid //doesn't search it why? is it a race? - ))); + QueryResponse queryCheck = + cluster + .getSolrClient("ubi_queries") + .query( + new MapSolrParams( + Map.of( + "q", "id:" + qid // doesn't search it why? is it a race? + ))); // however I can't see doc ids found there. Shouldn't I ? assertEquals(1L, queryCheck.getResults().getNumFound()); - assertEquals(queryCheck.getResults().get(0).get("id"),qid); + assertEquals(queryCheck.getResults().get(0).get("id"), qid); } }