本文整理汇总了Java中org.apache.lucene.store.SimpleFSDirectory类的典型用法代码示例。如果您正苦于以下问题:Java SimpleFSDirectory类的具体用法?Java SimpleFSDirectory怎么用?Java SimpleFSDirectory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SimpleFSDirectory类属于org.apache.lucene.store包,在下文中一共展示了SimpleFSDirectory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: acquireFSLockForPaths
import org.apache.lucene.store.SimpleFSDirectory; //导入依赖的package包/类
/**
* Acquires, then releases, all {@code write.lock} files in the given
* shard paths. The "write.lock" file is assumed to be under the shard
* path's "index" directory as used by Elasticsearch.
*
* @throws LockObtainFailedException if any of the locks could not be acquired
*/
public static void acquireFSLockForPaths(IndexSettings indexSettings, Path... shardPaths) throws IOException {
Lock[] locks = new Lock[shardPaths.length];
Directory[] dirs = new Directory[shardPaths.length];
try {
for (int i = 0; i < shardPaths.length; i++) {
// resolve the directory the shard actually lives in
Path p = shardPaths[i].resolve("index");
// open a directory (will be immediately closed) on the shard's location
dirs[i] = new SimpleFSDirectory(p, indexSettings.getValue(FsDirectoryService.INDEX_LOCK_FACTOR_SETTING));
// create a lock for the "write.lock" file
try {
locks[i] = dirs[i].obtainLock(IndexWriter.WRITE_LOCK_NAME);
} catch (IOException ex) {
throw new LockObtainFailedException("unable to acquire " +
IndexWriter.WRITE_LOCK_NAME + " for " + p, ex);
}
}
} finally {
IOUtils.closeWhileHandlingException(locks);
IOUtils.closeWhileHandlingException(dirs);
}
}
示例2: load
import org.apache.lucene.store.SimpleFSDirectory; //导入依赖的package包/类
/**
* Loads information about the Elasticsearch keystore from the provided config directory.
*
* {@link #decrypt(char[])} must be called before reading or writing any entries.
* Returns {@code null} if no keystore exists.
*/
public static KeyStoreWrapper load(Path configDir) throws IOException {
Path keystoreFile = keystorePath(configDir);
if (Files.exists(keystoreFile) == false) {
return null;
}
SimpleFSDirectory directory = new SimpleFSDirectory(configDir);
try (IndexInput indexInput = directory.openInput(KEYSTORE_FILENAME, IOContext.READONCE)) {
ChecksumIndexInput input = new BufferedChecksumIndexInput(indexInput);
CodecUtil.checkHeader(input, KEYSTORE_FILENAME, FORMAT_VERSION, FORMAT_VERSION);
byte hasPasswordByte = input.readByte();
boolean hasPassword = hasPasswordByte == 1;
if (hasPassword == false && hasPasswordByte != 0) {
throw new IllegalStateException("hasPassword boolean is corrupt: "
+ String.format(Locale.ROOT, "%02x", hasPasswordByte));
}
String type = input.readString();
String secretKeyAlgo = input.readString();
byte[] keystoreBytes = new byte[input.readInt()];
input.readBytes(keystoreBytes, 0, keystoreBytes.length);
CodecUtil.checkFooter(input);
return new KeyStoreWrapper(hasPassword, type, secretKeyAlgo, keystoreBytes);
}
}
示例3: FbEntitySearcher
import org.apache.lucene.store.SimpleFSDirectory; //导入依赖的package包/类
public FbEntitySearcher(String indexDir, int numOfDocs, String searchingStrategy) throws IOException {
LogInfo.begin_track("Constructing Searcher");
if (!searchingStrategy.equals("exact") && !searchingStrategy.equals("inexact"))
throw new RuntimeException("Bad searching strategy: " + searchingStrategy);
this.searchStrategy = searchingStrategy;
queryParser = new QueryParser(
Version.LUCENE_44,
FbIndexField.TEXT.fieldName(),
searchingStrategy.equals("exact") ? new KeywordAnalyzer() : new StandardAnalyzer(Version.LUCENE_44));
LogInfo.log("Opening index dir: " + indexDir);
IndexReader indexReader = DirectoryReader.open(SimpleFSDirectory.open(new File(indexDir)));
indexSearcher = new IndexSearcher(indexReader);
LogInfo.log("Opened index with " + indexReader.numDocs() + " documents.");
this.numOfDocs = numOfDocs;
LogInfo.end_track();
}
示例4: acquireFSLockForPaths
import org.apache.lucene.store.SimpleFSDirectory; //导入依赖的package包/类
/**
* Acquires, then releases, all {@code write.lock} files in the given
* shard paths. The "write.lock" file is assumed to be under the shard
* path's "index" directory as used by Elasticsearch.
*
* @throws LockObtainFailedException if any of the locks could not be acquired
*/
public static void acquireFSLockForPaths(Settings indexSettings, Path... shardPaths) throws IOException {
Lock[] locks = new Lock[shardPaths.length];
Directory[] dirs = new Directory[shardPaths.length];
try {
for (int i = 0; i < shardPaths.length; i++) {
// resolve the directory the shard actually lives in
Path p = shardPaths[i].resolve("index");
// open a directory (will be immediately closed) on the shard's location
dirs[i] = new SimpleFSDirectory(p, FsDirectoryService.buildLockFactory(indexSettings));
// create a lock for the "write.lock" file
try {
locks[i] = dirs[i].obtainLock(IndexWriter.WRITE_LOCK_NAME);
} catch (IOException ex) {
throw new LockObtainFailedException("unable to acquire " +
IndexWriter.WRITE_LOCK_NAME + " for " + p);
}
}
} finally {
IOUtils.closeWhileHandlingException(locks);
IOUtils.closeWhileHandlingException(dirs);
}
}
示例5: init
import org.apache.lucene.store.SimpleFSDirectory; //导入依赖的package包/类
private static void init() {
if (indexWriter==null || searcherManager==null) {
try {
// load directory path
Properties properties = PropertiesUtil.loadProperties(PropertiesUtil.DEFAULT_CONFIG);
String luceneDirectory = PropertiesUtil.getString(properties, "lucene.directory");
// directory
directory = new SimpleFSDirectory(Paths.get(luceneDirectory));
// IndexWriter
Analyzer analyzer = new SmartChineseAnalyzer();
IndexWriterConfig indexWriterConfig = new IndexWriterConfig(analyzer);
indexWriter = new IndexWriter(directory, indexWriterConfig);
// SearcherManager
searcherManager = new SearcherManager(indexWriter, false, new SearcherFactory());
TrackingIndexWriter trackingIndexWriter = new TrackingIndexWriter(indexWriter);
ControlledRealTimeReopenThread controlledRealTimeReopenThread = new ControlledRealTimeReopenThread<IndexSearcher>(trackingIndexWriter, searcherManager, 5.0, 0.025);
controlledRealTimeReopenThread.setDaemon(true);//设为后台进程
controlledRealTimeReopenThread.start();
} catch (IOException e) {
logger.error("", e);
}
}
}
示例6: build
import org.apache.lucene.store.SimpleFSDirectory; //导入依赖的package包/类
/**
* Crea el buscador a partir del índice pasado como argumento de entrada
* @param index índice con el que crear el buscador
*/
@Override
public void build(Index index) {
try{
//apertura del indice
Directory directory = new SimpleFSDirectory(new File(index.getPath()));
this.ireader = IndexReader.open(directory);
this.isearcher = new IndexSearcher(this.ireader);
//query parser, parsea igual que el creador de indices.
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_31);
this.qParser = new QueryParser(Version.LUCENE_31, "content", analyzer);
}catch(Exception e){
Logger.getLogger(LuceneSearcher.class.getName()).log(Level.SEVERE, null, e);
}
}
示例7: Json2Lucene
import org.apache.lucene.store.SimpleFSDirectory; //导入依赖的package包/类
public Json2Lucene(final String luceneDir,
final boolean store,
final boolean append) throws IOException {
if (luceneDir == null) {
throw new NullPointerException("luceneDir");
}
final Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_4_9);
final IndexWriterConfig config = new IndexWriterConfig(
Version.LUCENE_4_9, analyzer);
config.setOpenMode(append ? IndexWriterConfig.OpenMode.APPEND
: IndexWriterConfig.OpenMode.CREATE);
directory = new SimpleFSDirectory(new File(luceneDir));
iwriter = new IndexWriter(directory, config);
this.store = store ? Field.Store.YES : Field.Store.NO;
}
示例8: run
import org.apache.lucene.store.SimpleFSDirectory; //导入依赖的package包/类
private int run(String[] args) throws Exception {
StandardQueryParser parser = new StandardQueryParser(Indexer.LUCENE_ANALYZER);
//try (Directory indexDirectory = new MMapDirectory(new File(indexName))) {
//try (Directory indexDirectory = new NIOFSDirectory(new File(indexName))) {
try (Directory indexDirectory = new SimpleFSDirectory(new File(indexName))) {
try (IndexReader indexReader = DirectoryReader.open(indexDirectory)) {
IndexSearcher indexSearcher = new IndexSearcher(indexReader, Executors.newFixedThreadPool(this.maxThreadCount));
BufferedReader queryReader = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Type 'help' for help, type 'exit' or 'quit' to leave.");
System.out.flush();
String queryExpr;
do {
System.out.print(">>> ");
System.out.flush();
queryExpr = queryReader.readLine();
} while (queryExpr != null && processQuery(indexSearcher, parser, queryExpr));
}
}
return 0;
}
示例9: Indexer
import org.apache.lucene.store.SimpleFSDirectory; //导入依赖的package包/类
public Indexer(JSAPResult config) throws IOException {
String outputPath = config.getString(OUTPUT_PATH, "<NONE>");
if (!outputPath.equals("<NONE>")) {
SimpleFSDirectory idx_dir = new SimpleFSDirectory(new File(
outputPath));
IndexWriterConfig indexConfig = new IndexWriterConfig(
Version.LUCENE_4_10_2, analyzer);
this.writer = new IndexWriter(idx_dir, indexConfig);
} else {
this.writer = null;
}
this.joiner = Joiner.on(" ").skipNulls();
this.config = config;
Options options = new Options();
options.createIfMissing(true);
leveldb = factory.open(new File(outputPath, "leveldb"), options);
}
示例10: getIndex
import org.apache.lucene.store.SimpleFSDirectory; //导入依赖的package包/类
private Directory getIndex(String indexPath, boolean onRAM) {
Directory index = null;
try {
Directory dir = new SimpleFSDirectory(new File(indexPath));
if(onRAM){
index = new RAMDirectory(dir);
dir.close();
return index;
}
else {
return dir;
}
} catch (IOException e) {
e.printStackTrace();
}
return index;
}
示例11: BabelNet
import org.apache.lucene.store.SimpleFSDirectory; //导入依赖的package包/类
/**
* The private constructor used to initialize the BabelNet indexes
*
* @throws IOException
*/
private BabelNet() throws IOException
{
BabelNetConfiguration config = BabelNetConfiguration.getInstance();
String lexiconFile = config.getBabelNetLexiconIndexDir();
String dictionaryFile = config.getBabelNetDictIndexDir();
String glossFile = config.getBabelNetGlossIndexDir();
String graphFile = config.getBabelNetGraphIndexDir();
Directory lexiconDir = new SimpleFSDirectory(new File(lexiconFile));
Directory dictionaryDir = new SimpleFSDirectory(new File(dictionaryFile));
Directory glossDir = new SimpleFSDirectory(new File(glossFile));
Directory graphDir = new SimpleFSDirectory(new File(graphFile));
log.info("OPENING BABEL LEXICON FROM: " + lexiconFile);
log.info("OPENING BABEL DICTIONARY FROM: " + dictionaryFile);
log.info("OPENING BABEL GLOSSES FROM: " + glossFile);
log.info("OPENING BABEL GRAPH FROM: " + graphFile);
// apre gli indici e li tiene aperti
this.lexicon = new IndexSearcher(lexiconDir, true);
this.dictionary = new IndexSearcher(dictionaryDir, true);
this.glosses = new IndexSearcher(glossDir, true);
this.graph = new IndexSearcher(graphDir, true);
}
示例12: getLoaded
import org.apache.lucene.store.SimpleFSDirectory; //导入依赖的package包/类
@Override
public List<RepositoryInfo> getLoaded(final List<RepositoryInfo> repos) {
final List<RepositoryInfo> toRet = new ArrayList<RepositoryInfo>(repos.size());
for (final RepositoryInfo repo : repos) {
File loc = new File(getDefaultIndexLocation(), repo.getId()); // index folder
try {
if (loc.exists() && new File(loc, "timestamp").exists() && DirectoryReader.indexExists(new SimpleFSDirectory(loc.toPath()))) {
toRet.add(repo);
}
} catch (IOException ex) {
LOGGER.log(Level.FINER, "Index Not Available: " +repo.getId() + " at: " + loc.getAbsolutePath(), ex);
}
}
return toRet;
}
示例13: newFSDirectory
import org.apache.lucene.store.SimpleFSDirectory; //导入依赖的package包/类
protected Directory newFSDirectory(Path location, LockFactory lockFactory) throws IOException {
final String storeType = indexSettings.getSettings().get(IndexModule.INDEX_STORE_TYPE_SETTING.getKey(),
IndexModule.Type.FS.getSettingsKey());
if (IndexModule.Type.FS.match(storeType)) {
return FSDirectory.open(location, lockFactory); // use lucene defaults
} else if (IndexModule.Type.SIMPLEFS.match(storeType)) {
return new SimpleFSDirectory(location, lockFactory);
} else if (IndexModule.Type.NIOFS.match(storeType)) {
return new NIOFSDirectory(location, lockFactory);
} else if (IndexModule.Type.MMAPFS.match(storeType)) {
return new MMapDirectory(location, lockFactory);
}
throw new IllegalArgumentException("No directory found for type [" + storeType + "]");
}
示例14: tryOpenIndex
import org.apache.lucene.store.SimpleFSDirectory; //导入依赖的package包/类
/**
* Tries to open an index for the given location. This includes reading the
* segment infos and possible corruption markers. If the index can not
* be opened, an exception is thrown
*/
public static void tryOpenIndex(Path indexLocation, ShardId shardId, NodeEnvironment.ShardLocker shardLocker, Logger logger) throws IOException, ShardLockObtainFailedException {
try (ShardLock lock = shardLocker.lock(shardId, TimeUnit.SECONDS.toMillis(5));
Directory dir = new SimpleFSDirectory(indexLocation)) {
failIfCorrupted(dir, shardId);
SegmentInfos segInfo = Lucene.readSegmentInfos(dir);
logger.trace("{} loaded segment info [{}]", shardId, segInfo);
}
}
示例15: save
import org.apache.lucene.store.SimpleFSDirectory; //导入依赖的package包/类
/** Write the keystore to the given config directory. */
void save(Path configDir) throws Exception {
char[] password = this.keystorePassword.get().getPassword();
SimpleFSDirectory directory = new SimpleFSDirectory(configDir);
// write to tmp file first, then overwrite
String tmpFile = KEYSTORE_FILENAME + ".tmp";
try (IndexOutput output = directory.createOutput(tmpFile, IOContext.DEFAULT)) {
CodecUtil.writeHeader(output, KEYSTORE_FILENAME, FORMAT_VERSION);
output.writeByte(password.length == 0 ? (byte)0 : (byte)1);
output.writeString(type);
output.writeString(secretFactory.getAlgorithm());
ByteArrayOutputStream keystoreBytesStream = new ByteArrayOutputStream();
keystore.get().store(keystoreBytesStream, password);
byte[] keystoreBytes = keystoreBytesStream.toByteArray();
output.writeInt(keystoreBytes.length);
output.writeBytes(keystoreBytes, keystoreBytes.length);
CodecUtil.writeFooter(output);
}
Path keystoreFile = keystorePath(configDir);
Files.move(configDir.resolve(tmpFile), keystoreFile, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE);
PosixFileAttributeView attrs = Files.getFileAttributeView(keystoreFile, PosixFileAttributeView.class);
if (attrs != null) {
// don't rely on umask: ensure the keystore has minimal permissions
attrs.setPermissions(PosixFilePermissions.fromString("rw-------"));
}
}