lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hoss...@apache.org
Subject svn commit: r493170 - in /incubator/solr/trunk: ./ example/exampledocs/ example/solr/conf/ src/java/org/apache/solr/schema/ src/java/org/apache/solr/update/ src/test/org/apache/solr/ src/test/test-files/solr/conf/
Date Fri, 05 Jan 2007 20:12:19 GMT
Author: hossman
Date: Fri Jan  5 12:12:18 2007
New Revision: 493170

URL: http://svn.apache.org/viewvc?view=rev&rev=493170
Log:
SOLR-82 - allow default field values to be specified in the schema.xml

Modified:
    incubator/solr/trunk/CHANGES.txt
    incubator/solr/trunk/example/exampledocs/utf8-example.xml
    incubator/solr/trunk/example/solr/conf/schema.xml
    incubator/solr/trunk/src/java/org/apache/solr/schema/IndexSchema.java
    incubator/solr/trunk/src/java/org/apache/solr/schema/SchemaField.java
    incubator/solr/trunk/src/java/org/apache/solr/update/DocumentBuilder.java
    incubator/solr/trunk/src/test/org/apache/solr/BasicFunctionalityTest.java
    incubator/solr/trunk/src/test/org/apache/solr/ConvertedLegacyTest.java
    incubator/solr/trunk/src/test/test-files/solr/conf/schema.xml

Modified: incubator/solr/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/solr/trunk/CHANGES.txt?view=diff&rev=493170&r1=493169&r2=493170
==============================================================================
--- incubator/solr/trunk/CHANGES.txt (original)
+++ incubator/solr/trunk/CHANGES.txt Fri Jan  5 12:12:18 2007
@@ -35,7 +35,8 @@
 --------------------
 
 New Features
- 1.
+ 1. SOLR-82: Default field values can be specified in the schema.xml.
+    (Ryan McKinley via hossman)
 
 Changes in runtime behavior
  1. Highlighting using DisMax will only pick up terms from the main 
@@ -54,7 +55,7 @@
 Other Changes
  1.
 
-================== Release 1.1.0, YYYYMMDD ==================
+================== Release 1.1.0, 20061222 ==================
 
 Status
 ------

Modified: incubator/solr/trunk/example/exampledocs/utf8-example.xml
URL: http://svn.apache.org/viewvc/incubator/solr/trunk/example/exampledocs/utf8-example.xml?view=diff&rev=493170&r1=493169&r2=493170
==============================================================================
--- incubator/solr/trunk/example/exampledocs/utf8-example.xml (original)
+++ incubator/solr/trunk/example/exampledocs/utf8-example.xml Fri Jan  5 12:12:18 2007
@@ -35,7 +35,7 @@
     <field name="features">tag with escaped chars: &lt;nicetag/&gt;</field>
     <field name="features">escaped ampersand: Bonnie &amp; Clyde</field>
     <field name="price">0</field>
-    <field name="popularity">10</field>
+    <!-- no popularity, get the default from schema.xml -->
     <field name="inStock">true</field>
   </doc>
 </add>

Modified: incubator/solr/trunk/example/solr/conf/schema.xml
URL: http://svn.apache.org/viewvc/incubator/solr/trunk/example/solr/conf/schema.xml?view=diff&rev=493170&r1=493169&r2=493170
==============================================================================
--- incubator/solr/trunk/example/solr/conf/schema.xml (original)
+++ incubator/solr/trunk/example/solr/conf/schema.xml Fri Jan  5 12:12:18 2007
@@ -211,7 +211,10 @@
 
    <field name="weight" type="sfloat" indexed="true" stored="true"/>
    <field name="price"  type="sfloat" indexed="true" stored="true"/>
