lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sha...@apache.org
Subject svn commit: r1665108 - in /lucene/dev/branches/branch_5x: ./ solr/ solr/core/ solr/core/src/java/org/apache/solr/schema/ solr/core/src/test-files/solr/collection1/conf/ solr/core/src/test/org/apache/solr/schema/
Date Mon, 09 Mar 2015 01:38:55 GMT
Author: shalin
Date: Mon Mar  9 01:38:55 2015
New Revision: 1665108

URL: http://svn.apache.org/r1665108
Log:
SOLR-5846: EnumField supports DocValues functionality

Modified:
    lucene/dev/branches/branch_5x/   (props changed)
    lucene/dev/branches/branch_5x/solr/   (props changed)
    lucene/dev/branches/branch_5x/solr/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_5x/solr/core/   (props changed)
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/schema/EnumField.java
    lucene/dev/branches/branch_5x/solr/core/src/test-files/solr/collection1/conf/schema-enums.xml
    lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/schema/EnumFieldTest.java

Modified: lucene/dev/branches/branch_5x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/CHANGES.txt?rev=1665108&r1=1665107&r2=1665108&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/solr/CHANGES.txt Mon Mar  9 01:38:55 2015
@@ -96,6 +96,8 @@ New Features
 * SOLR-6841: Visualize lucene segment information in Admin UI.
   (Alexey Kozhemiakin, Michal Bienkowski, hossman, Shawn Heisey, Varun Thacker via shalin)
 
