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


Java FSDirectory類代碼示例

本文整理匯總了Java中org.apache.lucene.store.FSDirectory的典型用法代碼示例。如果您正苦於以下問題:Java FSDirectory類的具體用法?Java FSDirectory怎麽用?Java FSDirectory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


FSDirectory類屬於org.apache.lucene.store包,在下文中一共展示了FSDirectory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testMMapDirectory

import org.apache.lucene.store.FSDirectory; //導入依賴的package包/類
public void testMMapDirectory() throws IOException {
    long start = System.currentTimeMillis();
    IndexWriterConfig indexWriterConfig = new IndexWriterConfig(new WhitespaceAnalyzer()).setOpenMode(IndexWriterConfig
            .OpenMode.CREATE);
    FSDirectory open = FSDirectory.open(Paths.get("E:/testlucene"));
    IndexWriter indexWriter = new IndexWriter(open, indexWriterConfig);
    for (int i = 0; i < 10000000; i++) {
        indexWriter.addDocument(addDocument(i));
    }
    indexWriter.commit();
    indexWriter.close();
    long end = System.currentTimeMillis();
    log.error("MMapDirectory consumes {}s!", (end - start) / 1000);
    start = System.currentTimeMillis();
    IndexSearcher indexSearcher = new IndexSearcher(DirectoryReader.open(open));
    int total = 0;
    for (int i = 0; i < 10000000; i++) {
        TermQuery key1 = new TermQuery(new Term("key1", "key" + i));
        TopDocs search = indexSearcher.search(key1, 10);
        total += search.totalHits;
    }
    System.out.println(total);
    end = System.currentTimeMillis();
    log.error("MMapDirectory search consumes {}ms!", (end - start));
}
 
開發者ID:shijiebei2009,項目名稱:RedisDirectory,代碼行數:26,代碼來源:TestLucene.java

示例2: createFSDirectory

