当前位置: 首页>>代码示例>>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;未经允许,请勿转载。