lucene索引库优化二
2014-02-10 12:21
429 查看
其实提高索引查询的速度最简洁的方法技术将索引放到内存当中,减少IO,从而提高查询速度:
public class MergePolicies { public static void main(String[] args) throws Exception { long start=new Date().getTime(); IOContext context=new IOContext(); Directory dir=FSDirectory.open(new File("E:/docData/indexDir")); /** * 把索引存储到内存中 */ Directory directory=new RAMDirectory(dir,context); IndexReader reader=DirectoryReader.open(directory); IndexSearcher searcher=new IndexSearcher(reader); /** * 多条件查询 */ String[] fields={"content"}; QueryParser parser=new MultiFieldQueryParser(Version.LUCENE_44, fields,new StandardAnalyzer(Version.LUCENE_44)); Query query = parser.parse("源码"); TopScoreDocCollector results=TopScoreDocCollector.create(10, false); searcher.search(query, results); ScoreDoc[] scoreDocs = results.topDocs().scoreDocs; System.out.println(scoreDocs.length); /** * 可以在此分页 * start 起始位置 * length 记录数 */ for(int i=0;i<scoreDocs.length;i++){ Document doc= searcher.doc(scoreDocs[i].doc); System.out.println(doc.getField("filename")+" "+scoreDocs[i].toString()); } long end=new Date().getTime(); System.out.println("took time:"+(end-start)); } }
相关文章推荐
- lucene_indexWriter说明、索引库优化
- 全文检索之lucene的优化篇--创建索引库
- lucene_indexWriter说明、索引库优化
- JAVAWEB开发之Lucene详解——Lucene入门及使用场景、全文检索、索引CRUD、优化索引库、分词器、高亮、相关度排序、各种查询
- lucene_indexWriter说明、索引库优化
- Lucene 索引库的优化
- lucene学习四:索引库的优化
- 全文检索之lucene的优化篇--创建索引库
- Lucene索引库的简单优化
- Lucene索引库的优化
- 【Lucene】使用反射技术优化Lucene索引库的查询与创建
- Lucene索引库的简单优化
- Lucene索引库的简单优化
- lucene索引库优化一
- lucene_indexWriter说明、索引库优化
- Lucene第二篇【抽取工具类、索引库优化、分词器、高亮、摘要、排序、多条件搜索】
- Lucene第二篇【抽取工具类、索引库优化、分词器、高亮、摘要、排序、多条件搜索】
- 【Lucene】索引库的优化
- lucene索引库优化建议
- [DotLucene]优化索引库