Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for Lucene indexes configuration: directory (mmap, fs), a…
…nalyzers, stopwords, size of buffers
- Loading branch information
Showing
21 changed files
with
797 additions
and
705 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
lucene/src/main/java/com/orientechnologies/lucene/engine/OLuceneDirectoryFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.orientechnologies.lucene.engine; | ||
|
||
import com.orientechnologies.common.log.OLogManager; | ||
import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal; | ||
import com.orientechnologies.orient.core.record.impl.ODocument; | ||
import org.apache.lucene.store.Directory; | ||
import org.apache.lucene.store.MMapDirectory; | ||
import org.apache.lucene.store.NIOFSDirectory; | ||
import org.apache.lucene.store.RAMDirectory; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
/** | ||
* | ||
* | ||
* | ||
* Created by frank on 03/03/2016. | ||
*/ | ||
public class OLuceneDirectoryFactory { | ||
|
||
public static final String OLUCENE_BASE_DIR = "luceneIndexes"; | ||
|
||
public static final String DIRECTORY_TYPE = "directory_type"; | ||
|
||
public static final String DIRECTORY_NIO = "nio"; | ||
public static final String DIRECTORY_MMAP = "mmap"; | ||
public static final String DIRECTORY_RAM = "ram"; | ||
|
||
public static final String DIRECTORY_PATH = "directory_path"; | ||
|
||
public Directory createDirectory(ODatabaseDocumentInternal database, String indexName, ODocument metadata) { | ||
|
||
String luceneType = metadata.containsField(DIRECTORY_TYPE) ? metadata.<String>field(DIRECTORY_TYPE) : DIRECTORY_MMAP; | ||
|
||
if (database.getStorage().getType().equals("memory") || DIRECTORY_RAM.equals(luceneType)) { | ||
return new RAMDirectory(); | ||
} | ||
|
||
return createDirectory(database, indexName, metadata, luceneType); | ||
} | ||
|
||
private Directory createDirectory(ODatabaseDocumentInternal database, String indexName, ODocument metadata, String luceneType) { | ||
String luceneBasePath = metadata.containsField(DIRECTORY_PATH) ? metadata.<String>field(DIRECTORY_PATH) : OLUCENE_BASE_DIR; | ||
|
||
Path luceneIndexPath = Paths.get(database.getStorage().getConfiguration().getDirectory(), luceneBasePath, indexName); | ||
try { | ||
|
||
if (DIRECTORY_NIO.equals(luceneType)) { | ||
return new NIOFSDirectory(luceneIndexPath); | ||
} | ||
|
||
if (DIRECTORY_MMAP.equals(luceneType)) { | ||
return new MMapDirectory(luceneIndexPath); | ||
} | ||
|
||
} catch (IOException e) { | ||
OLogManager.instance().error(this, "unable to create Lucene Directory with type " + luceneType, e); | ||
} | ||
|
||
OLogManager.instance().warn(this, "unable to create Lucene Directory, FALL BACK to ramDir"); | ||
return new RAMDirectory(); | ||
} | ||
|
||
} |
Oops, something went wrong.