You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by Erik Hatcher <er...@ehatchersolutions.com> on 2003/09/29 01:25:56 UTC

Add Document constructor?

Are there any objections to adding a constructor to Document to take a 
Field[]?

   public Document(Field[] fields) {
     // any other optimizations needed here?
     for (int i = 0; i < fields.length; i++) {
       add(fields[i]);
     }
   }


It would make test code a lot cleaner at least:

     Document doc = new Document();
     doc.add(Field.Text("contents", "fuzzy"));
     writer.addDocument(doc);
     doc = new Document();
     doc.add(Field.Text("contents", "wuzzy"));
     writer.addDocument(doc);

reduced to:

	writer.addDocument(new Document(new Field[] {Field.Text("contents", 
"fuzzy"),
                                                 Field.Text("contents", 
"wuzzy")}));


Thanks,
	Erik


Re: Add Document constructor?

Posted by Doug Cutting <cu...@lucene.com>.
Erik Hatcher wrote:
> Are there any objections to adding a constructor to Document to take a 
> Field[]?
> 
> It would make test code a lot cleaner at least:
> 
>     Document doc = new Document();
>     doc.add(Field.Text("contents", "fuzzy"));
>     writer.addDocument(doc);
>     doc = new Document();
>     doc.add(Field.Text("contents", "wuzzy"));
>     writer.addDocument(doc);
> 
> reduced to:
> 
>     writer.addDocument(new Document(new Field[] {Field.Text("contents", 
> "fuzzy"),
>                                                 Field.Text("contents", 
> "wuzzy")}));

You're over stating your case a bit.  This is only equivalent to:

   Document doc = new Document();
   doc.add(Field.Text("contents", "fuzzy"));
   doc.add(Field.Text("contents", "wuzzy"));
   writer.addDocument(doc);

And, your reduced example, if formatted within 80 columns, would 
probably really require three lines, not two.  So you've saved but a line.

That's not enough for me to motivate the change, but I don't object 
strongly.

Doug


---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org


Re: Add Document constructor?

Posted by Doug Cutting <cu...@lucene.com>.
Erik Hatcher wrote:
> Are there any objections to adding a constructor to Document to take a 
> Field[]?
> 
> It would make test code a lot cleaner at least:
> 
>     Document doc = new Document();
>     doc.add(Field.Text("contents", "fuzzy"));
>     writer.addDocument(doc);
>     doc = new Document();
>     doc.add(Field.Text("contents", "wuzzy"));
>     writer.addDocument(doc);
> 
> reduced to:
> 
>     writer.addDocument(new Document(new Field[] {Field.Text("contents", 
> "fuzzy"),
>                                                 Field.Text("contents", 
> "wuzzy")}));

You're over stating your case a bit.  This is only equivalent to:

   Document doc = new Document();
   doc.add(Field.Text("contents", "fuzzy"));
   doc.add(Field.Text("contents", "wuzzy"));
   writer.addDocument(doc);

And, your reduced example, if formatted within 80 columns, would 
probably really require three lines, not two.  So you've saved but a line.

That's not enough for me to motivate the change, but I don't object 
strongly.

Doug