Discussion:
How to add a Lucene index to a jar file?
Bill Janssen
2005-01-17 18:25:08 UTC
Permalink
Hi.

I'd like to package up a Lucene index with the Lucene class files and
my own application classes into a single jar file, so that it forms a
"double-clickable" single-file Java application that supports
searching over the index. However, I'm not sure how to read the index
(create an IndexReader) if the files that form the index are packaged
into the same jar file with the code.

If anyone could shed some light on how to do this, I'd appreciate it.

Thanks!

Bill
Miles Barr
2005-01-17 18:44:57 UTC
Permalink
Post by Bill Janssen
I'd like to package up a Lucene index with the Lucene class files and
my own application classes into a single jar file, so that it forms a
"double-clickable" single-file Java application that supports
searching over the index. However, I'm not sure how to read the index
(create an IndexReader) if the files that form the index are packaged
into the same jar file with the code.
If anyone could shed some light on how to do this, I'd appreciate it.
You'll have to implement org.apache.lucene.store.Directory to load the
index from the JAR file. Take a look at FSDirectory and RAMDirectory for
some more details.

Then you have either load the JAR file with java.util.jar.JarFile to get
to the files or you can use Classloader#getResourceAsStream to get to
them.
--
Miles Barr <***@runtime-collective.com>
Runtime Collective Ltd.
Doug Cutting
2005-01-17 19:10:49 UTC
Permalink
Post by Miles Barr
You'll have to implement org.apache.lucene.store.Directory to load the
index from the JAR file. Take a look at FSDirectory and RAMDirectory for
some more details.
Then you have either load the JAR file with java.util.jar.JarFile to get
to the files or you can use Classloader#getResourceAsStream to get to
them.
The problem is that a jar file entry becomes an InputStream, but
InputStream is not random access, and Lucene requires random access. So
you need to extract the index either to disk or RAM in order to get
random access. I think folks have posted code for this to the list
previously.

Doug
David Spencer
2005-01-17 19:16:39 UTC
Permalink
Post by Doug Cutting
Post by Miles Barr
You'll have to implement org.apache.lucene.store.Directory to load the
index from the JAR file. Take a look at FSDirectory and RAMDirectory for
some more details.
Then you have either load the JAR file with java.util.jar.JarFile to get
to the files or you can use Classloader#getResourceAsStream to get to
them.
The problem is that a jar file entry becomes an InputStream, but
InputStream is not random access, and Lucene requires random access. So
you need to extract the index either to disk or RAM in order to get
random access. I think folks have posted code for this to the list
Isn't "ZipDirectory" the thing to search for?
Post by Doug Cutting
previously.
Doug
---------------------------------------------------------------------
Doug Cutting
2005-01-17 19:28:17 UTC
Permalink
Post by David Spencer
Isn't "ZipDirectory" the thing to search for?
I think it's actually URLDirectory:

http://www.mail-archive.com/lucene-***@jakarta.apache.org/msg02453.html

Doug

Luke Francl
2005-01-17 19:17:36 UTC
Permalink
Post by Doug Cutting
The problem is that a jar file entry becomes an InputStream, but
InputStream is not random access, and Lucene requires random access. So
you need to extract the index either to disk or RAM in order to get
random access. I think folks have posted code for this to the list
previously.
I think it would be cool if Lucene included a class that facilitated
creating a RAMDirectory from an index in a JAR file, for the kind of
point-and-click startup that Bill is talking about.

Regards,
Luke Francl
Loading...