Solr
  1. Solr
  2. SOLR-82

specify default values in the schema

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.2
    • Component/s: update
    • Labels:
      None

      Description

      It would be nice to specify a default value for a given field in the schema.

      Chris Hostetter suggested this in:
      http://www.mail-archive.com/solr-user@lucene.apache.org/msg01564.html

      1. defaultValuesPatch.patch
        7 kB
        Ryan McKinley
      2. defaultValuesPatch2.patch
        8 kB
        Ryan McKinley
      3. defaultValuesPatch2.patch
        10 kB
        Hoss Man

        Activity

        Hide
        Ryan McKinley added a comment -

        This modifies SchemaField.java to keep a "defaultValue" and DocumentBuilder.java makes sure they exist when returning the document.

        The test is not totally adequate (i'm not so good with XPath yet..) but it does make sure a date specified in the schema exists

        Show
        Ryan McKinley added a comment - This modifies SchemaField.java to keep a "defaultValue" and DocumentBuilder.java makes sure they exist when returning the document. The test is not totally adequate (i'm not so good with XPath yet..) but it does make sure a date specified in the schema exists
        Hide
        Hoss Man added a comment -

        only had a chance to skim the patch so far, and i think this aspect from the mailing list is going to be a real issue with indexing performance...

        : The only change I might make is to have the schema store if it has fields
        : with default values so that DocumentBuilder.getDoc() does not cycle through
        : all fields if there aren't any.

        ... we can add a "Set<SchemaField> fieldsWithDefaults" to IndexSchema to quickly determine if there are any fields with defaults DocumentBuilder needs to check and what those fields are.

        Show
        Hoss Man added a comment - only had a chance to skim the patch so far, and i think this aspect from the mailing list is going to be a real issue with indexing performance... : The only change I might make is to have the schema store if it has fields : with default values so that DocumentBuilder.getDoc() does not cycle through : all fields if there aren't any. ... we can add a "Set<SchemaField> fieldsWithDefaults" to IndexSchema to quickly determine if there are any fields with defaults DocumentBuilder needs to check and what those fields are.
        Hide
        Ryan McKinley added a comment -

        This is a revised version that stores a list of fieldsWithDefaultValue in the schema and only cycles through them (rather then every field)

        The important bit is in: DocumentBuilder.java

        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;
        }

        Show
        Ryan McKinley added a comment - This is a revised version that stores a list of fieldsWithDefaultValue in the schema and only cycles through them (rather then every field) The important bit is in: DocumentBuilder.java 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; }
        Hide
        Hoss Man added a comment -

        Ryan: i finally got a chance to look this over in depth (your second version) and I love it!

        I'm attaching a patch with some minor modifications...

        1) fixed a typo in SchemaField.toString
        2) cleaned up some indenting oddness in the lines you modified
        3) added the name of the field to your log.fine line in IndexSchema
        4) added sample usage to the example schema and 1 exampledoc (utf8-example.xml)
        5) replaced your new testclass with a single new method in BasicFunctionalityTest which not only tests that the default is there, but also that it can be explicitly set when adding the doc.

        what do you think?

        Show
        Hoss Man added a comment - Ryan: i finally got a chance to look this over in depth (your second version) and I love it! I'm attaching a patch with some minor modifications... 1) fixed a typo in SchemaField.toString 2) cleaned up some indenting oddness in the lines you modified 3) added the name of the field to your log.fine line in IndexSchema 4) added sample usage to the example schema and 1 exampledoc (utf8-example.xml) 5) replaced your new testclass with a single new method in BasicFunctionalityTest which not only tests that the default is there, but also that it can be explicitly set when adding the doc. what do you think?
        Hide
        Ryan McKinley added a comment -

        looks great. thanks!

        Show
        Ryan McKinley added a comment - looks great. thanks!
        Hide
        Hoss Man added a comment -

        commited.

        Thanks for doing the leg work Ryan!

        Show
        Hoss Man added a comment - commited. Thanks for doing the leg work Ryan!
        Hide
        Hoss Man added a comment -

        This bug was modified as part of a bulk update using the criteria...

        • Marked ("Resolved" or "Closed") and "Fixed"
        • Had no "Fix Version" versions
        • Was listed in the CHANGES.txt for 1.2

        The Fix Version for all 39 issues found was set to 1.2, email notification
        was suppressed to prevent excessive email.

        For a list of all the issues modified, search jira comments for this
        (hopefully) unique string: 20080415hossman2

        Show
        Hoss Man added a comment - This bug was modified as part of a bulk update using the criteria... Marked ("Resolved" or "Closed") and "Fixed" Had no "Fix Version" versions Was listed in the CHANGES.txt for 1.2 The Fix Version for all 39 issues found was set to 1.2, email notification was suppressed to prevent excessive email. For a list of all the issues modified, search jira comments for this (hopefully) unique string: 20080415hossman2

          People

          • Assignee:
            Hoss Man
            Reporter:
            Ryan McKinley
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development