学习Lucene的一点心得

<script type="text/javascript"> google_ad_client = "pub-8800625213955058"; /* 336x280, 创建于 07-11-21 */ google_ad_slot = "0989131976"; google_ad_width = 336; google_ad_height = 280; // </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> Google上搜索关于lucene的中文文章基本上都是出自车东先生的那篇,我也是从那篇文章开始的, 不过做的可能比那更多些,也许因为侧重点不同,代码的改动还是比较多的。 建索引那部分也就没有必要再详细提及,那篇文章和车东的开放源码的一个项目已经说得很详细 了,基于二元切分也是比较简便快捷的方法(在索引量不是很大的情况下)。至于编码方式倒是不是 特别重要,因为只要索引和查询串用相同编码方式的字符串就行了。 查询部分调用的lucene的queryParser对象确实很脆弱(不知道是不是和我使用iso8859的编码 方式有关),建议最好自己先做一下语法检查。其实里面有好多的逻辑和类似数据库的操作对于搜索 来说我认为用处不大。当然根据实际需要去操作吧。如果要做大的修改,建议还是自己去改QueryParser.jj, 只是修改难度应该并不会很大,然后用javacc去生成代码。如果只是做小的改动那就直接改java文件 吧,没有必要费那功夫。:) 有一点注意一下,车东的开源项目那个查询对象里调用了一次 QueryParser.setPhraseSlop(QueryParser.AND)(注int AND = 7)其实是没有必要的,呵呵,误导了我一下。 这个值最后是传给PhraseQuery对象的private int slop = 0;lucene里对这个变量有详细的说明: Sets the number of other words permitted between words in query phrase. If zero, then this is an exact phrase search. For larger values this works like a WITHIN or NEAR operator. The slop is in fact an edit-distance, where the units correspond to moves of terms in the query phrase out of position. For example, to switch the order of two words requires two moves (the first move places the words atop one another), so to permit re-orderings of phrases, the slop must be at least two. More exact matches are scored higher than sloppier matches, thus search results are sorted by exactness. The slop is zero by default, requiring exact matches. 看完说明就应该很清楚了,其实那是一个废代码,因为那个项目是基于二元切分的所以应该出问题 的几率小一些,但如果是单字切分话7个字符应该足以导致查询结果混乱,如果再修改了排序的话。 如果是基于词库的分词应该会好一点,但是精确匹配就无法实现了。 还有一些小的细节就是如果索引和查询使用不同的分词算法尤其是stopwords不同时,那么就要 修改DocumentWriter中的positions变量了,他原先只是记分词结果中每个词的相对位置,查询中 有可能这些相对位置因为stopwords的变化而改变,那么精确匹配就无法得出结果。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值