全文检索例子

全文检索例子

ID:28183431

大小:25.90 KB

页数:22页

时间:2018-12-08

全文检索例子_第1页
全文检索例子_第2页
全文检索例子_第3页
全文检索例子_第4页
全文检索例子_第5页
资源描述:

《全文检索例子》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库

1、实用标准文案本文由美白面膜排行榜www.tompall.com整理全文检索例子lucene3搜索引擎,索引建立搜索排序分页高亮显示,IKAnalyzer分词publicclassLuceneService{privatefinalLoglogger=LogFactory.getLog(LuceneService.class);privatefinalStringdirPath="d:/temp/user";Analyzeranalyzer=newIKAnalyzer();Directorydirectory=null;IndexWriterwriter=null;

2、IndexSearcherindexSearcher=null;privatevoidconfirmDirs(){FileindexFile=newFile(dirPath);if(!indexFile.exists()){indexFile.mkdirs();}if(!indexFile.exists()

3、

4、!indexFile.canWrite()){if(logger.isDebugEnabled())logger.error("索引文件目录创建失败或不可写入!");}}publicvoidinit(){精彩文档实用标准文案confirmDirs();try

5、{Filef=newFile(dirPath);directory=FSDirectory.open(f);}catch(Exceptione){if(logger.isDebugEnabled()){logger.error("解除索引文件锁定失败!"+e.getCause());}}}publicvoidcreateIndex(List<User>userList){init();try{//第一个参数是存放索引目录有FSDirectory(存储到磁盘上)和RAMDirectory(存储到内存中),//第二个参数是使用的分词器,第三个:true,建

6、立全新的索引,false,建立增量索引,第四个是建立的索引的最大长度writer=newIndexWriter(directory,analyzer,true,IndexWriter.MaxFieldLength.LIMITED);writer.setMergeFactor(500);writer.setMaxBufferedDocs(155);精彩文档实用标准文案writer.setMaxFieldLength(Integer.MAX_VALUE);writeIndex(writer,userList);writer.optimize();writer.clos

7、e();}catch(IOExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}publicList<User>search(Stringkeyword){FileindexFile=newFile(dirPath);if(!indexFile.exists()){returnnull;}Directorydir;try{dir=FSDirectory.open(indexFile);indexSearcher=newIndexSearcher(dir);indexSearche

8、r.setSimilarity(newIKSimilarity());//单字段查询,单条件查询//Queryquery=IKQueryParser.parse("userInfo",keyword);精彩文档实用标准文案//多字段,单条件查询String[]fields=newString[]{"userInfo","parameter1"};Queryquery=IKQueryParser.parseMultiField(fields,keyword);//多字体,单条件,多BooleanClause.Occur[]flags,查询条件的组合方式(Or/And

9、)//BooleanClause.Occur[]数组,它表示多个条件之间的关系,//BooleanClause.Occur.MUST表示and,//BooleanClause.Occur.MUST_NOT表示not,//BooleanClause.Occur.SHOULD表示or.//String[]fields=newString[]{"userInfo","parameter1"};//BooleanClause.Occur[]flags=new//BooleanClause.Occur[]{BooleanClause.Occur.MUST,BooleanCl

10、ause.

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。