package com.sensei.search.nodes;

import java.io.File;
import java.io.FileNotFoundException;

import proj.zoie.api.indexing.IndexReaderDecorator;
import proj.zoie.api.indexing.ZoieIndexableInterpreter;
import proj.zoie.impl.indexing.ZoieConfig;
import proj.zoie.impl.indexing.ZoieSystem;

import com.browseengine.bobo.api.BoboIndexReader;

public class SenseiZoieSystemFactory<V>
{
  protected File _idxDir;
  protected ZoieIndexableInterpreter<V> _interpreter;
  protected IndexReaderDecorator<BoboIndexReader> _indexReaderDecorator;
  
  protected final ZoieConfig _zoieConfig;
  
  public SenseiZoieSystemFactory(File idxDir, ZoieIndexableInterpreter<V> interpreter, IndexReaderDecorator<BoboIndexReader> indexReaderDecorator,
                                 ZoieConfig zoieConfig)
  {
    _idxDir = idxDir;
    _interpreter = interpreter;
    _indexReaderDecorator = indexReaderDecorator;
    _zoieConfig = zoieConfig;
  }
  
  public ZoieSystem<BoboIndexReader,V> getZoieSystem(int partitionId) throws FileNotFoundException
  {
    File partDir = getPath(partitionId);
    if(!partDir.exists())
    {
      throw new FileNotFoundException("partition=" + partitionId + " does not exist");
    }
    return new ZoieSystem<BoboIndexReader,V>(getPath(partitionId), _interpreter, _indexReaderDecorator, _zoieConfig);
  }
  
  // TODO: change to getDirectoryManager
  protected File getPath(int partitionId)
  {
    return new File(_idxDir, "shard"+partitionId);
  }
}

@@ -87,16 +87,49 @@
 ption;%0A%0A
+import org.apache.log4j.Logger;%0A%0A
 import p
@@ -408,16 +408,95 @@
 ry%3CV%3E%0A%7B%0A
+  private static Logger log = Logger.getLogger(SenseiZoieSystemFactory.class);%0A
   protec
@@ -1222,39 +1222,40 @@
     
-throw new FileNotFoundException
+partDir.mkdirs();%0A      log.info
 (%22pa
@@ -1296,16 +1296,36 @@
 ot exist
+, directory created.
 %22);%0A    
@@ -1371,36 +1371,23 @@
 ader,V%3E(
-getPath(partitionId)
+partDir
 , _inter

allow for intial empty indexes