lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Hatcher <e...@ehatchersolutions.com>
Subject Fwd: Lucene and Groovy...
Date Fri, 22 Apr 2005 20:06:08 GMT
Jeremey - I'm passing this on to the Lucene dev list for comment.

There are two .java files attached that may not make it through to the 
list.  These are simple wrappers that do exactly what you'd expect.  
The idea is to make dealing with Lucene Hits more "Java like" with an 
Iterator, which in turn makes this much more amenable to Groovy.

It's syntactic sugar in a sense, but quality expressions are much more 
than syntactic IMO.

What do folks think of this single additional method to Hits and two 
additional classes?

	Erik


Begin forwarded message:

> From: Jeremy Rayner <jeremy.rayner@gmail.com>
> Date: April 22, 2005 3:18:31 PM EDT
> To: Erik Hatcher <erik@ehatchersolutions.com>
> Subject: Re: Lucene and Groovy...
> Reply-To: Jeremy Rayner <jeremy.rayner@gmail.com>
>
> Hi Erik,
>
>>> hits.each {
>>>     println(it["filename"])
>>> }
>
> OK, I've implemented the above now :-)
>
>>>
>>> where 'it' is bound as a a Document instance obtained from 
>>> hits.doc(i)
>>
>> The issue with that is that there are some other methods on Hits that
>> you'd want to access besides just the doc(i).  score(i) for example, 
>> or
>> get the document id with id(i).  Also, the "hit" (excuse the pun) to
>> retrieve a document is made when the doc(i) is called, so you may want
>> to avoid doing that if you're simply iterating the hits but not
>> accessing the underlying data (rare, but possible - and there is a
>> HitCollector facility to allow for this type of thing anyway).
>
> I've created two classes to do this
>
> Hit.java - provides a lazy shell that stores a reference to hits and
> the current index
> HitIterator.java - provides a simple cursor across the hits object
>
> I have also added a minor convienience method to Hits.java which 
> returns
> an Iterator over the hits.
>
>> You guys just let me know what is needed on the Java Lucene side of
>> things and I'll be happy to facilitate any changes needed.
>
> Have a look at the two sources attached, and the patch to Hits.java in 
> Lucene,
> you can have the sources for the lucene distro, I'm sure they'd be
> useful in Java
> too, and they have no mention of groovy in them.  With them in the 
> core distro,
> it'd certainly make lucene even nicer to use :-)
>
> Thanks
>
> jez.
>
>
>
> Index: Hits.java
> ===================================================================
> --- Hits.java   (revision 164251)
> +++ Hits.java   (working copy)
> @@ -18,6 +18,7 @@
>
>  import java.io.IOException;
>  import java.util.Vector;
> +import java.util.Iterator;
>
>  import org.apache.lucene.document.Document;
>
> @@ -160,6 +161,11 @@
>
>      numDocs--;
>    }
> +
> +  public Iterator iterator() {
> +      return new HitIterator(this);
> +  }
> +
>  }
>
>  final class HitDoc {
>
>
>
>
>
> -- 
> http://javanicus.com/blog2

Mime
View raw message