本文整理匯總了Java中org.apache.lucene.store.FSDirectory.open方法的典型用法代碼示例。如果您正苦於以下問題:Java FSDirectory.open方法的具體用法?Java FSDirectory.open怎麽用?Java FSDirectory.open使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.lucene.store.FSDirectory
的用法示例。
在下文中一共展示了FSDirectory.open方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: isIndexed
import org.apache.lucene.store.FSDirectory; //導入方法依賴的package包/類
@Override
public boolean isIndexed(Project project, ObjectId commit) {
File indexDir = storageManager.getProjectIndexDir(project.getForkRoot().getId());
try (Directory directory = FSDirectory.open(indexDir)) {
if (DirectoryReader.indexExists(directory)) {
try (IndexReader reader = DirectoryReader.open(directory)) {
IndexSearcher searcher = new IndexSearcher(reader);
return getCurrentCommitIndexVersion().equals(getCommitIndexVersion(searcher, commit));
}
} else {
return false;
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例2: ajaxsearch
import org.apache.lucene.store.FSDirectory; //導入方法依賴的package包/類
/**
* 根據關鍵詞查找
*
* @param keyword
* @return
*/
@Override
public Set<String> ajaxsearch(String keyword) {
try {
Directory dir = FSDirectory.open(Paths.get(AUTOCOMPLETEPATH));
SmartChineseAnalyzer analyzer = new SmartChineseAnalyzer();
AnalyzingInfixSuggester suggester = new AnalyzingInfixSuggester(dir, analyzer);
List<String> list = lookup(suggester, keyword);
list.sort((o1, o2) -> {
if (o1.length() > o2.length()) {
return 1;
} else {
return -1;
}
});
Set<String> set = new LinkedHashSet<>(list);
ssubSet(set, 7);
return set;
} catch (IOException e) {
System.err.println("Error!");
return null;
}
}
示例3: reset
import org.apache.lucene.store.FSDirectory; //導入方法依賴的package包/類
@PostConstruct
public void reset() {
String indexDir = appConfig.getAllSpellCheckerDir();
try {
Directory spellcheckDir = FSDirectory.open(new File(indexDir));
if (!IndexReader.indexExists(spellcheckDir)) {
logger.info("Please reset index firstly!");
return;
}
SpellChecker newSpellChecker = new SpellChecker(spellcheckDir);
newSpellChecker.setStringDistance(new JaroWinklerDistance());
newSpellChecker.setAccuracy(0.7f);
if (spellChecker == null) {
spellChecker = newSpellChecker;
} else {
final Closeable preSpellChecker = spellChecker;
spellChecker = newSpellChecker;
IOUtils.closeQuietly(preSpellChecker);
}
} catch (Exception e) {
logger.error("Exception", e);
}
}
示例4: process
import org.apache.lucene.store.FSDirectory; //導入方法依賴的package包/類
@Override
public void process(ProcessingContext<Corpus> ctx, Corpus corpus) throws ModuleException {
try (KeywordAnalyzer kwa = new KeywordAnalyzer()) {
IndexWriterConfig writerConfig = new IndexWriterConfig(Version.LUCENE_36, kwa);
writerConfig.setOpenMode(append ? OpenMode.CREATE_OR_APPEND : OpenMode.CREATE);
try (Directory dir = FSDirectory.open(indexDir)) {
try (IndexWriter writer = new IndexWriter(dir, writerConfig)) {
AlvisDBIndexerResolvedObjects resObj = getResolvedObjects();
Logger logger = getLogger(ctx);
EvaluationContext evalCtx = new EvaluationContext(logger);
for (ADBElements.Resolved ent : resObj.elements) {
ent.indexElements(logger, writer, evalCtx, corpus);
}
}
}
catch (IOException e) {
rethrow(e);
}
}
}
示例5: init
import org.apache.lucene.store.FSDirectory; //導入方法依賴的package包/類
public void init(String db, String uri, String lucene) {
Dataset ds = TDBFactory.createDataset(db);
// Lucene configuration
try {
Directory luceneDir = FSDirectory.open(new File(lucene));
EntityDefinition entDef = new EntityDefinition("comment", "text", RDFS.comment);
// Set uid in order to remove index entries automatically
entDef.setUidField("uid");
StandardAnalyzer stAn = new StandardAnalyzer(Version.LUCENE_4_9);
dataset = TextDatasetFactory.createLucene(ds, luceneDir, entDef, stAn);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
baseURI = uri;
servers = new ArrayList<>();
tdQueue = new PriorityQueue<ThingDescription>();
loadTDQueue();
}
示例6: createWriter
import org.apache.lucene.store.FSDirectory; //導入方法依賴的package包/類
public void createWriter(String indexPath){
/*
The indexPath specifies where to create the index
*/
// I am can imagine that there are lots of ways to create indexers -
// We could add in some parameters to customize its creation
try {
Directory dir = FSDirectory.open(Paths.get(indexPath));
System.out.println("Indexing to directory '" + indexPath + "'...");
IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
writer = new IndexWriter(dir, iwc);
} catch (IOException e){
e.printStackTrace();
System.exit(1);
}
}
示例7: removeLocks
import org.apache.lucene.store.FSDirectory; //導入方法依賴的package包/類
private void removeLocks() {
for (IndexType indexType : IndexType.values()) {
Directory dir = null;
try {
dir = FSDirectory.open(getIndexDirectory(indexType));
if (IndexWriter.isLocked(dir)) {
IndexWriter.unlock(dir);
LOG.info("Removed Lucene lock file in " + dir);
}
} catch (Exception x) {
LOG.warn("Failed to remove Lucene lock file in " + dir, x);
} finally {
FileUtil.closeQuietly(dir);
}
}
}
示例8: index
import org.apache.lucene.store.FSDirectory; //導入方法依賴的package包/類
/**
* Indexing documents using provided Analyzer
*
* @param create to decide create new or append to previous one
* @throws IOException
*/
public void index(final Boolean create, List<Document> documents, Analyzer analyzer) throws IOException {
final Directory dir = FSDirectory.open(Paths.get(pathToIndexFolder));
final IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
if (create) {
// Create a new index in the directory, removing any
// previously indexed documents:
iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
}
else {
// Add new documents to an existing index:
iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
}
final IndexWriter w = new IndexWriter(dir, iwc);
w.addDocuments(documents);
w.close();
}
示例9: initializeIndexBuilder
import org.apache.lucene.store.FSDirectory; //導入方法依賴的package包/類
public void initializeIndexBuilder() throws Exception {
// Create a new index directory and writer to index a triples file.
// Raise an error if an index already exists, so we don't accidentally overwrite it.
String indexDir = getIndexDirectoryName();
if ((new File(indexDir)).isDirectory())
throw new IOException("Index directory already exists, remove it before indexing");
indexDirectory = FSDirectory.open(Paths.get(indexDir));
IndexWriterConfig iwc = new IndexWriterConfig(getIndexAnalyzer());
// we always create a new index from scratch:
iwc.setOpenMode(OpenMode.CREATE);
iwc.setCodec(new Lucene54Codec(Mode.BEST_SPEED)); // the default
//iwc.setCodec(new Lucene54Codec(Mode.BEST_COMPRESSION)); // slower, but better compression
indexWriter = new IndexWriter(indexDirectory, iwc);
indexAnalyzer = getIndexAnalyzer();
if (INDEX_PREDICATES) printlnProg("Indexing individual predicates");
if (INDEX_TEXT) printlnProg("Indexing combined predicate text values");
if (INDEX_LANGUAGE) printlnProg("Indexing predicates for language(s): " + supportedLanguages);
}
示例10: openWriter
import org.apache.lucene.store.FSDirectory; //導入方法依賴的package包/類
private IndexWriter openWriter(Conf conf, boolean create) throws IOException {
File indexDir = new File(conf.getEsaIndexDir());
indexDir.mkdirs();
System.out.println("Create index on " + indexDir.getAbsolutePath());
Directory fsDirectory = FSDirectory.open(indexDir);
IndexWriterConfig config = new IndexWriterConfig(Conf.LUCENE_VERSION, new ESAAnalyzer(conf));
config.setSimilarity(new ESASimilarity());
if (create) {
// Create a new index in the directory, removing any
// previously indexed documents:
config.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
} else {
// Add new documents to an existing index:
config.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
}
return new IndexWriter(fsDirectory, config);
}
示例11: rebuild
import org.apache.lucene.store.FSDirectory; //導入方法依賴的package包/類
/**
* Rebuild a suggestion index from the document index.
*
* This method iterates through the entire document index and makes sure that only unique titles
* are indexed.
*
* @param indexRoot The parent directory inside which both the document index and the suggestion
* index lives.
* @throws IOException
*/
public static void rebuild(String indexRoot) throws IOException {
Path indexRootPath = Paths.get(indexRoot);
Path suggestionPath = getSuggestionIndexPath(indexRootPath);
// Delete the suggestion index if it exists.
if (Files.exists(suggestionPath)) {
Util.deletePath(suggestionPath);
}
// Create the suggestion index.
Analyzer analyzer = Indexer.getAnalyzer();
Directory suggestionDir = FSDirectory.open(getSuggestionIndexPath(indexRootPath));
AnalyzingInfixSuggester suggester = new AnalyzingInfixSuggester(suggestionDir, analyzer);
// Open the document index.
Directory indexDir = FSDirectory.open(Indexer.getMainIndexPath(indexRootPath));
IndexReader reader = DirectoryReader.open(indexDir);
// Get a document iterator.
DocumentDictionary docDict = new DocumentDictionary(reader, Indexer.TITLE_FIELD_NAME, null);
InputIterator iterator = docDict.getEntryIterator();
Set<BytesRef> titleSet = new HashSet<>();
BytesRef next;
while ((next = iterator.next()) != null) {
if (titleSet.contains(next)) {
continue;
}
titleSet.add(next);
suggester.add(next, null, 0, null);
}
reader.close();
suggester.commit();
suggester.close();
}
示例12: LuceneFiler
import org.apache.lucene.store.FSDirectory; //導入方法依賴的package包/類
public LuceneFiler(@Nonnull Filer delegate, @Nonnull Config config) throws IOException {
super(delegate);
String path = config.getString("index.path");
maxAge = config.getTime("index.maxAge", "-1");
double maxMergeMb = config.getDouble("index.maxMergeMb", 4);
double maxCachedMb = config.getDouble("index.maxCacheMb", 64);
long targetMaxStale = config.getTime("index.targetMaxStale", "5s");
long targetMinStale = config.getTime("index.targetMinStale", "1s");
Directory dir = FSDirectory.open(new File(path).toPath());
NRTCachingDirectory cachingDir = new NRTCachingDirectory(dir, maxMergeMb, maxCachedMb);
IndexWriterConfig writerConfig = new IndexWriterConfig(null);
writerConfig.setOpenMode(OpenMode.CREATE_OR_APPEND);
writer = new TrackingIndexWriter(new IndexWriter(cachingDir, writerConfig));
manager = new SearcherManager(writer.getIndexWriter(), true, new SearcherFactory());
thread = new ControlledRealTimeReopenThread<>(writer, manager, targetMaxStale, targetMinStale);
thread.start();
}
示例13: PDLucene
import org.apache.lucene.store.FSDirectory; //導入方法依賴的package包/類
public PDLucene () throws IOException
{
// Where to store the index files
final Path aPath = getLuceneIndexDir ().toPath ();
m_aDir = FSDirectory.open (aPath);
// Analyzer to use
m_aAnalyzer = createAnalyzer ();
// Create the index writer
final IndexWriterConfig aWriterConfig = new IndexWriterConfig (m_aAnalyzer);
aWriterConfig.setOpenMode (OpenMode.CREATE_OR_APPEND);
m_aIndexWriter = new IndexWriter (m_aDir, aWriterConfig);
// Reader and searcher are opened on demand
s_aLogger.info ("Lucene index operating on " + aPath);
}
示例14: Indexer
import org.apache.lucene.store.FSDirectory; //導入方法依賴的package包/類
public Indexer(String indexDirectoryPath) throws IOException {
// Directory directory = new RAMDirectory();
Directory indexDirectory = FSDirectory.open(Paths.get(indexDirectoryPath));
// create the indexer
Analyzer analyzer = new StandardAnalyzer();
IndexWriterConfig config = new IndexWriterConfig(analyzer);
writer = new IndexWriter(indexDirectory, config);
}
示例15: main
import org.apache.lucene.store.FSDirectory; //導入方法依賴的package包/類
public static void main(String[] args) {
try {
Directory dir = FSDirectory.open(Paths.get(AUTOCOMPLETEPATH));
RAMDirectory indexDir = new RAMDirectory();
SmartChineseAnalyzer analyzer = new SmartChineseAnalyzer();
AnalyzingInfixSuggester suggester = new AnalyzingInfixSuggester(dir, analyzer);
IBlogService blogService = new BlogServiceImpl();
lookup(suggester, "jav");
// new BlogServiceImpl().ajaxsearch("北京");
} catch (Exception e) {
e.printStackTrace();
}
}