import org.apache.lucene.store.FSDirectory; //導入依賴的package包/類
private static FSDirectory createFSDirectory (
        final File indexFolder,
        final LockFactory lockFactory) throws IOException {
    assert indexFolder != null;
    assert lockFactory != null;
    final FSDirectory directory;
    final String dirType = System.getProperty(PROP_DIR_TYPE);
    if(DIR_TYPE_MMAP.equals(dirType)) {
        directory = new MMapDirectory(indexFolder, lockFactory);
    } else if (DIR_TYPE_NIO.equals(dirType)) {
        directory = new NIOFSDirectory(indexFolder, lockFactory);
    } else if (DIR_TYPE_IO.equals(dirType)) {
        directory = new SimpleFSDirectory(indexFolder, lockFactory);
    } else {
        directory = FSDirectory.open(indexFolder, lockFactory);
    }
    return directory;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:LuceneIndex.java

示例3: ajaxbuild

import org.apache.lucene.store.FSDirectory; //導入依賴的package包/類
/**
 * ajax簡曆索引
 */
@Override
public void ajaxbuild() {
    try {
        FileUtils.deleteDirectory(new File(AUTOCOMPLETEPATH));
        logger.info("delete autocomplete file success");
        Directory dir = FSDirectory.open(Paths.get(AUTOCOMPLETEPATH));
        SmartChineseAnalyzer analyzer = new SmartChineseAnalyzer();
        AnalyzingInfixSuggester suggester = new AnalyzingInfixSuggester(dir, analyzer);
        //創建Blog測試數據
        List<Blog> blogs = blogMapper.getAllBlog();
        suggester.build(new BlogIterator(blogs.iterator()));
    } catch (IOException e) {
        System.err.println("Error!");
    }
}
 
開發者ID:Zephery,項目名稱:newblog,代碼行數:19,代碼來源:BlogServiceImpl.java

示例4: 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

示例5: getTempDir

import org.apache.lucene.store.FSDirectory; //導入依賴的package包/類
@SuppressForbidden(reason = "access temp directory for building index")
protected static synchronized FSDirectory getTempDir() {
    if (tmpBuildDir == null) {
        // Lazy init
        String tempDirPath = System.getProperty("java.io.tmpdir");
        if (tempDirPath == null)  {
            throw new RuntimeException("Java has no temporary folder property (java.io.tmpdir)?");
        }
        try {
            tmpBuildDir = FSDirectory.open(PathUtils.get(tempDirPath));
        } catch (IOException ioe) {
            throw new RuntimeException(ioe);
        }
    }
    return tmpBuildDir;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:17,代碼來源:XAnalyzingSuggester.java

示例6: main

import org.apache.lucene.store.FSDirectory; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
	IndexReader reader = DirectoryReader.open(FSDirectory.open(Paths.get(INDEX_DIRECTORY)));
	IndexSearcher indexSearcher = new IndexSearcher(reader);

	Analyzer analyzer = new StandardAnalyzer();
	QueryParser queryParser = new QueryParser(FIELD_CONTENTS, analyzer);
	String searchString = "shakespeare";
	Query query = queryParser.parse(searchString);

	TopDocs results = indexSearcher.search(query, 5);
	ScoreDoc[] hits = results.scoreDocs;

	int numTotalHits = results.totalHits;
	System.out.println(numTotalHits + " total matching documents");

	for(int i=0;i<hits.length;++i) {
		int docId = hits[i].doc;
		Document d = indexSearcher.doc(docId);
		System.out.println((i + 1) + ". " + d.get("path") + " score=" + hits[i].score);
	}
}
 
開發者ID:PacktPublishing,項目名稱:Java-Data-Science-Cookbook,代碼行數:22,代碼來源:SearchFiles.java

示例7: search

import org.apache.lucene.store.FSDirectory; //導入依賴的package包/類
public SearchResult search(String index, String queryString, int page) {
    SearchResult searchResult = null;

    try {
        IndexReader reader = DirectoryReader.open(FSDirectory.open(Paths.get(Properties.getProperties().getProperty(Values.INDEX_LOCATION, Values.DEFAULT_INDEX_LOCATION))));
        IndexSearcher searcher = new IndexSearcher(reader);
        Analyzer analyzer = new StandardAnalyzer();

        // Search over the titles only for the moment
        QueryParser parser = new QueryParser(index, analyzer);
        Query query = parser.parse(queryString);

        searchResult = this.doPagingSearch(reader, searcher, query, queryString, page);
        reader.close();
    }
    catch(Exception ex) {}

    return searchResult;
}
 
開發者ID:boyter,項目名稱:freemoz,代碼行數:20,代碼來源:Searcher.java

示例8: 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:airsonic,項目名稱:airsonic,代碼行數:17,代碼來源:SearchService.java

示例9: 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

示例10: init

import org.apache.lucene.store.FSDirectory; //導入依賴的package包/類
@Before
public void init(){

    if(dir == null){
        try {
            dir = FSDirectory.open(Paths.get(datadir));

            for(int i = 0; i < 10; i++){
                Article article = new Article();
                long createTime = System.currentTimeMillis();
                article.setId(i);
                article.setTitle("titile" + i);
                article.setAuthor("wind" + i);
                article.setContent("content" + i);
                article.setCreateTime(createTime);
                article.setUpdateTime(createTime);
                articleList.add(article);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
開發者ID:followwwind,項目名稱:apache,代碼行數:24,代碼來源:LuceneTest.java

示例11: 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

示例12: 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

示例13: 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());
    }
  }
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:23,代碼來源:DeleteFiles.java

示例14: main

import org.apache.lucene.store.FSDirectory; //導入依賴的package包/類
/**
 * Main entry point. 
 * 
 * @param args the command line arguments.
 * @throws IOException in case of I/O failure.
 * @throws ParseException in case of Query parse exception.
 */
public static void main(String[] args) throws IOException, ParseException {
	// 1. Creates a directory reference. This is where index datafiles will be created.
	Directory directory = FSDirectory.open(new File("/tmp").toPath());
	
	// 2. Creates an IndexWriter
	try (IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig())) {
		
		// 3. Add some data
		indexSomeData(writer);
		
		// 4. Search
		search(directory);			
		
		writer.deleteAll();
	} 
}
 
開發者ID:agazzarini,項目名稱:as-full-text-search-server,代碼行數:24,代碼來源:LuceneBasicFlowExample.java

示例15: test

import org.apache.lucene.store.FSDirectory; //導入依賴的package包/類
@Test
public void test() throws Exception {
    Path path = FileSystems.getDefault().getPath("", "index");
    Directory directory = FSDirectory.open(path);
    Analyzer analyzer = new StandardAnalyzer();
    IndexWriterConfig indexWriterConfig = new IndexWriterConfig(analyzer).setOpenMode(IndexWriterConfig.OpenMode.CREATE);
    IndexWriter indexWriter = new IndexWriter(directory, indexWriterConfig);
    Document document = new Document();
    document.add(new LegacyLongField("id", 5499, Field.Store.YES));
    document.add(new Field("title", "小米6", TYPE_STORED));
    document.add(new Field("sellPoint", "驍龍835,6G內存,雙攝!", TYPE_STORED));
    document.
    indexWriter.addDocument(document);
    indexWriter.commit();
    indexWriter.close();
}
 
開發者ID:felayman,項目名稱:elasticsearch-full,代碼行數:17,代碼來源:CreateIndexDemo.java


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