Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Choosing the right Lucene Directory

There are many kind of directory types that can be used to build a Lucene index. Which one is best suited to improve search speed on a RedHat machine (not sure if the OS is relevant or not)?

  • RAMDirectory - Cannot use, index is too big
  • SimpleFSDirectory - Cannot be this one because it's 'Simple'...
  • MMapDirectory - Maybe this one?
  • NIOFSDirectory - Or this one?
  • Any better options?
like image 527
Marsellus Wallace Avatar asked Sep 23 '13 23:09

Marsellus Wallace


1 Answers

Unless you have a good reason to pick one over the others, I'd recommend simply calling FSDirectory.open(File). This allows Lucene to make the decision on which implementation is ideal.

For the curious, here is how the decision is made:

public static FSDirectory open(File path, LockFactory lockFactory) throws IOException {
  if ((Constants.WINDOWS || Constants.SUN_OS || Constants.LINUX)
        && Constants.JRE_IS_64BIT && MMapDirectory.UNMAP_SUPPORTED) {
    return new MMapDirectory(path, lockFactory);
  } else if (Constants.WINDOWS) {
    return new SimpleFSDirectory(path, lockFactory);
  } else {
    return new NIOFSDirectory(path, lockFactory);
  }
}

If you want to try to be surer about getting the ideal pick than that, I can only recommend trying them and profiling, to see which provides the best performance.

like image 57
femtoRgon Avatar answered Nov 07 '22 07:11

femtoRgon