You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by yo...@apache.org on 2007/06/27 07:52:03 UTC
svn commit: r551060 -
/lucene/solr/trunk/src/java/org/apache/solr/update/DocumentBuilder.java
Author: yonik
Date: Tue Jun 26 22:52:02 2007
New Revision: 551060
URL: http://svn.apache.org/viewvc?view=rev&rev=551060
Log:
check for null copyField source, delay some allocations
Modified:
lucene/solr/trunk/src/java/org/apache/solr/update/DocumentBuilder.java
Modified: lucene/solr/trunk/src/java/org/apache/solr/update/DocumentBuilder.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/update/DocumentBuilder.java?view=diff&rev=551060&r1=551059&r2=551060
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/update/DocumentBuilder.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/update/DocumentBuilder.java Tue Jun 26 22:52:02 2007
@@ -43,7 +43,7 @@
public class DocumentBuilder {
private final IndexSchema schema;
private Document doc;
- private HashMap<String,String> map = new HashMap<String,String>();
+ private HashMap<String,String> map;
public DocumentBuilder(IndexSchema schema) {
this.schema = schema;
@@ -51,7 +51,7 @@
public void startDoc() {
doc = new Document();
- map.clear();
+ map = new HashMap<String,String>();
}
protected void addSingleField(SchemaField sfield, String val, float boost) {
@@ -69,11 +69,6 @@
+ ": first='" + oldValue + "' second='" + val + "'");
}
}
-
- if( doc == null ) {
- throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,
- "must call startDoc() before adding fields!" );
- }
// field.setBoost(boost);
doc.add(field);
@@ -122,18 +117,21 @@
// Check for all required fields -- Note, all fields with a
// default value are defacto 'required' fields.
- List<String> missingFields = new ArrayList<String>( schema.getRequiredFields().size() );
+ List<String> missingFields = null;
for (SchemaField field : schema.getRequiredFields()) {
if (doc.getField(field.getName() ) == null) {
if (field.getDefaultValue() != null) {
doc.add( field.createField( field.getDefaultValue(), 1.0f ) );
} else {
+ if (missingFields==null) {
+ missingFields = new ArrayList<String>(1);
+ }
missingFields.add(field.getName());
}
}
}
- if (missingFields.size() > 0) {
+ if (missingFields != null) {
StringBuilder builder = new StringBuilder();
// add the uniqueKey if possible
if( schema.getUniqueKeyField() != null ) {
@@ -181,7 +179,7 @@
// Make sure it has the correct number
Collection<Object> vals = doc.getFieldValues( name );
- if( vals.size() > 1 && !sfield.multiValued() ) {
+ if(vals.size() > 1 && sfield!=null && !sfield.multiValued() ) {
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,
"ERROR: multiple values encountered for non multiValued field " +
sfield.getName() + ": " +vals.toString() );
Re: svn commit: r551060 - /lucene/solr/trunk/src/java/org/apache/solr/update/DocumentBuilder.java
Posted by Yonik Seeley <yo...@apache.org>.
On 6/27/07, Chris Hostetter <ho...@fucit.org> wrote:
>
> : check for null copyField source, delay some allocations
>
> i understanding delaying the allocation of missingFields, but why only a
> size of 1 once it is allocated?
Actually, it's an error case, so I don't really care about the speed
or memory consumption, as long as it only happens in that error case.
Could have just as easily left off the size.
-Yonik
Re: svn commit: r551060 - /lucene/solr/trunk/src/java/org/apache/solr/update/DocumentBuilder.java
Posted by Chris Hostetter <ho...@fucit.org>.
: check for null copyField source, delay some allocations
i understanding delaying the allocation of missingFields, but why only a
size of 1 once it is allocated? (is this just an assumption thta
typically only a few fieldswill be missing? would it make sense to just
switch to a LinkedLIst since missingFields is only ever used for
iteration?)
: - List<String> missingFields = new ArrayList<String>( schema.getRequiredFields().size() );
: + List<String> missingFields = null;
: for (SchemaField field : schema.getRequiredFields()) {
: if (doc.getField(field.getName() ) == null) {
: if (field.getDefaultValue() != null) {
: doc.add( field.createField( field.getDefaultValue(), 1.0f ) );
: } else {
: + if (missingFields==null) {
: + missingFields = new ArrayList<String>(1);
: + }
-Hoss