Return-Path: Delivered-To: apmail-lucene-java-user-archive@www.apache.org Received: (qmail 24549 invoked from network); 11 Aug 2005 19:41:35 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 11 Aug 2005 19:41:35 -0000 Received: (qmail 38080 invoked by uid 500); 11 Aug 2005 19:41:29 -0000 Delivered-To: apmail-lucene-java-user-archive@lucene.apache.org Received: (qmail 38060 invoked by uid 500); 11 Aug 2005 19:41:29 -0000 Mailing-List: contact java-user-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: java-user@lucene.apache.org Delivered-To: mailing list java-user@lucene.apache.org Received: (qmail 38046 invoked by uid 99); 11 Aug 2005 19:41:28 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Aug 2005 12:41:28 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=RCVD_BY_IP,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of brogar@gmail.com designates 64.233.184.207 as permitted sender) Received: from [64.233.184.207] (HELO wproxy.gmail.com) (64.233.184.207) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Aug 2005 12:41:50 -0700 Received: by wproxy.gmail.com with SMTP id 71so488325wri for ; Thu, 11 Aug 2005 12:41:27 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=n2Df+lMqKk+1UWx9ZDrg3k2geWJpLK7icduAxQ3jC0F59k3VAv+cUw2rWG425MeYWwzjNKzT7N3dcn0RFtZjg73E++xeYXOe1prtQJ/mlE3kjdk18AXh0WAYKZAzAHBENwLHWrS/1oDMGeAwJPu4yM2nGqGjPxKY5lVN1HcQmyc= Received: by 10.54.10.61 with SMTP id 61mr1431954wrj; Thu, 11 Aug 2005 12:41:27 -0700 (PDT) Received: by 10.54.121.15 with HTTP; Thu, 11 Aug 2005 12:41:26 -0700 (PDT) Message-ID: <34cc3b0a05081112412a18a802@mail.gmail.com> Date: Thu, 11 Aug 2005 15:41:27 -0400 From: Chris D To: java-user@lucene.apache.org Subject: Re: Indexing document instances and retrieving instance attributes In-Reply-To: <20050811185206.5998.qmail@web31107.mail.mud.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <34cc3b0a050811113411bcfea@mail.gmail.com> <20050811185206.5998.qmail@web31107.mail.mud.yahoo.com> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N On 8/11/05, Otis Gospodnetic wrote: >=20 > > So I've decided I'm going to simply have empty fields, and that > > brought up several other questions. > > > > First, is there a limit on the number of fields per document? >=20 > I don't think so. >=20 > > Secondly why are fields in Document implemented with a Vector instead > > of a HashSet or similar? Wouldn't retrieval be faster without > > iterating through a list? >=20 > Field order may be important. Maybe it could be done with Lists > instead of Vectors, though. > > Lastly how difficult (or possible) is it to do something like extend > > the Document class to have the functionality I want? >=20 > I'm not sure, I never had to do it. I see the class is final, so you > won't be able to extend it. Maybe the final modifier could be removed, > if you present a good use case. Well in my case field order is important, but the order of the individual fields isn't. So I can speed up getFields to roughly O(1) by implementing Document as follows. (I think add() takes a bit of a hit as a result) Hashtable fields =3D new Hashtable(); private float boost =3D 1.0f; public final void add(Field field) { if(fields.contains(field.name)){ =09((LinkedList)(fields.get(field.name))).addLast(field); } else { =09LinkedList al =3D new LinkedList(); =09al.add(field); =09fields.add(al); } } public final void removeField(String name) { if(fields.contains(name)){ =09((LinkedList)(fields.get(name))).removeFirst(); } } =20 public final void removeFields(String name) { =09 if(fields.contains(name)){ =09 =09fields.remove(name); =09 } } public final Field getField(String name) { if(fields.contains(name)){ =09return ((LinkedList)(fields.get(name))).getFirst(); } return null; } public final String get(String name) { =09if(fields.contains(name)){ =09=09return ((Field)((LinkedList)(fields.get(name))).getFirst()).stringVal= ue(); =09} return null; } /** Returns an Enumeration of all the fields in a document. */ public final Enumeration fields() { =09//This one is a little harder. return ((Vector)fields).elements(); } public final Field[] getFields(String name) { List result =3D (LinkedList)(fields.get(name)); if (result.size() =3D=3D 0) return null; return (Field[])result.toArray(new Field[result.size()]); } public final String[] getValues(String name) { List result =3D new ArrayList(); =09Field[] arr =3D getFields(name); for (int i =3D 0; i < arr.length; i++) { Field field =3D arr[i]; if (!field.isBinary()) result.add(field.stringValue()); } if (result.size() =3D=3D 0) return null; return (String[])result.toArray(new String[result.size()]); } (I missed some functions because I got tired and it's nearing the end of the day.) This doesn't solve the original problem of having to have empty string playing placeholder but at least it would lessen the pain a bit. Chris --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org For additional commands, e-mail: java-user-help@lucene.apache.org