- 浏览: 194822 次
文章分类
最新评论
-
code_xiaoke:
session可是有30分钟有效期的还有如果在分布式的环境下 ...
Java Web 用户登陆示例代码 -
xul0038:
http://www.baidu.com
Java Web 用户登陆示例代码 -
16866:
非常棒,配置信息呢
Nginx负载均衡 -
开发小菜:
什么意思,没明白?能不能写一个例子
JS 实现DIV随浏览器窗口大小变化
PrefixQuery类似于 数据库中的 like 'a%'查询
以下是测试代码,这种方式的缺陷是人为的分出了更多的term,目前还在找有没有更优的方法。
测试代码:
public static String index_path3="D:\\ix3";
public static void main(String[]args) throws Exception{
//createPrefixIndex();
//前缀查询
Query trquery = new PrefixQuery(new Term("pinyin","ghai" ));
IndexReader indexReader = IndexReader.open(FSDirectory.open(new File(index_path3)));
Searcher searcher = new IndexSearcher(indexReader);
TopDocs topDocs = searcher.search(trquery,100);
for (ScoreDoc hits:topDocs.scoreDocs){
Document doc = searcher.doc(hits.doc);
System.out.println("doc = "+doc.get("hotelName"));
}
}
/**
* 创建pinyin索引
*/
public static void createPrefixIndex(){
Analyzer analyzer = new IKAnalyzer();
PerFieldAnalyzerWrapper perFieldAnalyzerWrapper = new PerFieldAnalyzerWrapper(analyzer);
try {
//perFieldAnalyzerWrapper.addAnalyzer("price", new WhitespaceAnalyzer());
IndexWriter writer = new IndexWriter(FSDirectory.open(new File(index_path3)), perFieldAnalyzerWrapper, true,IndexWriter.MaxFieldLength.LIMITED);
Document doc = new Document();
String pinyin="shanghai";
int len = pinyin.length();
//将拼音截取保存
for(int i=0;i<len;i++){
String value = pinyin.substring(i,len);
doc.add(new Field("pinyin", value, Field.Store.YES, Field.Index.NOT_ANALYZED));
}
doc.add(new Field("hotelName", "test2", Field.Store.YES, Field.Index.ANALYZED));
writer.addDocument(doc);
doc = new Document();
doc.add(new Field("hotelName", "test3", Field.Store.YES, Field.Index.ANALYZED));
pinyin="beijing";
len = pinyin.length();
for(int i=0;i<len;i++){
String value = pinyin.substring(i,len);
doc.add(new Field("pinyin", value, Field.Store.YES, Field.Index.NOT_ANALYZED));
}
writer.addDocument(doc);
doc = new Document();
doc.add(new Field("hotelName", "test6", Field.Store.YES, Field.Index.ANALYZED));
pinyin="zhongguo_benxi";
len = pinyin.length();
for(int i=0;i<len;i++){
String value = pinyin.substring(i,len);
doc.add(new Field("pinyin", value, Field.Store.YES, Field.Index.NOT_ANALYZED));
}
writer.addDocument(doc);
doc = new Document();
doc.add(new Field("hotelName", "test1", Field.Store.YES, Field.Index.ANALYZED));
pinyin="tianjin";
len = pinyin.length();
for(int i=0;i<len;i++){
String value = pinyin.substring(i,len);
doc.add(new Field("pinyin", value, Field.Store.YES, Field.Index.NOT_ANALYZED));
}
writer.addDocument(doc);
writer.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
发表评论
-
java实现动态切换上网IP (ADSL拨号上网) java开发
2013-04-24 10:06 1217动态切换IP的实现主是也由Windows的rasdial命令提 ... -
JAVA字符串处理函数
2013-04-12 09:21 1029Java中的字符串也是一连串的字符。但是与许多其他的计算机语 ... -
(转)Lucene打分规则与Similarity模块详解
2013-02-06 14:08 1126搜索排序结果的控制 Lu ... -
Compass将lucene、Spring、Hibernate三者结合
2013-02-01 11:02 1639版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声 ... -
Lucene3.0详解
2013-02-01 10:57 1339★第一部分:概述 1. 我 ... -
Java Web 用户登陆示例代码
2013-02-01 09:56 57996实现功能: 1、用户登陆、注销 2、利用session记 ... -
Java对数函数及Java对数运算
2013-02-01 09:47 6718Java对数函数的计算方法非常有问题,然而在API中却有惊人 ... -
Lucene为不同字段指定不同分词器(转)
2013-01-31 17:34 3370在lucene使用过程中,如 ... -
域名管理与解析原理 — 《Java邮件开发详解》读书笔记
2013-01-31 14:56 1652一 基本概念 1. 域名:域名是由圆点分开一串单词或缩写组 ... -
优秀的Java工程师需要掌握的10项技能
2013-01-31 14:04 1788编程专业相对于计算机领域其他专业来讲,是一门比较难以修炼的专业 ... -
Web开发入门不得不看
2013-01-28 17:31 994如今,各种互联网的Web ... -
MVC框架的映射和解耦
2013-01-25 21:37 785最近在写一个业务上用到的框架,回想起接触过的一些MVC框架, ... -
JAVA发送EMAIL的例子
2013-07-09 09:44 863import javax.mail.*; ... -
SSH + Lucene + 分页 + 排序 + 高亮 模拟简单新闻网站搜索引擎
2012-11-19 09:55 1336前两天看到了一个中国新闻网,这个网站的搜索form的actio ... -
Lucene多字段搜索
2012-11-19 09:53 927最近在学习Lucene的过程中遇到了需要多域搜索并排序的问题, ... -
lucene之sort
2012-11-16 15:06 1040package cn.zqh.lucene.sort; im ... -
Nginx负载均衡
2012-11-16 11:45 7533最近迷上了Nginx,真实麻雀虽小,五脏俱全..功能实在强大. ... -
Lucene相关度排序的调整
2012-11-16 11:38 1675Lucene的搜索结果默认按 ... -
HashSet重复元素判断
2012-10-15 16:37 9093HashSet不能添加重复的元素,当调用add(Object) ... -
JAVA提高教程(2)-认识Set集合之HashSet
2012-10-09 09:44 932集合在Java里面的作用非 ...
相关推荐
NULL 博文链接:https://baobeituping.iteye.com/blog/846998
lucene6.6中适配的拼音分词jar包以及ik中文分词jar包,以及自定义的分词词组包和停词包,可以实现lucene建立索引时进行拼音和中文的分词。
在Eclipse环境中运用java,Lucene建索引及查询关键字
NULL 博文链接:https://iamyida.iteye.com/blog/2207080
Lucene创建索引,查询索引的简单使用。
spark-lucenerdd, 使用Lucene功能的查询来激发 RDD lucenerdd 使用 Apache Lucene的RDD x Spark x Spark 。主要抽象是特殊类型的RDD 调用 LuceneRDD 。FacetedLuceneRDD 和 ShapeLuceneR
lucene,solr的使用lucene,solr的使用lucene,solr的使用lucene,solr的使用lucene,solr的使用lucene,solr的使用lucene,solr的使用lucene,solr的使用lucene,solr的使用lucene,solr的使用lucene,solr的使用
教大家使用lucene进行简单的开发,贴出了主要的源码和注释.
Lucene3.0之查询处理(1):原理和查询类型 各种Query对象详解
为了快速查询,加快查询速度,减少与数据库交互,经常需要用到lucene实现创建索引和查询
用lucene于本地数据库建立连接,进行查询,代码已经经过测试。
使用Lucene.net进行全文查找多关键字匹配
Lucene实现索引和查询的实例讲解Lucene实现索引和查询的实例讲解
使用lucene编程实现全文检索数据库内容,程序使用lucene-core-2.4.0以及access数据库
这是lucene的使用案例,实现了对word文档中的关键字检索,并将检索出的内容高亮打印出来
lucene的查询语法事例.
(3) 前缀查询(PrefixQuery) 11 (4) 通配符查询(WildcardQuery) 11 (5) 多条件查询(BooleanQuery) 12 (6) 短语查询(PhraseQuery) 12 (7) 模糊查询(FuzzyQuery) 12 3.3 QueryParser 13 (1) 创建QueryParser ...
lucene
c#下实现Lucene时间区间查询匹配。主要还是对Lucene查循对像Query的实现
lucene 做索引查询流程,来自《lucene in action》