Return-Path: Delivered-To: apmail-jakarta-lucene-dev-archive@www.apache.org Received: (qmail 27110 invoked from network); 20 Apr 2004 17:26:20 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 20 Apr 2004 17:26:20 -0000 Received: (qmail 25699 invoked by uid 500); 20 Apr 2004 17:26:09 -0000 Delivered-To: apmail-jakarta-lucene-dev-archive@jakarta.apache.org Received: (qmail 25685 invoked by uid 500); 20 Apr 2004 17:26:09 -0000 Mailing-List: contact lucene-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Lucene Developers List" Reply-To: "Lucene Developers List" Delivered-To: mailing list lucene-dev@jakarta.apache.org Received: (qmail 25672 invoked by uid 500); 20 Apr 2004 17:26:09 -0000 Received: (qmail 25667 invoked from network); 20 Apr 2004 17:26:09 -0000 Received: from unknown (HELO minotaur.apache.org) (209.237.227.194) by daedalus.apache.org with SMTP; 20 Apr 2004 17:26:09 -0000 Received: (qmail 27091 invoked by uid 1754); 20 Apr 2004 17:26:16 -0000 Date: 20 Apr 2004 17:26:16 -0000 Message-ID: <20040420172616.27090.qmail@minotaur.apache.org> From: goller@apache.org To: jakarta-lucene-cvs@apache.org Subject: cvs commit: jakarta-lucene/src/java/org/apache/lucene/document Document.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N goller 2004/04/20 10:26:16 Modified: src/test/org/apache/lucene/document TestDocument.java src/java/org/apache/lucene/document Document.java Log: removeField and removeFields added to Document enhancement was proposed in bug 28462 Revision Changes Path 1.4 +33 -1 jakarta-lucene/src/test/org/apache/lucene/document/TestDocument.java Index: TestDocument.java =================================================================== RCS file: /home/cvs/jakarta-lucene/src/test/org/apache/lucene/document/TestDocument.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- TestDocument.java 29 Mar 2004 22:48:06 -0000 1.3 +++ TestDocument.java 20 Apr 2004 17:26:16 -0000 1.4 @@ -40,6 +40,38 @@ */ public class TestDocument extends TestCase { + + /** + * Tests {@link Document#remove()} method for a brand new Document + * that has not been indexed yet. + * + * @throws Exception on error + */ + public void testRemoveForNewDocument() throws Exception + { + Document doc = makeDocumentWithFields(); + assertEquals(8, doc.fields.size()); + doc.removeFields("keyword"); + assertEquals(6, doc.fields.size()); + doc.removeFields("doesnotexists"); // removing non-existing fields is siltenlty ignored + doc.removeFields("keyword"); // removing a field more than once + assertEquals(6, doc.fields.size()); + doc.removeField("text"); + assertEquals(5, doc.fields.size()); + doc.removeField("text"); + assertEquals(4, doc.fields.size()); + doc.removeField("text"); + assertEquals(4, doc.fields.size()); + doc.removeField("doesnotexists"); // removing non-existing fields is siltenlty ignored + assertEquals(4, doc.fields.size()); + doc.removeFields("unindexed"); + assertEquals(2, doc.fields.size()); + doc.removeFields("unstored"); + assertEquals(0, doc.fields.size()); + doc.removeFields("doesnotexists"); // removing non-existing fields is siltenlty ignored + assertEquals(0, doc.fields.size()); + } + /** * Tests {@link Document#getValues()} method for a brand new Document * that has not been indexed yet. 1.17 +31 -0 jakarta-lucene/src/java/org/apache/lucene/document/Document.java Index: Document.java =================================================================== RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/document/Document.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- Document.java 29 Mar 2004 22:48:01 -0000 1.16 +++ Document.java 20 Apr 2004 17:26:16 -0000 1.17 @@ -17,6 +17,7 @@ */ import java.util.Enumeration; +import java.util.Iterator; import java.util.List; import java.util.ArrayList; import java.util.Vector; @@ -79,6 +80,36 @@ * treated as though appended for the purposes of search. */ public final void add(Field field) { fields.add(field); + } + + /** + * Removes field with the given name from the document. + * If multiple fields exist with this name, this method returns the first value added. + * If there is no field with the specified name, the document remains unchanged. + */ + public final void removeField(String name) { + Iterator it = fields.iterator(); + while (it.hasNext()) { + Field field = (Field)it.next(); + if (field.name().equals(name)) { + it.remove(); + return; + } + } + } + + /** + * Removes all fields with the given name from the document. + * If there is no field with the specified name, the document remains unchanged. + */ + public final void removeFields(String name) { + Iterator it = fields.iterator(); + while (it.hasNext()) { + Field field = (Field)it.next(); + if (field.name().equals(name)) { + it.remove(); + } + } } /** Returns a field with the given name if any exist in this document, or --------------------------------------------------------------------- To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: lucene-dev-help@jakarta.apache.org