Read Only Directory for Lucene

Jakarta Lucene is a open source search engine written entirely in Java available as a part of the Apache Jakarta Project.

In Lucene FAQ 1.8, you can read that can be used in CD-ROM-based Online Documentation Search, but if you try to use it with an index built on CD-ROM, it will not work. This happen because implementation of org.apache.lucene.store.Directory needs write access right to manage concurrent write operations. But on CD-ROM nobody can write, so I rewrote the class org.apache.lucene.store.FSDirectory to meet this requirement.

The result is the class it.unige.csita.lucene.RODirectory (Read Only Directory).

Download

You can download RODirectory version 0.1 in a jar file (26 kbyte) including source and javadocs.

Usage

Basic usage is simple; in classic way, you write:


    import org.apache.lucene.store.*;
    ...

    Searcher searcher = new IndexSearcher("D:\\index\\");
    Query query = QueryParser.parse("someword",
             "somefield", new SimpleAnalyzer());
    Hits hits = searcher.search(query);

Assuming D: is your CD-ROM drive, with RODirectory, you must write:


    import org.apache.lucene.store.*;
    ...
    import org.apache.lucene.store.Directory;
    import it.unige.csita.lucene.RODirectory;

    Directory dir = RODirectory.getDirectory("D:\\index\\");
    Searcher searcher = new IndexSearcher(dir);
    Query query = QueryParser.parse("someword",
            "somefield", new SimpleAnalyzer());
    Hits hits = searcher.search(query);

Comments

Any suggestion and comment are appreciated. You can write to marco@csita.unige.it