摘要: 如果要分析lucene的索引文件的相关数据,我们可以使用luke这个工具来可视化查询相关数据。1.下载http://code.google.com/p/luke/downloads/list下面的jar包2.下载完之后在命令行执行java -jarlukeall-3.5.0.jar3.出现界面在path输入索引文件的路径4.然后就可以查看lucene的索引文件里面的相关数据了, 查看当前索引中出现的所有的term和相关统计数据查看每个document的信息可以查询可以查看索引里面的相关文件信息还可以继承其他的插件lucene开发很有用的一款工具。 阅读全文
posted @ 2012-06-01 11:02 zhwj184 阅读(124) 评论(0) 推荐(0) 编辑
摘要: 自定义排序 IndexSearcher.java 动态计算存储的饭馆离某个位置最近最远 /** Expert: Low-level search implementation with arbitrary sorting. Finds * the top <code>n</code> hits for <code>query</code>, applying * <code>filter</code> if non-null, and sorting the hits by the criteria in * <co 阅读全文
posted @ 2012-06-01 11:02 zhwj184 阅读(124) 评论(0) 推荐(0) 编辑
摘要: 高级搜索技术: 排序 默认排序按照相关性, public class Sort implements Serializable { /** * Represents sorting by computed relevance. Using this sort criteria returns * the same results as calling * {@link Searcher#search(Query,int) Searcher#search()}without a sort criteria, * only with slightly more ov... 阅读全文
posted @ 2012-06-01 11:02 zhwj184 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 你如果想再maven中定义一些配置,这些配置需要整个团队遵守,比如定义maven版本,java版本,os配置,文件系统的配置,或者你想扩展的任何配置,那么就可以使用Maven Enforcer Plugin这个maven插件。pom中引入Maven Enforcer Plugin插件。<project> ... <build> <!-- To define the plugin version in your parent POM --> <pluginManagement> <plugins> <plugin> < 阅读全文
posted @ 2012-06-01 11:01 zhwj184 阅读(315) 评论(0) 推荐(0) 编辑
摘要: 语汇单元:位置增量是唯一的元数据 poter词干提取算法实现 /** * * Stemmer, implementing the Porter Stemming Algorithm * * The Stemmer class transforms a word into its root form. The input * word can be provided a character at time (by calling add()), or at once * by calling one of the various stem(something) methods.... 阅读全文
posted @ 2012-06-01 11:00 zhwj184 阅读(135) 评论(0) 推荐(0) 编辑
摘要: // TermQuery:词条查询。通过对某个词条的指定,实现检索索引中存在该词条的所有文档。 Query query = new TermQuery(New Term("content","java")),区分大小写 // TermRangeQuery:范围查询。这种范围可以是日期,时间,数字,大小等等。可以使用"context:[a to b]"(包含边界)或者"content:{a to b}"(不包含边界) 查询表达式 // PrefixQuery:前缀查询。 可以使用"content:lua*& 阅读全文
posted @ 2012-06-01 11:00 zhwj184 阅读(132) 评论(0) 推荐(0) 编辑
摘要: lucene的评分机制:所有hits的分数<=1.0每个document(d)的分数:∑tf(t in d)*idf(t)*boost(t.field in d)*lengthNorm(t.field in d)t In q查询的得分:score(q,d)=coord(q,d)·queryNorm(q)·∑tf(t in d)*idf(t)*boost(t.field in d)*lengthNorm(t.field in d)t In qtf(t in d):文档中d出现搜索项t的频率idf(t):搜索项t在倒排文档中出现的频率boost(t.field in d) 阅读全文
posted @ 2012-06-01 10:59 zhwj184 阅读(146) 评论(0) 推荐(0) 编辑
摘要: 索引操作: 删除索引 indexreader:delete document,删除索引是在indexreader类进行 numDoc,maxDoc,删除索引是在内存先进行索引删除,合并索引后才能更新到磁盘,当删除一个document时,numDoc能及时更新,而maxDoc得等到合并索引后才会更新。 恢复被删除的索引: undelete方法 更新索引: 删除之后再插入 批量操作 对document某些field加权,降权, 对整个Document加权降权: Document.java类的下面这个方法: /** Sets a boost factor for hits on any f... 阅读全文
posted @ 2012-06-01 10:58 zhwj184 阅读(198) 评论(0) 推荐(0) 编辑
摘要: 最简单的LRU cache的实现:import java.util.LinkedHashMap; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; public class LruCache<K, V> extends LinkedHashMap<K, V> { /** * */ private static final long serialVersionUID = -3923317621052085848L; private int max 阅读全文
posted @ 2012-06-01 10:57 zhwj184 阅读(164) 评论(0) 推荐(0) 编辑
摘要: lucene插入document建立索引代码import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.List; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.document.. 阅读全文
posted @ 2012-06-01 10:56 zhwj184 阅读(208) 评论(0) 推荐(0) 编辑
摘要: import java.util.ArrayList; import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; import org.apache.log4j.Logger; public c... 阅读全文
posted @ 2012-06-01 10:54 zhwj184 阅读(324) 评论(0) 推荐(0) 编辑
摘要: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Proxy; import java.net.URL; import org.apache.log4j.Logger; im.. 阅读全文
posted @ 2012-06-01 10:54 zhwj184 阅读(746) 评论(0) 推荐(0) 编辑
摘要: 一个对象实例占用了多少字节,消耗了多少内存?这样的问题在c或c++里使用sizeof()方法就可以得到明确答案,在java里好像没有这样的方法(java一样可以实现),不过通过jmap工具倒是可以查看出一个对象的占用内存的大小,这里介绍一种通过分析java代码计算内存使用情况的方法。注意,一下讨论的情况都是基于32位机,不适用用64位机,JVM是sun的HotSpot,不同的虚拟机实现可能会不同规则一:每个对象被按照8bytes粒度对齐(数组除外)在jvm中每个对象(数组除外)都有一个头,这个头有两个字,第一个字存储的时对象的一些标志位信息,例如:锁标志位、经历了几次gc等信息,第二个字是一个 阅读全文
posted @ 2012-06-01 10:53 zhwj184 阅读(480) 评论(0) 推荐(0) 编辑
摘要: 很实用的要点,每次重构都要重新看看这些要点,真正用到平时的日常工作中。代码坏味道: 1.duplicate code 重复代码 2.long method 长方法 3.large class 过大的类 4.long parameter list 过长参数列 5.divergent change 发散式变化 6.shotgun surgery 散弹式变化 7 feture envy 依恋情结 8.data clumps 数据泥团 9.primitive obsession 基本类型偏执 10.switch statument switch惊悚现身 11.parallel inheritance 阅读全文
posted @ 2012-06-01 10:53 zhwj184 阅读(189) 评论(0) 推荐(0) 编辑
摘要: CGLIB动态代理类import java.lang.reflect.Method; import net.sf.cglib.proxy.Enhancer; import net.sf.cglib.proxy.MethodInterceptor; import net.sf.cglib.proxy.MethodProxy; public class CglibProxy implements MethodInterceptor { private Object target; /** * 创建代理对象 * * @param... 阅读全文
posted @ 2012-06-01 10:52 zhwj184 阅读(358) 评论(0) 推荐(0) 编辑
摘要: /** * Spring有三种注入方法: * <ul> * <li>通过明确的bean definition声明来注入对象,缺点是无法注入 * <code>ConfigurableListableBeanFactory.registerResolvableDependency()</code> * 中注册的对象,如<code>HttpServletRequest</code>。</li> * <li>通过autowire * byConstructor来注入对象,可以注入包括resolvableDe 阅读全文
posted @ 2012-06-01 10:51 zhwj184 阅读(144) 评论(0) 推荐(0) 编辑
摘要: Caused by: org.springframework.jdbc.UncategorizedSQLException: SqlMapClient operation; uncategorized SQLException for SQL []; SQL state [null]; error code [0]; 列名无效; nested exception is java.sql.SQLException: 列名无效 at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(. 阅读全文
posted @ 2012-06-01 10:50 zhwj184 阅读(540) 评论(0) 推荐(0) 编辑
摘要: java使用jpcap抓包工具获得本机发送的所有tcp请求,根据tcp请求的内容可以调试某个应用启动后对外发送的相关http请求或者sql连接请求,这样可以很好的调试我们的程序。很不错的一种应用无侵入性的调试本机发送的http接口,sql连接接口等。import java.io.UnsupportedEncodingException; import java.net.InetAddress; import jpcap.*; import jpcap.packet.EthernetPacket; import jpcap.packet.Packet; import jpcap.packet.. 阅读全文
posted @ 2012-06-01 10:49 zhwj184 阅读(869) 评论(0) 推荐(0) 编辑
摘要: /** * Internal private hashing method. * * This is the original hashing algorithm from other clients. * Found to be slow and have poor distribution. * * @param key String to hash * @return hashCode for this string using our own hashing algorithm */ private static long origCompatH... 阅读全文
posted @ 2012-06-01 10:48 zhwj184 阅读(157) 评论(0) 推荐(0) 编辑