本文整理匯總了Java中org.apache.lucene.store.FSDirectory.getDirectory方法的典型用法代碼示例。如果您正苦於以下問題:Java FSDirectory.getDirectory方法的具體用法?Java FSDirectory.getDirectory怎麽用?Java FSDirectory.getDirectory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.lucene.store.FSDirectory
的用法示例。
在下文中一共展示了FSDirectory.getDirectory方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import org.apache.lucene.store.FSDirectory; //導入方法依賴的package包/類
public static void main(String[] args) {
try {
Directory directory = FSDirectory.getDirectory("demo index", false);
IndexReader reader = IndexReader.open(directory);
// Term term = new Term("path", "pizza");
// int deleted = reader.delete(term);
// System.out.println("deleted " + deleted +
// " documents containing " + term);
for (int i = 0; i < reader.maxDoc(); i++)
reader.delete(i);
reader.close();
directory.close();
} catch (Exception e) {
System.out.println(" caught a " + e.getClass() +
"\n with message: " + e.getMessage());
}
}
示例2: MixedDirectory
import org.apache.lucene.store.FSDirectory; //導入方法依賴的package包/類
public MixedDirectory(FileSystem readFs, Path readPath, FileSystem writeFs,
Path writePath, Configuration conf) throws IOException {
try {
readDir = new FileSystemDirectory(readFs, readPath, false, conf);
// check writeFS is a local FS?
writeDir = FSDirectory.getDirectory(writePath.toString());
} catch (IOException e) {
try {
close();
} catch (IOException e1) {
// ignore this one, throw the original one
}
throw e;
}
lockFactory = new NoLockFactory();
}
示例3: getId
import org.apache.lucene.store.FSDirectory; //導入方法依賴的package包/類
private String getId(IndexCommit commit) {
StringBuilder sb = new StringBuilder();
Directory dir = commit.getDirectory();
// For anything persistent, make something that will
// be the same, regardless of the Directory instance.
if (dir instanceof FSDirectory) {
FSDirectory fsd = (FSDirectory) dir;
File fdir = fsd.getDirectory();
sb.append(fdir.getPath());
} else {
sb.append(dir);
}
sb.append('/');
sb.append(commit.getGeneration());
return sb.toString();
}
示例4: spellChecker
import org.apache.lucene.store.FSDirectory; //導入方法依賴的package包/類
/**
* 拚寫錯誤的提示修正
*
* @param keyword
* @return
*/
@Override
public List<String> spellChecker(Integer typeId, String sword) {
try {
List<String> strList = new ArrayList<String>();
SpellChecker sp = new SpellChecker(FSDirectory.getDirectory(typeId == appConfig.getGameTypeId() ? appConfig
.getGameSpellIndexDir() : appConfig.getSoftSpellIndexDir()), new JaroWinklerDistance());
String[] suggestions = sp.suggestSimilar(sword, appConfig.getSuggestNum());
for (int i = 0; i < suggestions.length; i++)
strList.add(suggestions[i]);
return strList;
} catch (IOException e) {
logger.error("Exception", e);
return null;
}
}
示例5: initSpellIndex
import org.apache.lucene.store.FSDirectory; //導入方法依賴的package包/類
/**
* 初始化SpellIndex
*
* @throws IOException
*/
public void initSpellIndex(boolean isGame) throws IOException {
FileOPHelper.del(isGame ? appConfig.getGameSpellIndexDir() : appConfig.getSoftSpellIndexDir());
Directory spellIndexDir = FSDirectory.getDirectory(new File(isGame ? appConfig.getGameSpellIndexDir()
: appConfig.getSoftSpellIndexDir()));
SpellChecker spellChecker = new SpellChecker(spellIndexDir);
spellChecker.indexDictionary(new PlainTextDictionary(new File(isGame ? appConfig.getGameSuggestDict()
: appConfig.getSoftSuggestDict())));
spellIndexDir.close();
}
示例6: indexSpellCheck
import org.apache.lucene.store.FSDirectory; //導入方法依賴的package包/類
private void indexSpellCheck(String id) throws SearchException {
if(!spellcheck) return;
IndexReader reader=null;
FSDirectory spellDir=null;
Resource dir = _createSpellDirectory(id);
try {
File spellFile = FileWrapper.toFile(dir);
spellDir = FSDirectory.getDirectory(spellFile);
reader = _getReader(id,false);
Dictionary dictionary = new LuceneDictionary(reader,"contents");
SpellChecker spellChecker = new SpellChecker(spellDir);
spellChecker.indexDictionary(dictionary);
}
catch(IOException ioe) {
throw new SearchException(ioe);
}
finally {
flushEL(reader);
closeEL(reader);
}
}
示例7: setup
import org.apache.lucene.store.FSDirectory; //導入方法依賴的package包/類
/**
* Sets up any Lucene Indexer classes
*
* @param context
* @return
* @throws Exception
*/
public boolean setup(IndexerContext context) throws Exception {
// Make sure the complex queries can use more than the default clause count
BooleanQuery.setMaxClauseCount(Integer.MAX_VALUE);
// Setup the Indexes so they are in a state in which they can immediately
// be accessed
ApplicationPrefs prefs = context.getApplicationPrefs();
{
// Establish the full directory
LOG.info("Starting Lucene disk index");
File path = new File(prefs.get("FILELIBRARY") + Constants.FULL_INDEX);
boolean create = !path.exists();
fullIndex = FSDirectory.getDirectory(prefs.get("FILELIBRARY") + Constants.FULL_INDEX);
if (create) {
LOG.warn("Lucene index not found, creating new index: " + path.getPath());
Analyzer fullAnalyzer = new StandardAnalyzer();
fullWriter = new IndexWriter(fullIndex, fullAnalyzer, true);
fullWriter.close();
}
}
{
// Load up the ram directory
LOG.info("Creating Lucene RAM index...");
// Create the Ram Directory
directoryIndex = new RAMDirectory();
Analyzer directoryAnalyzer = new SnowballAnalyzer("English");
directoryWriter = new IndexWriter(directoryIndex, directoryAnalyzer, true);
directoryWriter.close();
LOG.info("Initialization of RAM index complete...");
}
// Search using the updated index
resetSearchers();
return true;
}
示例8: getSpellChecker
import org.apache.lucene.store.FSDirectory; //導入方法依賴的package包/類
private SpellChecker getSpellChecker(String id) throws IOException {
FSDirectory siDir = FSDirectory.getDirectory(FileWrapper.toFile(_getSpellDirectory(id)));
SpellChecker spellChecker = new SpellChecker(siDir);
return spellChecker;
}
示例9: getSpellCheckerDirectory
import org.apache.lucene.store.FSDirectory; //導入方法依賴的package包/類
/**
* @param language
* @return the Lucene Directory object for indexedClass and Entity. it is constructed as
* "${base-spellchecker-directory}/${indexed-class-name}/${indexedField}" so each field indexes are stored in it's
* own file-directory inside owning-class directory
* @throws IOException
*/
private Directory getSpellCheckerDirectory(String language) throws IOException {
String path = "./spellchecker/lucene/" + language;
return FSDirectory.getDirectory(path);
}