-   <field name="popularity" type="sint" indexed="true" stored="true"/>
+   <!-- "default" values can be specified for fields, indicating which
+        value should be used if no value is specified when adding a document.
+     -->
+   <field name="popularity" type="sint" indexed="true" stored="true" default="0"/>
    <field name="inStock" type="boolean" indexed="true" stored="true"/>
 
    <!-- catchall field, containing all other searchable text fields (implemented
@@ -222,6 +225,11 @@
         results by manufacturer.  copied from "manu" via copyField -->
    <field name="manu_exact" type="string" indexed="true" stored="false"/>
 
+   <!-- Here, default is used to create a "timestamp" field indicating
+        When each document was indexed.
+     -->
+   <field name="timestamp" type="date" indexed="true" stored="true" default="NOW" multiValued="false"/>
+   
 
    <!-- Dynamic field definitions.  If a field name is not found, dynamicFields
         will be used if the name matches any of the patterns.

Modified: incubator/solr/trunk/src/java/org/apache/solr/schema/IndexSchema.java
URL: http://svn.apache.org/viewvc/incubator/solr/trunk/src/java/org/apache/solr/schema/IndexSchema.java?view=diff&rev=493170&r1=493169&r2=493170
==============================================================================
--- incubator/solr/trunk/src/java/org/apache/solr/schema/IndexSchema.java (original)
+++ incubator/solr/trunk/src/java/org/apache/solr/schema/IndexSchema.java Fri Jan  5 12:12:18
2007
@@ -88,6 +88,7 @@
 
   private final HashMap<String, SchemaField> fields = new HashMap<String,SchemaField>();
   private final HashMap<String, FieldType> fieldTypes = new HashMap<String,FieldType>();
+  private final List<SchemaField> fieldsWithDefaultValue = new ArrayList<SchemaField>();
 
   /**
    * Provides direct access to the Map containing all explicit
@@ -109,6 +110,10 @@
    */
   public Map<String,FieldType> getFieldTypes() { return fieldTypes; }
 
+  /**
+   * Provides direct access to the List containing all fields with a default value
+   */
+  public List<SchemaField> getFieldsWithDefaultValue() { return fieldsWithDefaultValue;
}
 
   private Similarity similarity;
 
@@ -335,6 +340,10 @@
         if (node.getNodeName().equals("field")) {
           fields.put(f.getName(),f);
           log.fine("field defined: " + f);
+          if( f.getDefaultValue() != null ) {
+            log.fine(name+" contains default value: " + f.getDefaultValue());
+        	  fieldsWithDefaultValue.add( f );
+          }
         } else if (node.getNodeName().equals("dynamicField")) {
           dFields.add(new DynamicField(f));
           log.fine("dynamic field defined: " + f);

Modified: incubator/solr/trunk/src/java/org/apache/solr/schema/SchemaField.java
URL: http://svn.apache.org/viewvc/incubator/solr/trunk/src/java/org/apache/solr/schema/SchemaField.java?view=diff&rev=493170&r1=493169&r2=493170
==============================================================================
--- incubator/solr/trunk/src/java/org/apache/solr/schema/SchemaField.java (original)
+++ incubator/solr/trunk/src/java/org/apache/solr/schema/SchemaField.java Fri Jan  5 12:12:18
2007
@@ -36,20 +36,21 @@
   final String name;
   final FieldType type;
   final int properties;
+  final String defaultValue;
 
 
   /** Create a new SchemaField with the given name and type,
    *  using all the default properties from the type.
    */
   public SchemaField(String name, FieldType type) {
-    this(name, type, type.properties);
+    this(name, type, type.properties, null);
   }
 
   /** Create a new SchemaField from an existing one by using all
    * of the properties of the prototype except the field name.
    */
   public SchemaField(SchemaField prototype, String name) {
-    this(name, prototype.type, prototype.properties);
+    this(name, prototype.type, prototype.properties, prototype.defaultValue );
   }
 
  /** Create a new SchemaField with the given name and type,
@@ -58,10 +59,11 @@
    * constructor should derive the properties from type.getProperties()
    *  using all the default properties from the type.
    */
-  public SchemaField(String name, FieldType type, int properties) {
+  public SchemaField(String name, FieldType type, int properties, String defaultValue ) {
     this.name = name;
     this.type = type;
     this.properties = properties;
+    this.defaultValue = defaultValue;
   }
 
   public String getName() { return name; }
@@ -89,8 +91,9 @@
 
   public String toString() {
     return name + "{type="+type.getTypeName()
-            + ",properties=" + propertiesToString(properties)
-            + "}";
+      + ((defaultValue==null)?"":(",default="+defaultValue))
+      + ",properties=" + propertiesToString(properties)
+      + "}";
   }
 
   public void write(XMLWriter writer, String name, Fieldable val) throws IOException {
@@ -157,7 +160,15 @@
     p &= ~falseProps;
     p |= trueProps;
 
-    return new SchemaField(name, ft, p);
+    String defaultValue = null;
+    if( props.containsKey( "default" ) ) {
+    	defaultValue = (String)props.get( "default" );
+    }
+    return new SchemaField(name, ft, p, defaultValue );
+  }
+
+  public String getDefaultValue() {
+    return defaultValue;
   }
 }
 

Modified: incubator/solr/trunk/src/java/org/apache/solr/update/DocumentBuilder.java
URL: http://svn.apache.org/viewvc/incubator/solr/trunk/src/java/org/apache/solr/update/DocumentBuilder.java?view=diff&rev=493170&r1=493169&r2=493170
==============================================================================
--- incubator/solr/trunk/src/java/org/apache/solr/update/DocumentBuilder.java (original)
+++ incubator/solr/trunk/src/java/org/apache/solr/update/DocumentBuilder.java Fri Jan  5 12:12:18
2007
@@ -105,6 +105,14 @@
 
   // specific to this type of document builder
   public Document getDoc() {
+	  
+    // Check for default fields in our schema...
+    for( SchemaField field : schema.getFieldsWithDefaultValue() ) {
+      if( doc.getField( field.getName() ) == null ) {
+        doc.add( field.createField( field.getDefaultValue(), 1.0f ) );
+      }
+    }
+	  
     Document ret = doc; doc=null;
     return ret;
   }

Modified: incubator/solr/trunk/src/test/org/apache/solr/BasicFunctionalityTest.java
URL: http://svn.apache.org/viewvc/incubator/solr/trunk/src/test/org/apache/solr/BasicFunctionalityTest.java?view=diff&rev=493170&r1=493169&r2=493170
==============================================================================
--- incubator/solr/trunk/src/test/org/apache/solr/BasicFunctionalityTest.java (original)
+++ incubator/solr/trunk/src/test/org/apache/solr/BasicFunctionalityTest.java Fri Jan  5 12:12:18
2007
@@ -340,6 +340,46 @@
   }
 
 
+  public void testDefaultFieldValues() {
+    
+    assertU(adoc("id",  "4055",
+                 "subject", "Hoss the Hoss man Hostetter"));
+    assertU(adoc("id",  "4056",
+                 "intDefault", "4",
+                 "subject", "Some Other Guy"));
+    assertU(adoc("id",  "4057",
+                 "multiDefault", "a",
+                 "multiDefault", "b",
+                 "subject", "The Dude"));
+    assertU(commit());
+
+    assertQ("everthing should have recent timestamp",
+            req("timestamp:[NOW-10MINUTES TO NOW]")
+            ,"*[count(//doc)=3]"
+            ,"//date[@name='timestamp']"
+            );
+    
+    assertQ("2 docs should have the default for multiDefault",
+            req("multiDefault:muLti-Default")
+            ,"*[count(//doc)=2]"
+            ,"//arr[@name='multiDefault']"
+            );
+    assertQ("1 doc should have it's explicit multiDefault",
+            req("multiDefault:a")
+            ,"*[count(//doc)=1]"
+            );
+
+    assertQ("2 docs should have the default for intDefault",
+            req("intDefault:42")
+            ,"*[count(//doc)=2]"
+            );
+    assertQ("1 doc should have it's explicit intDefault",
+            req("intDefault:[3 TO 5]")
+            ,"*[count(//doc)=1]"
+            );
+    
+  }
+
   public void testConfigDefaults() {
     assertU(adoc("id", "42",
                  "name", "Zapp Brannigan"));

Modified: incubator/solr/trunk/src/test/org/apache/solr/ConvertedLegacyTest.java
URL: http://svn.apache.org/viewvc/incubator/solr/trunk/src/test/org/apache/solr/ConvertedLegacyTest.java?view=diff&rev=493170&r1=493169&r2=493170
==============================================================================
--- incubator/solr/trunk/src/test/org/apache/solr/ConvertedLegacyTest.java (original)
+++ incubator/solr/trunk/src/test/org/apache/solr/ConvertedLegacyTest.java Fri Jan  5 12:12:18
2007
@@ -1118,7 +1118,7 @@
             ,"//str[.='Yonik']  "
             ,"//float[.='1.4142135'] "
             ,"//float[@name='score'] "
-            ,"*[count(//doc/*)=10]"
+            ,"*[count(//doc/*)=13]"
             );
     args = new HashMap<String,String>();
     args.put("version","2.0");
@@ -1129,7 +1129,7 @@
             ,"//str[.='Yonik']  "
             ,"//float[.='1.4142135'] "
             ,"//float[@name='score'] "
-            ,"*[count(//doc/*)=10]"
+            ,"*[count(//doc/*)=13]"
             );
     args = new HashMap<String,String>();
     args.put("version","2.0");
