當前位置: 首頁>>代碼示例>>Java>>正文


Java FSDirectory.open方法代碼示例

本文整理匯總了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);
	}
}
 
開發者ID:jmfgdev,項目名稱:gitplex-mit,代碼行數:17,代碼來源:DefaultIndexManager.java

示例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;
    }
}
 
開發者ID:Zephery,項目名稱:newblog,代碼行數:29,代碼來源:BlogServiceImpl.java

示例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);
    }
}
 
開發者ID:zhaoxi1988,項目名稱:sjk,代碼行數:24,代碼來源:SpellCheckerServiceImpl.java

示例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);
		}
	}
}
 
開發者ID:Bibliome,項目名稱:alvisnlp,代碼行數:21,代碼來源:AlvisDBIndexer.java

示例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();
    }
 
開發者ID:thingweb,項目名稱:thingweb-directory,代碼行數:24,代碼來源:ThingDirectory.java

示例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);
    }
}
 
開發者ID:lucene4ir,項目名稱:lucene4ir,代碼行數:22,代碼來源:DocumentIndexer.java

示例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);
        }
    }
}
 
開發者ID:sindremehus,項目名稱:subsonic,代碼行數:17,代碼來源:SearchService.java

示例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();
}
 
開發者ID:c0rp-aubakirov,項目名稱:lucene-tutorial,代碼行數:24,代碼來源:MessageIndexer.java

示例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);
}
 
開發者ID:isoboroff,項目名稱:basekb-search,代碼行數:23,代碼來源:FreebaseIndexer.java

示例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);
}
 
開發者ID:iamxiatian,項目名稱:wikit,代碼行數:19,代碼來源:IndexConceptVisitor.java

示例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();
}
 
開發者ID:lukhnos,項目名稱:lucenestudy,代碼行數:48,代碼來源:Suggester.java

示例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();
}
 
開發者ID:lithiumtech,項目名稱:flow,代碼行數:21,代碼來源:LuceneFiler.java

示例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);
}
 
開發者ID:phax,項目名稱:peppol-directory,代碼行數:19,代碼來源:PDLucene.java

示例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);
}
 
開發者ID:tedyli,項目名稱:Tedyli-Searcher,代碼行數:9,代碼來源:indexer.java

示例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();
        }
    }
 
開發者ID:Zephery,項目名稱:newblog,代碼行數:14,代碼來源:BlogServiceImpl.java


注:本文中的org.apache.lucene.store.FSDirectory.open方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。