ITeye博客

2009 年文章归档

共 6 篇文章

the Decorator Pattern 装饰模式

Decorating Objects 装饰对象 给爱用继承的人一个全新的设计眼界 动态地将责任附加到对象上。想要扩展功能,妆饰者提供有别于继承的另一种选择 星巴克更新订单系统 有多种咖啡和配料, 每种饮料价格不同,还有各种配料,每种咖啡搭配配料都会有不同的价格 超类:Beverage Beverage -description -milk(boolean) -soy(boolean) .. --getDescription() --cost() --hasMilk() --setMilk() ... 子类:HouseBlend,DarkRoast,Decaf,Espresso 超类cost(…

2009-12-02 16:44 · 设计模式 · OO · 编程 · 设计模式

lucene学习(4)

other directory implementations 将某个directory装入到RAMDirectory中 Directory ramDir = new RAMDirectory(otherDir) 这个被用来加速搜索,将一个已经存在的在硬盘上的索引放入到ram中 我们也可以反过来:将RAMDirectory中的索引复制到另一个Directory中 Directory.copy(ramDir,otherDir) 该方法只是直接替换otherDir中的文件,需要保证没有indexwriter在ramDir中打开,因为该方法不会加锁 如果otherDir中存在一个index,当你需…

2009-11-10 16:25 · lucene · junit · Apache · Lucene · thread · 多线程

the observer pattern 观察者模式

keeping your objects in the know 类似于报纸发行商和订阅者之间的关系 publisher + subscribers = observer pattern 我们称发行者为subject,订阅者为observers 1.subject对象管理一些数据 2.当subject对象中的数据改变时,通知observers 3.注册到subject的observers接收更新,当subject中的数据改变 观察者模式定义一个一对多的关系,当那个一个对象状态改变,附属的多个对象会接收到通知然后自动修改自己的状态 观察者模式提供subject和observer之间的松耦合 好…

2009-11-06 13:45 · 设计模式 · F# · 设计模式

lucene学习(3)

Boosting Documents and Fields setBoost(float) 设置Documents和Fields在index中的重要性 可以给document设置boost,也可以给field设置boost 设置boost会删除原来的document然后重新建立索引 doc.setBoost(); field.setBoost(); boost是怎样存储到index中的,利用norms 在建立索引过程中生成的boosts会被结合在一起变成一个浮点数,然后每个文档每个字段 都会存为一个byte。在查询过程中,每个field的norms会被装入内存,重新解码为一个浮点数 即使no…

2009-11-05 23:10 · lucene · Lucene

lucene学习(2)

import java.io.IOException; import junit.framework.TestCase; import org.apache.lucene.analysis.WhitespaceAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.…

2009-11-03 17:36 · lucene · junit · Apache · Lucene · F#

lucene学习(1)

建立索引的主要用到的类: IndexWriter: 建立一个新的index,添加新的documen到一个存在的index,indexwriter能让我们写index,但是不能读和搜索index Directory: 就是指存储index的位置,一般是他的子类来存储index(常用的有FSDirectory和RAMDirectory) Analyzer: 就是在建立索引的过程中对内容进行处理,如过滤停用词,大小写转换等\Document: 就是一系列field的组合,每个document都对应着应用中的一个记录(如数据库中的一条记录,一个网页等) field: 就是对于一个document你要…

2009-11-02 23:35 · lucene · Lucene