You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mu...@apache.org on 2020/02/04 16:16:57 UTC

[lucene-solr] branch master updated (b0bb299 -> c91dd9d)

This is an automated email from the ASF dual-hosted git repository.

munendrasn pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git.


    from b0bb299  LUCENE-9134: Port ant-regenerate tasks to Gradle build (#1230)
     new 4eff9c9  SOLR-10567: add support for DateRangeField in JSON facet range
     new c91dd9d  SOLR-14090: fix delete-copy-field when source is dynamic field

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 solr/CHANGES.txt                                   |  4 ++
 .../org/apache/solr/schema/ManagedIndexSchema.java |  6 +-
 .../org/apache/solr/search/facet/FacetRange.java   | 10 ++-
 .../solr/collection1/conf/schema_latest.xml        |  4 ++
 .../apache/solr/rest/schema/TestBulkSchemaAPI.java | 77 +++++++++++++++++++++-
 .../apache/solr/search/facet/TestJsonFacets.java   | 56 ++++++++++++++++
 6 files changed, 152 insertions(+), 5 deletions(-)


[lucene-solr] 01/02: SOLR-10567: add support for DateRangeField in JSON facet range

Posted by mu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

munendrasn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git

commit 4eff9c9b5e5187eb1b1600370d19841a5553c33c
Author: Munendra S N <mu...@apache.org>
AuthorDate: Tue Feb 4 21:26:40 2020 +0530

    SOLR-10567: add support for DateRangeField in JSON facet range
---
 solr/CHANGES.txt                                   |  2 +
 .../org/apache/solr/search/facet/FacetRange.java   | 10 +++-
 .../solr/collection1/conf/schema_latest.xml        |  4 ++
 .../apache/solr/search/facet/TestJsonFacets.java   | 56 ++++++++++++++++++++++
 4 files changed, 71 insertions(+), 1 deletion(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 7fc4e1d..745401a 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -207,6 +207,8 @@ Improvements
 
 * SOLR-14221: Upgrade restlet to version 2.4.0 (janhoy)
 
+* SOLR-10567: Add Support for DateRangeField in JSON Facet range (Stephen Weiss, Munendra S N)
+
 Optimizations
 ---------------------
 
diff --git a/solr/core/src/java/org/apache/solr/search/facet/FacetRange.java b/solr/core/src/java/org/apache/solr/search/facet/FacetRange.java
index 5aaa039..a74f35d 100644
--- a/solr/core/src/java/org/apache/solr/search/facet/FacetRange.java
+++ b/solr/core/src/java/org/apache/solr/search/facet/FacetRange.java
@@ -32,6 +32,7 @@ import org.apache.solr.common.params.FacetParams.FacetRangeOther;
 import org.apache.solr.common.util.SimpleOrderedMap;
 import org.apache.solr.schema.CurrencyFieldType;
 import org.apache.solr.schema.CurrencyValue;
+import org.apache.solr.schema.DateRangeField;
 import org.apache.solr.schema.ExchangeRateProvider;
 import org.apache.solr.schema.FieldType;
 import org.apache.solr.schema.SchemaField;
@@ -249,6 +250,8 @@ class FacetRangeProcessor extends FacetProcessor<FacetRange> {
       }
     } else if (ft instanceof CurrencyFieldType) {
       return new CurrencyCalc(sf);
+    } else if (ft instanceof DateRangeField) {
+      return new DateCalc(sf, null);
     }
 
     // if we made it this far, we have no idea what it is...
@@ -737,6 +740,7 @@ class FacetRangeProcessor extends FacetProcessor<FacetRange> {
       return ((Number) value).floatValue() + Float.parseFloat(gap);
     }
   }
