You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@solr.apache.org by GitBox <gi...@apache.org> on 2022/10/20 03:44:14 UTC

[GitHub] [solr] risdenk commented on a diff in pull request #1045: SOLR-16420: {!mlt_content}

risdenk commented on code in PR #1045:
URL: https://github.com/apache/solr/pull/1045#discussion_r1000113482


##########
solr/core/src/test/org/apache/solr/search/mlt/CloudMLTQContentParserTest.java:
##########
@@ -0,0 +1,296 @@
+/*
+ * 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.search.mlt;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import org.apache.solr.client.solrj.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.SolrDocumentList;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class CloudMLTQContentParserTest extends SolrCloudTestCase {
+
+  private final String seventeenth =
+      "The quote red fox jumped moon over the lazy brown dogs moon."
+          + " Of course moon. Foxes and moon come back to the foxes and moon";
+
+  @Before
+  public void setupCluster() throws Exception {
+    configureCluster(2).addConfig("conf", configset("cloud-dynamic")).configure();
+
+    CloudMLTQParserTest.indexDocs();
+  }
+
+  @After
+  public void cleanCluster() throws Exception {
+    if (null != cluster) {
+      cluster.shutdown();
+    }
+  }
+
+  public static final String COLLECTION = "mlt-collection";
+
+  @Test
+  public void testMLTQParser() throws Exception {
+
+    QueryResponse queryResponse =
+        cluster
+            .getSolrClient()
+            .query(
+                COLLECTION,
+                new SolrQuery(
+                        "q", "{!mlt_content qf=lowerfilt_u mindf=0}" + seventeenth, "fq", "-id:17")
+                    .setShowDebugInfo(true));
+    SolrDocumentList solrDocuments = queryResponse.getResults();
+    int[] expectedIds = new int[] {7, 9, 13, 14, 15, 16, 20, 22, 24, 32};
+    int[] actualIds = new int[10];
+    int i = 0;
+    for (SolrDocument solrDocument : solrDocuments) {
+      actualIds[i++] = Integer.parseInt(String.valueOf(solrDocument.getFieldValue("id")));
+    }
+
+    Arrays.sort(actualIds);
+    Arrays.sort(expectedIds);
+    assertArrayEquals(expectedIds, actualIds);
+  }
+
+  @Test
+  public void testBoost() throws Exception {
+
+    QueryResponse queryResponse =
+        cluster
+            .getSolrClient()
+            .query(
+                COLLECTION,
+                new SolrQuery(
+                    "q",
+                    "{!mlt_content qf=lowerfilt_u boost=true mindf=0}" + seventeenth,
+                    "fq",
+                    "-id:17"));
+    SolrDocumentList solrDocuments = queryResponse.getResults();
+    int[] expectedIds = new int[] {7, 9, 13, 14, 15, 16, 20, 22, 24, 32};
+    int[] actualIds = new int[solrDocuments.size()];
+    int i = 0;
+    for (SolrDocument solrDocument : solrDocuments) {
+      actualIds[i++] = Integer.parseInt(String.valueOf(solrDocument.getFieldValue("id")));
+    }
+
+    Arrays.sort(actualIds);
+    Arrays.sort(expectedIds);
+    assertArrayEquals(expectedIds, actualIds);
+
+    String thirtineenth = "The quote red fox jumped over the lazy brown dogs." + "red green yellow";
+    queryResponse =
+        cluster
+            .getSolrClient()
+            .query(
+                COLLECTION,
+                new SolrQuery(
+                    "q",
+                    "{!mlt_content qf=lowerfilt_u^10,lowerfilt1_u^1000 boost=false mintf=0 mindf=0}"
+                        + thirtineenth,
+                    "fq",
+                    "-id:30"));
+    solrDocuments = queryResponse.getResults();
+    expectedIds = new int[] {31, 18, 23, 13, 14, 20, 22, 32, 19, 21};
+    actualIds = new int[solrDocuments.size()];
+    i = 0;
+    for (SolrDocument solrDocument : solrDocuments) {
+      actualIds[i++] = Integer.parseInt(String.valueOf(solrDocument.getFieldValue("id")));
+    }
+
+    Arrays.sort(actualIds);
+    Arrays.sort(expectedIds);
+    System.out.println("DEBUG ACTUAL IDS 1: " + Arrays.toString(actualIds));
+    assertArrayEquals(expectedIds, actualIds);
+
+    queryResponse =
+        cluster
+            .getSolrClient()
+            .query(
+                COLLECTION,
+                new SolrQuery(
+                    "q",
+                    "{!mlt_content qf=lowerfilt_u^10,lowerfilt1_u^1000 boost=true mintf=0 mindf=0}"
+                        + thirtineenth,
+                    "fq",
+                    "-id:30"));
+    solrDocuments = queryResponse.getResults();
+    expectedIds = new int[] {29, 31, 32, 18, 23, 13, 14, 20, 22, 19};
+    actualIds = new int[solrDocuments.size()];
+    i = 0;
+    for (SolrDocument solrDocument : solrDocuments) {
+      actualIds[i++] = Integer.parseInt(String.valueOf(solrDocument.getFieldValue("id")));
+    }
+
+    Arrays.sort(actualIds);
+    Arrays.sort(expectedIds);
+    System.out.println("DEBUG ACTUAL IDS 2: " + Arrays.toString(actualIds));

Review Comment:
   left over debugging?



##########
solr/core/src/test/org/apache/solr/search/mlt/CloudMLTQContentParserTest.java:
##########
@@ -0,0 +1,296 @@
+/*
+ * 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.search.mlt;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import org.apache.solr.client.solrj.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.SolrDocumentList;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class CloudMLTQContentParserTest extends SolrCloudTestCase {
+
+  private final String seventeenth =
+      "The quote red fox jumped moon over the lazy brown dogs moon."
+          + " Of course moon. Foxes and moon come back to the foxes and moon";
+
+  @Before
+  public void setupCluster() throws Exception {
+    configureCluster(2).addConfig("conf", configset("cloud-dynamic")).configure();
+
+    CloudMLTQParserTest.indexDocs();
+  }
+
+  @After
+  public void cleanCluster() throws Exception {
+    if (null != cluster) {
+      cluster.shutdown();
+    }
+  }
+
+  public static final String COLLECTION = "mlt-collection";
+
+  @Test
+  public void testMLTQParser() throws Exception {
+
+    QueryResponse queryResponse =
+        cluster
+            .getSolrClient()
+            .query(
+                COLLECTION,
+                new SolrQuery(
+                        "q", "{!mlt_content qf=lowerfilt_u mindf=0}" + seventeenth, "fq", "-id:17")
+                    .setShowDebugInfo(true));
+    SolrDocumentList solrDocuments = queryResponse.getResults();
+    int[] expectedIds = new int[] {7, 9, 13, 14, 15, 16, 20, 22, 24, 32};
+    int[] actualIds = new int[10];
+    int i = 0;
+    for (SolrDocument solrDocument : solrDocuments) {
+      actualIds[i++] = Integer.parseInt(String.valueOf(solrDocument.getFieldValue("id")));
+    }
+
+    Arrays.sort(actualIds);
+    Arrays.sort(expectedIds);
+    assertArrayEquals(expectedIds, actualIds);
+  }
+
+  @Test
+  public void testBoost() throws Exception {
+
+    QueryResponse queryResponse =
+        cluster
+            .getSolrClient()
+            .query(
+                COLLECTION,
+                new SolrQuery(
+                    "q",
+                    "{!mlt_content qf=lowerfilt_u boost=true mindf=0}" + seventeenth,
+                    "fq",
+                    "-id:17"));
+    SolrDocumentList solrDocuments = queryResponse.getResults();
+    int[] expectedIds = new int[] {7, 9, 13, 14, 15, 16, 20, 22, 24, 32};
+    int[] actualIds = new int[solrDocuments.size()];
+    int i = 0;
+    for (SolrDocument solrDocument : solrDocuments) {
+      actualIds[i++] = Integer.parseInt(String.valueOf(solrDocument.getFieldValue("id")));
+    }
+
+    Arrays.sort(actualIds);
+    Arrays.sort(expectedIds);
+    assertArrayEquals(expectedIds, actualIds);
+
+    String thirtineenth = "The quote red fox jumped over the lazy brown dogs." + "red green yellow";
+    queryResponse =
+        cluster
+            .getSolrClient()
+            .query(
+                COLLECTION,
+                new SolrQuery(
+                    "q",
+                    "{!mlt_content qf=lowerfilt_u^10,lowerfilt1_u^1000 boost=false mintf=0 mindf=0}"
+                        + thirtineenth,
+                    "fq",
+                    "-id:30"));
+    solrDocuments = queryResponse.getResults();
+    expectedIds = new int[] {31, 18, 23, 13, 14, 20, 22, 32, 19, 21};
+    actualIds = new int[solrDocuments.size()];
+    i = 0;
+    for (SolrDocument solrDocument : solrDocuments) {
+      actualIds[i++] = Integer.parseInt(String.valueOf(solrDocument.getFieldValue("id")));
+    }
+
+    Arrays.sort(actualIds);
+    Arrays.sort(expectedIds);
+    System.out.println("DEBUG ACTUAL IDS 1: " + Arrays.toString(actualIds));

Review Comment:
   leftover debugging?



##########
solr/core/src/test/org/apache/solr/search/mlt/CloudMLTQContentParserTest.java:
##########
@@ -0,0 +1,296 @@
+/*
+ * 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.search.mlt;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import org.apache.solr.client.solrj.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.SolrDocumentList;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class CloudMLTQContentParserTest extends SolrCloudTestCase {
+
+  private final String seventeenth =
+      "The quote red fox jumped moon over the lazy brown dogs moon."
+          + " Of course moon. Foxes and moon come back to the foxes and moon";
+
+  @Before
+  public void setupCluster() throws Exception {
+    configureCluster(2).addConfig("conf", configset("cloud-dynamic")).configure();
+
+    CloudMLTQParserTest.indexDocs();
+  }
+
+  @After
+  public void cleanCluster() throws Exception {
+    if (null != cluster) {
+      cluster.shutdown();
+    }
+  }
+
+  public static final String COLLECTION = "mlt-collection";
+
+  @Test
+  public void testMLTQParser() throws Exception {
+
+    QueryResponse queryResponse =
+        cluster
+            .getSolrClient()
+            .query(
+                COLLECTION,
+                new SolrQuery(
+                        "q", "{!mlt_content qf=lowerfilt_u mindf=0}" + seventeenth, "fq", "-id:17")
+                    .setShowDebugInfo(true));
+    SolrDocumentList solrDocuments = queryResponse.getResults();
+    int[] expectedIds = new int[] {7, 9, 13, 14, 15, 16, 20, 22, 24, 32};
+    int[] actualIds = new int[10];
+    int i = 0;
+    for (SolrDocument solrDocument : solrDocuments) {
+      actualIds[i++] = Integer.parseInt(String.valueOf(solrDocument.getFieldValue("id")));
+    }
+
+    Arrays.sort(actualIds);
+    Arrays.sort(expectedIds);
+    assertArrayEquals(expectedIds, actualIds);
+  }
+
+  @Test
+  public void testBoost() throws Exception {
+
+    QueryResponse queryResponse =
+        cluster
+            .getSolrClient()
+            .query(
+                COLLECTION,
+                new SolrQuery(
+                    "q",
+                    "{!mlt_content qf=lowerfilt_u boost=true mindf=0}" + seventeenth,
+                    "fq",
+                    "-id:17"));
+    SolrDocumentList solrDocuments = queryResponse.getResults();
+    int[] expectedIds = new int[] {7, 9, 13, 14, 15, 16, 20, 22, 24, 32};
+    int[] actualIds = new int[solrDocuments.size()];
+    int i = 0;
+    for (SolrDocument solrDocument : solrDocuments) {
+      actualIds[i++] = Integer.parseInt(String.valueOf(solrDocument.getFieldValue("id")));
+    }
+
+    Arrays.sort(actualIds);
+    Arrays.sort(expectedIds);
+    assertArrayEquals(expectedIds, actualIds);
+
+    String thirtineenth = "The quote red fox jumped over the lazy brown dogs." + "red green yellow";
+    queryResponse =
+        cluster
+            .getSolrClient()
+            .query(
+                COLLECTION,
+                new SolrQuery(
+                    "q",
+                    "{!mlt_content qf=lowerfilt_u^10,lowerfilt1_u^1000 boost=false mintf=0 mindf=0}"
+                        + thirtineenth,
+                    "fq",
+                    "-id:30"));
+    solrDocuments = queryResponse.getResults();
+    expectedIds = new int[] {31, 18, 23, 13, 14, 20, 22, 32, 19, 21};
+    actualIds = new int[solrDocuments.size()];
+    i = 0;
+    for (SolrDocument solrDocument : solrDocuments) {
+      actualIds[i++] = Integer.parseInt(String.valueOf(solrDocument.getFieldValue("id")));
+    }
+
+    Arrays.sort(actualIds);
+    Arrays.sort(expectedIds);
+    System.out.println("DEBUG ACTUAL IDS 1: " + Arrays.toString(actualIds));
+    assertArrayEquals(expectedIds, actualIds);
+
+    queryResponse =
+        cluster
+            .getSolrClient()
+            .query(
+                COLLECTION,
+                new SolrQuery(
+                    "q",
+                    "{!mlt_content qf=lowerfilt_u^10,lowerfilt1_u^1000 boost=true mintf=0 mindf=0}"
+                        + thirtineenth,
+                    "fq",
+                    "-id:30"));
+    solrDocuments = queryResponse.getResults();
+    expectedIds = new int[] {29, 31, 32, 18, 23, 13, 14, 20, 22, 19};
+    actualIds = new int[solrDocuments.size()];
+    i = 0;
+    for (SolrDocument solrDocument : solrDocuments) {
+      actualIds[i++] = Integer.parseInt(String.valueOf(solrDocument.getFieldValue("id")));
+    }
+
+    Arrays.sort(actualIds);
+    Arrays.sort(expectedIds);
+    System.out.println("DEBUG ACTUAL IDS 2: " + Arrays.toString(actualIds));
+    assertArrayEquals(
+        Arrays.toString(expectedIds) + " " + Arrays.toString(actualIds), expectedIds, actualIds);

Review Comment:
   not sure that `Arrays.toString(expectedIds) + " " + Arrays.toString(actualIds),` is needed? I think assertArrayEquals prints the differences.



-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org