Skip to content

Commit

Permalink
spotless apply
Browse files Browse the repository at this point in the history
  • Loading branch information
mkhludnev committed Dec 10, 2024
1 parent 47d8927 commit 0887cae
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Class<? extends SearchComponent>> STANDARD_COMPONENTS;

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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);
}
}

0 comments on commit 0887cae

Please sign in to comment.