@@ -1139,7 +1139,7 @@
     assertQ(req
             ,"//str[.='Yonik']  "
             ,"//float[.='1.4142135'] "
-            ,"*[count(//doc/*)>=9]"
+            ,"*[count(//doc/*)>=12]"
             );
 
     // test maxScore

Modified: incubator/solr/trunk/src/test/test-files/solr/conf/schema.xml
URL: http://svn.apache.org/viewvc/incubator/solr/trunk/src/test/test-files/solr/conf/schema.xml?view=diff&rev=493170&r1=493169&r2=493170
==============================================================================
--- incubator/solr/trunk/src/test/test-files/solr/conf/schema.xml (original)
+++ incubator/solr/trunk/src/test/test-files/solr/conf/schema.xml Fri Jan  5 12:12:18 2007
@@ -357,7 +357,13 @@
    <field name="sku2" type="skutype2" indexed="true" stored="true"/>
 
    <field name="textgap" type="textgap" indexed="true" stored="true"/>
+   
+   <field name="timestamp" type="date" indexed="true" stored="true" default="NOW" multiValued="false"/>
+   <field name="multiDefault" type="string" indexed="true" stored="true" default="muLti-Default"
multiValued="true"/>
+   <field name="intDefault" type="sint" indexed="true" stored="true" default="42" multiValued="false"/>
+   
 
+   
    <!-- Dynamic field definitions.  If a field name is not found, dynamicFields
         will be used if the name matches any of the patterns.
         RESTRICTION: the glob-like pattern in the name attribute must have



Mime
View raw message