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 2005/04/22 22:06:08 UTC

Fwd: Lucene and Groovy...

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 <je...@gmail.com>
> Date: April 22, 2005 3:18:31 PM EDT
> To: Erik Hatcher <er...@ehatchersolutions.com>
> Subject: Re: Lucene and Groovy...
> Reply-To: Jeremy Rayner <je...@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

Re: Lucene and Groovy...

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Apr 25, 2005, at 2:56 PM, Doug Cutting wrote:

> Erik Hatcher wrote:
>> 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.
>
> +1, but it needs more and better javadoc and unit tests.  Every public 
> method should have a javadoc commment.  Also, there should be some 
> cautions about blithely iterating through all hits.

Thanks for allowing this.  I've added javadoc comments to all public 
methods, made the constructors of HitIterator and Hit package scoped, 
added a unit test, and also added a warning about iterating over all 
hits.  If there is anything else that is needed to finish this off, let 
me know.

	Erik


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


Re: Fwd: Lucene and Groovy...

Posted by Doug Cutting <cu...@apache.org>.
Erik Hatcher wrote:
> 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.

+1, but it needs more and better javadoc and unit tests.  Every public 
method should have a javadoc commment.  Also, there should be some 
cautions about blithely iterating through all hits.

Doug

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