+* SOLR-5846: EnumField supports DocValues functionality. (Elran Dvir, shalin)
+
 Bug Fixes
 ----------------------
 

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/schema/EnumField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/schema/EnumField.java?rev=1665108&r1=1665107&r2=1665108&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/schema/EnumField.java
(original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/schema/EnumField.java
Mon Mar  9 01:38:55 2015
@@ -18,8 +18,10 @@ package org.apache.solr.schema;
  */
 
 import org.apache.lucene.document.FieldType;
-import org.apache.lucene.index.IndexableField;
+import org.apache.lucene.document.NumericDocValuesField;
+import org.apache.lucene.document.SortedSetDocValuesField;
 import org.apache.lucene.index.IndexOptions;
+import org.apache.lucene.index.IndexableField;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.queries.function.valuesource.EnumFieldSource;
 import org.apache.lucene.search.*;
@@ -49,9 +51,7 @@ import javax.xml.xpath.XPathFactory;
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
+import java.util.*;
 
 /***
  * Field type for support of string values with custom sort order.
@@ -226,6 +226,14 @@ public class EnumField extends Primitive
    * {@inheritDoc}
    */
   @Override
+  public FieldType.NumericType getNumericType() {
+    return FieldType.NumericType.INT;
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
   public Query getRangeQuery(QParser parser, SchemaField field, String min, String max, boolean
minInclusive, boolean maxInclusive) {
     Integer minValue = stringValueToIntValue(min);
     Integer maxValue = stringValueToIntValue(max);
@@ -255,10 +263,7 @@ public class EnumField extends Primitive
    * {@inheritDoc}
    */
   @Override
-  public void checkSchemaField(final SchemaField field) {
-    if (field.hasDocValues() && !field.multiValued() && !(field.isRequired()
|| field.getDefaultValue() != null)) {
-      throw new IllegalStateException("Field " + this + " has single-valued doc values enabled,
but has no default value and is not required");
-    }
+  public void checkSchemaField(SchemaField field) {
   }
 
   /**
@@ -394,6 +399,30 @@ public class EnumField extends Primitive
   }
 
   /**
+   * {@inheritDoc}
+   */
+  @Override
+  public List<IndexableField> createFields(SchemaField sf, Object value, float boost)
{
+    if (sf.hasDocValues()) {
+      List<IndexableField> fields = new ArrayList<>();
+      final IndexableField field = createField(sf, value, boost);
+      fields.add(field);
+
+      if (sf.multiValued()) {
+        BytesRefBuilder bytes = new BytesRefBuilder();
+        readableToIndexed(stringValueToIntValue(value.toString()).toString(), bytes);
+        fields.add(new SortedSetDocValuesField(sf.getName(), bytes.toBytesRef()));
+      } else {
+        final long bits = field.numericValue().intValue();
+        fields.add(new NumericDocValuesField(sf.getName(), bits));
+      }
+      return fields;
+    } else {
+      return Collections.singletonList(createField(sf, value, boost));
+    }
+  }
+
+  /**
    * Converting the (internal) integer value (indicating the sort order) to string (displayed)
value
    * @param intVal integer value
    * @return string value

Modified: lucene/dev/branches/branch_5x/solr/core/src/test-files/solr/collection1/conf/schema-enums.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/test-files/solr/collection1/conf/schema-enums.xml?rev=1665108&r1=1665107&r2=1665108&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/test-files/solr/collection1/conf/schema-enums.xml
(original)
+++ lucene/dev/branches/branch_5x/solr/core/src/test-files/solr/collection1/conf/schema-enums.xml
Mon Mar  9 01:38:55 2015
@@ -21,6 +21,7 @@
     <field name="_version_" type="long" indexed="true" stored="true" multiValued="false"/>
     <!-- Test EnumField -->
     <field name="severity" type="severityType" indexed="true" stored="true" multiValued="false"/>
+    <field name="severity_dv" type="severityType" indexed="true" stored="true" multiValued="false"
docValues="true"/>
     <field name="text" type="text" indexed="true" stored="true" multiValued="true"/>
   </fields>
   <uniqueKey>id</uniqueKey>

Modified: lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/schema/EnumFieldTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/schema/EnumFieldTest.java?rev=1665108&r1=1665107&r2=1665108&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/schema/EnumFieldTest.java
(original)
+++ lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/schema/EnumFieldTest.java
Mon Mar  9 01:38:55 2015
@@ -24,7 +24,7 @@ import org.junit.Test;
 
 public class EnumFieldTest extends SolrTestCaseJ4 {
 
-  private final static String FIELD_NAME = "severity";
+  private final String FIELD_NAME = random().nextBoolean() ? "severity" : "severity_dv";
 
   @BeforeClass
   public static void beforeClass() throws Exception {
@@ -178,7 +178,7 @@ public class EnumFieldTest extends SolrT
 
     assertU(commit());
 
-    assertQ(req("fl", "" + FIELD_NAME, "q", "*:*"), "//doc[1]/str[@name='severity']/text()='Low'");
+    assertQ(req("fl", "" + FIELD_NAME, "q", "*:*"), "//doc[1]/str[@name='" + FIELD_NAME +
"']/text()='Low'");
   }
 
   @Test
@@ -198,17 +198,17 @@ public class EnumFieldTest extends SolrT
 
     assertU(commit());
 
-    assertQ(req("fl", "" + FIELD_NAME, "q", "*:*", "sort", FIELD_NAME + " desc"), "//doc[1]/str[@name='severity']/text()='Critical'",
-            "//doc[2]/str[@name='severity']/text()='High'", "//doc[3]/str[@name='severity']/text()='Medium'",
"//doc[4]/str[@name='severity']/text()='Low'",
-            "//doc[5]/str[@name='severity']/text()='Not Available'");
+    assertQ(req("fl", "" + FIELD_NAME, "q", "*:*", "sort", FIELD_NAME + " desc"), "//doc[1]/str[@name='"
+ FIELD_NAME + "']/text()='Critical'",
+            "//doc[2]/str[@name='" + FIELD_NAME + "']/text()='High'", "//doc[3]/str[@name='"
+ FIELD_NAME + "']/text()='Medium'", "//doc[4]/str[@name='" + FIELD_NAME + "']/text()='Low'",
+            "//doc[5]/str[@name='" + FIELD_NAME + "']/text()='Not Available'");
 
     //sort ascending - empty values will be first
-    assertQ(req("fl", "" + FIELD_NAME, "q", "*:*", "sort", FIELD_NAME + " asc"), "//doc[3]/str[@name='severity']/text()='Not
Available'");
+    assertQ(req("fl", "" + FIELD_NAME, "q", "*:*", "sort", FIELD_NAME + " asc"), "//doc[3]/str[@name='"
+ FIELD_NAME + "']/text()='Not Available'");
 
     //q for not empty docs
-    assertQ(req("fl", "" + FIELD_NAME, "q", FIELD_NAME + ":[* TO *]" , "sort", FIELD_NAME
+ " asc"), "//doc[1]/str[@name='severity']/text()='Not Available'",
-            "//doc[2]/str[@name='severity']/text()='Low'", "//doc[3]/str[@name='severity']/text()='Medium'",
"//doc[4]/str[@name='severity']/text()='High'",
-            "//doc[5]/str[@name='severity']/text()='Critical'"
+    assertQ(req("fl", "" + FIELD_NAME, "q", FIELD_NAME + ":[* TO *]" , "sort", FIELD_NAME
+ " asc"), "//doc[1]/str[@name='" + FIELD_NAME + "']/text()='Not Available'",
+            "//doc[2]/str[@name='" + FIELD_NAME + "']/text()='Low'", "//doc[3]/str[@name='"
+ FIELD_NAME + "']/text()='Medium'", "//doc[4]/str[@name='" + FIELD_NAME + "']/text()='High'",
+            "//doc[5]/str[@name='" + FIELD_NAME + "']/text()='Critical'"
     );
   }
 



Mime
View raw message