+
   private static class DoubleCalc extends Calc {
     @Override
     public Comparable bitsToValue(long bits) {
@@ -762,6 +766,7 @@ class FacetRangeProcessor extends FacetProcessor<FacetRange> {
       return ((Number) value).doubleValue() + Double.parseDouble(gap);
     }
   }
+
   private static class IntCalc extends Calc {
 
     public IntCalc(final SchemaField f) { super(f); }
@@ -778,6 +783,7 @@ class FacetRangeProcessor extends FacetProcessor<FacetRange> {
       return ((Number) value).intValue() + Integer.parseInt(gap);
     }
   }
+
   private static class LongCalc extends Calc {
 
     public LongCalc(final SchemaField f) { super(f); }
@@ -790,13 +796,15 @@ class FacetRangeProcessor extends FacetProcessor<FacetRange> {
       return ((Number) value).longValue() + Long.parseLong(gap);
     }
   }
+
   private static class DateCalc extends Calc {
     private final Date now;
     public DateCalc(final SchemaField f,
                     final Date now) {
       super(f);
       this.now = now;
-      if (! (field.getType() instanceof TrieDateField) && !(field.getType().isPointField()) ) {
+      if (!(field.getType() instanceof TrieDateField || field.getType().isPointField() ||
+          field.getType() instanceof DateRangeField)) {
         throw new IllegalArgumentException("SchemaField must use field type extending TrieDateField, DateRangeField or PointField");
       }
     }
diff --git a/solr/core/src/test-files/solr/collection1/conf/schema_latest.xml b/solr/core/src/test-files/solr/collection1/conf/schema_latest.xml
index 78d5766..af445bc 100644
--- a/solr/core/src/test-files/solr/collection1/conf/schema_latest.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/schema_latest.xml
@@ -226,6 +226,9 @@
   <dynamicField name="*_dtd" type="date" indexed="true" stored="false" docValues="true"/>
   <dynamicField name="*_dtds" type="date" indexed="true" stored="false" multiValued="true" docValues="true"/>
 
+  <dynamicField name="*_drf" type="dateRange" indexed="true" stored="true"/>
+  <dynamicField name="*_drfs" type="dateRange" indexed="true" multiValued="true" stored="true"/>
+
   <!-- docvalues and stored (S suffix) -->
   <dynamicField name="*_idS" type="int" indexed="true" stored="true" docValues="true"/>
   <dynamicField name="*_idsS" type="int" indexed="true" stored="true" multiValued="true" docValues="true"/>
@@ -437,6 +440,7 @@
   <!-- A Trie based date field for faster date range queries and date faceting. -->
   <fieldType name="tdate" class="${solr.tests.DateFieldType}" precisionStep="6" positionIncrementGap="0"/>
 
+  <fieldType name="dateRange" class="solr.DateRangeField"/>
 
   <!--Binary data type. The data should be sent/retrieved in as Base64 encoded Strings -->
   <fieldtype name="binary" class="solr.BinaryField"/>
diff --git a/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java b/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java
index ed566e3..73bbfe3 100644
--- a/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java
+++ b/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java
@@ -3464,6 +3464,62 @@ public class TestJsonFacets extends SolrTestCaseHS {
   }
 
   @Test
+  public void testDateFacets() throws Exception {
+    Client client = Client.localClient();
+    client.deleteByQuery("*:*", null);
+    boolean multiValue = random().nextBoolean();
+    String dateField = multiValue? "b_dts": "b_dt";
+    String dateRange = multiValue? "b_drfs": "b_drf";
+
+    client.add(sdoc("id", "1", "cat_s", "A", dateField, "2014-03-15T12:00:00Z",
+        dateRange, "2014-03-15T12:00:00Z"), null);
+    client.add(sdoc("id", "2", "cat_s", "B", dateField, "2015-01-03T00:00:00Z",
+        dateRange, "2015-01-03T00:00:00Z"), null);
+    client.add(sdoc("id", "3"), null);
+    client.commit();
+    client.add(sdoc("id", "4", "cat_s", "A", dateField, "2014-03-15T12:00:00Z",
+        dateRange, "2014-03-15T12:00:00Z"), null);
+    client.add(sdoc("id", "5", "cat_s", "B", dateField, "2015-01-03T00:00:00Z",
+        dateRange, "2015-01-03T00:00:00Z"),null);
+    client.commit();
+    client.add(sdoc("id", "6", "cat_s", "B", dateField, "2014-03-15T12:00:00Z",
+        dateRange, "2014-03-15T12:00:00Z"),null);
+    client.commit();
+
+    SolrParams p = params("q", "*:*", "rows", "0");
+    for (String s : new String[]{dateField, dateRange}) {
+      client.testJQ(params(p, "json.facet"
+          , "{date:{type : range, mincount:1, field :" + s +
+              ",start:'2013-11-01T00:00:00Z',end:NOW,gap:'+90DAY'}}"),
+          "facets=={count:6, date:{buckets:" +
+              "[{val:\"2014-01-30T00:00:00Z\",count:3}, {val:\"2014-10-27T00:00:00Z\",count:2}]" +
+              "}}");
+
+      // with ranges
+      client.testJQ(params(p, "json.facet"
+          , "{date:{type : range, mincount:1, field :" + s +
+              ",ranges:[{from:'2013-11-01T00:00:00Z', to:'2014-04-30T00:00:00Z'}," +
+              "{from:'2015-01-01T00:00:00Z', to:'2020-01-30T00:00:00Z'}]}}"),
+          "facets=={count:6, date:{buckets:" +
+              "[{val:\"[2013-11-01T00:00:00Z,2014-04-30T00:00:00Z)\",count:3}," +
+              " {val:\"[2015-01-01T00:00:00Z,2020-01-30T00:00:00Z)\",count:2}]" +
+              "}}");
+    }
+
+    client.add(sdoc("id", "7", "cat_s", "B", dateRange, "[2010 TO 2014-05-21]"),null);
+    client.commit();
+    client.testJQ(params(p, "json.facet"
+        , "{date:{type : range, other:'before', field :" + dateRange +
+            ",start:'2011-11-01T00:00:00Z',end:'2016-01-30T00:00:00Z',gap:'+1YEAR'}}"),
+        "facets=={count:7, date:{buckets:[" +
+            "{val:\"2011-11-01T00:00:00Z\",count:1}, {val:\"2012-11-01T00:00:00Z\",count:1}," +
+            "{val:\"2013-11-01T00:00:00Z\",count:4}, {val:\"2014-11-01T00:00:00Z\",count:2}," +
+            "{val:\"2015-11-01T00:00:00Z\",count:0}" +
+            "],before:{count:1}" +
+            "}}");
+  }
+
+  @Test
   public void testRangeFacetWithRangesInNewFormat() throws Exception {
     Client client = Client.localClient();
     client.deleteByQuery("*:*", null);


[lucene-solr] 02/02: SOLR-14090: fix delete-copy-field when source is dynamic field

Posted by mu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

munendrasn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git

commit c91dd9d0e4336cb8fd24d4be2d53342f1e3a8cd3
Author: Munendra S N <mu...@apache.org>
AuthorDate: Tue Feb 4 21:33:31 2020 +0530

    SOLR-14090: fix delete-copy-field when source is dynamic field
---
 solr/CHANGES.txt                                   |  2 +
 .../org/apache/solr/schema/ManagedIndexSchema.java |  6 +-
 .../apache/solr/rest/schema/TestBulkSchemaAPI.java | 77 +++++++++++++++++++++-
 3 files changed, 81 insertions(+), 4 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 745401a..640e93c 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -259,6 +259,8 @@ Bug Fixes
 * SOLR-13897: Fix unsafe publication of Terms object in ZkShardTerms that can cause visibility issues
   and race conditions under contention. (shalin)
 
+* SOLR-14090: Handle the case in `delete-copy-field` when source is a dynamic field (Frank Iversen, Munendra S N)
+
 Other Changes
 ---------------------
 
diff --git a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java
index 57b0c90..7e16880 100644
--- a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java
+++ b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java
@@ -860,7 +860,11 @@ public final class ManagedIndexSchema extends IndexSchema {
           break;
         }
       }
-    } else { // non-dynamic copy field directive
+    }
+
+    if (!found) {
+      // non-dynamic copy field directive.
+      // Here, source field could either exists in schema or match a dynamic rule
       List<CopyField> copyFieldList = copyFieldsMap.get(source);
       if (copyFieldList != null) {
         for (Iterator<CopyField> iter = copyFieldList.iterator() ; iter.hasNext() ; ) {
diff --git a/solr/core/src/test/org/apache/solr/rest/schema/TestBulkSchemaAPI.java b/solr/core/src/test/org/apache/solr/rest/schema/TestBulkSchemaAPI.java
index d35f8d1..68c7811 100644
--- a/solr/core/src/test/org/apache/solr/rest/schema/TestBulkSchemaAPI.java
+++ b/solr/core/src/test/org/apache/solr/rest/schema/TestBulkSchemaAPI.java
@@ -675,7 +675,77 @@ public class TestBulkSchemaAPI extends RestTestBase {
     assertNotNull("'attr_*' dynamic field does not exist in the schema", m);
     assertEquals("string", m.get("type"));
   }
-  
+
+  public void testCopyFieldRules() throws Exception {
+    RestTestHarness harness = restTestHarness;
+
+    Map m = getObj(harness, "name", "fields");
+    assertNotNull("'name' field does not exist in the schema", m);
+
+    m = getObj(harness, "bind", "fields");
+    assertNotNull("'bind' field does not exist in the schema", m);
+
+    List l = getSourceCopyFields(harness, "bleh_s");
+    assertTrue("'bleh_s' copyField rule exists in the schema", l.isEmpty());
+
+    String payload = "{\n" +
+        "          'add-copy-field' : {\n" +
+        "                       'source' :'bleh_s',\n" +
+        "                       'dest':'name'\n" +
+        "                       }\n" +
+        "          }\n";
+    String response = harness.post("/schema", json(payload));
+
+    Map map = (Map) fromJSONString(response);
+    assertNull(response, map.get("error"));
+
+    l = getSourceCopyFields(harness, "bleh_s");
+    assertFalse("'bleh_s' copyField rule doesn't exist", l.isEmpty());
+    assertEquals("bleh_s", ((Map)l.get(0)).get("source"));
+    assertEquals("name", ((Map)l.get(0)).get("dest"));
+
+    // delete copy field rule
+    payload = "{\n" +
+        "          'delete-copy-field' : {\n" +
+        "                       'source' :'bleh_s',\n" +
+        "                       'dest':'name'\n" +
+        "                       }\n" +
+        "          }\n";
+
+    response = harness.post("/schema", json(payload));
+    map = (Map) fromJSONString(response);
+    assertNull(response, map.get("error"));
+    l = getSourceCopyFields(harness, "bleh_s");
+    assertTrue("'bleh_s' copyField rule exists in the schema", l.isEmpty());
+
+    // copy and delete with multiple destination
+    payload = "{\n" +
+        "          'add-copy-field' : {\n" +
+        "                       'source' :'bleh_s',\n" +
+        "                       'dest':['name','bind']\n" +
+        "                       }\n" +
+        "          }\n";
+    response = harness.post("/schema", json(payload));
+    map = (Map) fromJSONString(response);
+    assertNull(response, map.get("error"));
+
+    l = getSourceCopyFields(harness, "bleh_s");
+    assertEquals(2, l.size());
+
+    payload = "{\n" +
+        "          'delete-copy-field' : {\n" +
+        "                       'source' :'bleh_s',\n" +
+        "                       'dest':['name','bind']\n" +
+        "                       }\n" +
+        "          }\n";
+
+    response = harness.post("/schema", json(payload));
+    map = (Map) fromJSONString(response);
+    assertNull(response, map.get("error"));
+    l = getSourceCopyFields(harness, "bleh_s");
+    assertTrue("'bleh_s' copyField rule exists in the schema", l.isEmpty());
+  }
+
   public void testDeleteAndReplace() throws Exception {
     RestTestHarness harness = restTestHarness;
 
@@ -904,6 +974,7 @@ public class TestBulkSchemaAPI extends RestTestBase {
     map = (Map) fromJSONString(response);
     assertNull(map.get("error"));
   }
+
   public void testSortableTextFieldWithAnalyzer() throws Exception {
     String fieldTypeName = "sort_text_type";
     String fieldName = "sort_text";
@@ -958,7 +1029,7 @@ public class TestBulkSchemaAPI extends RestTestBase {
     }
     
   }
-  
+
   @Test
   public void testAddNewFieldAndQuery() throws Exception {
     getSolrClient().add(Arrays.asList(
@@ -976,7 +1047,7 @@ public class TestBulkSchemaAPI extends RestTestBase {
     int size = getSolrClient().query(query).getResults().size();
     assertEquals(1, size);
   }
-  
+
   public void testSimilarityParser() throws Exception {
     RestTestHarness harness = restTestHarness;