lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From karl wettin <karl.wet...@gmail.com>
Subject Re: why the mixed scopes?
Date Mon, 13 Aug 2007 14:13:42 GMT
I'm not sure whether or not this was a way too lame question and  
suggestion.

Still, I think it makes sense.


9 aug 2007 kl. 15.38 skrev karl wettin:

> Is there a reason for writers to be created via the constructor and  
> the readers to be created via the static scope?
>
> Would it not be much more beautiful and object oriented to handle  
> this using factory methods in Directory? Or perhaps even one layer  
> further down? The patch below will allow for alternative stores  
> (read: LUCENE-550) without changeing more than a single line of  
> code (given that code uses the factory methods).
>
> Also, it would make it much simple to augment Lucene with  
> decorative layers such as notification schemes, et c.
>
> According to /me/ the static scope is a violation of pretty much  
> everything.
>
>
> Index: src/java/org/apache/lucene/store/Index.java
> ===================================================================
> --- src/java/org/apache/lucene/store/Index.java (revision 0)
> +++ src/java/org/apache/lucene/store/Index.java (revision 0)
> @@ -0,0 +1,35 @@
> +package org.apache.lucene.store;
> +
> +import org.apache.lucene.index.IndexReader;
> +import org.apache.lucene.index.IndexWriter;
> +import org.apache.lucene.analysis.Analyzer;
> +
> +import java.io.IOException;
> +
> +/**
> + * A top level store class with factory methods for reader and  
> writer.
> + */
> +public abstract class Index {
> +
> +  public abstract IndexReader indexReaderFactory() throws  
> IOException;
> +  public IndexWriter indexWriterFactory(Analyzer analyzer) throws  
> IOException {
> +    return indexWriterFactory(analyzer, false);
> +  }
> +  public abstract IndexWriter indexWriterFactory(Analyzer  
> analyzer, boolean create) throws IOException;
> +
> +}
> Index: src/java/org/apache/lucene/store/Directory.java
> ===================================================================
> --- src/java/org/apache/lucene/store/Directory.java     (revision  
> 564022)
> +++ src/java/org/apache/lucene/store/Directory.java     (working copy)
> @@ -17,6 +17,10 @@
>   * limitations under the License.
>   */
> +import org.apache.lucene.index.IndexReader;
> +import org.apache.lucene.index.IndexWriter;
> +import org.apache.lucene.analysis.Analyzer;
> +
> import java.io.IOException;
> /** A Directory is a flat list of files.  Files may be written  
> once, when they
> @@ -36,8 +40,16 @@
>   *
>   * @author Doug Cutting
>   */
> -public abstract class Directory {
> +public abstract class Directory extends Index {
> +
> +  public IndexReader indexReaderFactory() throws IOException {
> +    return IndexReader.open(this);
> +  }
> +  public IndexWriter indexWriterFactory(Analyzer analyzer, boolean  
> create) throws IOException {
> +    return new IndexWriter(this, analyzer, create);
> +  }
> +
>    /** Holds the LockFactory instance (implements locking for
>     * this Directory instance). */
>    protected LockFactory lockFactory;
>
>


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


Mime
View raw message