You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Dingding Ye <ye...@gmail.com> on 2009/01/05 19:46:21 UTC
Questions about UUID type
Hi.
I'm confused by the UUID type comment. It's said that
/**
* Generates a UUID if val is either null, empty or "NEW".
*
* Otherwise it behaves much like a StrField but checks that the value
given
* is indeed a valid UUID.
*
* @param val The value of the field
* @see org.apache.solr.schema.FieldType#toInternal(java.lang.String)
*/
However, i found that if i don't specify the field and it will report the
exception
org.apache.solr.common.SolrException: Document [test] missing required
field: id
Surely when i set it to "NEW", it will work as expected.
I want to know that is this a expected way or should be possible a bug?
The related codes should be:
for (SchemaField field : schema.getRequiredFields()) {
if (out.getField(field.getName() ) == null) {
* if (field.getDefaultValue() != null) { // Here because
the default value is null. I think we should judge whether it's a UUID
field.
out.add( field.createField( field.getDefaultValue(), 1.0f ) );
} *
else {
String id = schema.printableUniqueKey( out );
String msg = "Document ["+id+"] missing required field: " +
field.getName();
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, msg
);
}
}
}
Thanks for help.
Best regards.
sishen
Re: Questions about UUID type
Posted by Chris Hostetter <ho...@fucit.org>.
1) please don't cc both solr-user and solr-dev ... if you are confused
about how something works, or having problems, please just email
solr-user.
2) ...
: I'm confused by the UUID type comment. It's said that
...
: However¡¤ i found that if i don't specify the field and it will report the
: exception
:
: org.apache.solr.common.SolrException: Document [test] missing required
: field: id
...the javadoc you quoted is correct an accurate for what that method
does, it behaves as documented when the value passed to it is null, empty
or "NEW".
but at a higher level you still need to supply a value for any
required="true" field when indexing a doc ... that value can be null, or
empty, or "NEW" but you have to provide one. If you want solr to just
take care of it for you, then specify a default value in your schema...
<field name="id" type="uuid" indexed="true" stored="true" default="NEW"/>
The current appraoch allwows Solr to be flexible to what the user wants...
* if you specify a default in the schema, solr won't complain if it's not
in the input and will pass that value on to UUIDFIeld
* if you don't specify a default, you take responsibility for seinging
some type of value for hte UUIDField to use
* regardless of where the input comes from UUIDField will do the right
thing if the input is null, empty, or "NEW"
-Hoss