lucene 4.10实现多域检索和区间范围检索
来源:互联网 发布:cms文章管理系统 编辑:程序博客网 时间:2024/06/02 18:53
多域检索和区间范围检索使用频率非常高
下面的代码展示了两个的使用方法,同时顺便介绍了布尔查询类BooleanQuery,关系有三种:Occur.MUST,Occur.MUST_NOT,Occur.SHOULD
//实现逻辑检索需要使用BooleanQuery,具体可以查询相关的逻辑关系表达式Occur BooleanQuery booleanQuery = new BooleanQuery(); Directory dir = FSDirectory.open(new File(indexpath)); IndexSearcher is = new IndexSearcher(DirectoryReader.open(dir)); Analyzer analyzer = new SmartChineseAnalyzer(); String housename=condition.getHousename(); long minPrice = condition.getMinPrice(); long maxPrice = condition.getMaxPrice(); if (!StringUtils.isBlank(housename)) { //使用MultiFieldQueryParser实现多域检索 QueryParser qp = new MultiFieldQueryParser(new String[]{"housename","kfs"}, analyzer); //QueryParser qp = new QueryParser("housename", analyzer); Query query = qp.parse(housename+"*"); booleanQuery.add(query, Occur.MUST); } if (minPrice==0) { minPrice=Long.MIN_VALUE; } if (maxPrice==0) { maxPrice=Long.MAX_VALUE; } //使用NumericRangeQuery实现价格区间范围的检索,因为价格的索引使用的是LongField,所以使用的是NumericRangeQuery<Long> NumericRangeQuery<Long> priceQuery = NumericRangeQuery.newLongRange("price", minPrice, maxPrice, true, true); booleanQuery.add(priceQuery, Occur.MUST); //使用Sort内实现检索结果排序 TopDocs hits = is.search(booleanQuery, 100, new Sort(new SortField("createtime", SortField.Type.LONG)));
1 0
- lucene 4.10实现多域检索和区间范围检索
- lucene检索机制和检索性能优化
- nutch Lucene 实现全文检索
- lucene全文检索实现流程
- 使用lucene实现全文检索
- Lucene.net 实现数据库检索
- lucene检索的具体实现
- lucene检索
- lucene索引和检索原理
- lucene 4.10 检索mysql数据库
- Lucene多索引目录检索
- 用lucene实现在上次检索结果中再检索
- Lucene实现在线全文检索的总结
- 使用Lucene.NET实现数据检索功能
- 使用Lucene.Net实现全文检索
- lucene实现全文检索的示例代码
- Lucene技术---Solr实现全文检索技术
- Lucene:实现数据库的全文检索
- Adaboost 算法的原理与推导
- 项目过程分析
- FreeBSD nginx php
- 第五章 树和二叉树
- C# ListView实例:文件图标显示
- lucene 4.10实现多域检索和区间范围检索
- storyboard怎么使用自己创建的控件
- IOS开发知识体系
- 整数排列
- 低头做事,抬头做人!
- 每日晨会表格
- Tomcat version 6.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5 Web modules
- Java IO
- Android Search 有历史记录 逐字检查 清空历史