摘要:
如果要分析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开发很有用的一款工具。 阅读全文
摘要:
自定义排序 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 阅读全文
摘要:
高级搜索技术: 排序 默认排序按照相关性,
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... 阅读全文
摘要:
你如果想再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> < 阅读全文
摘要:
语汇单元:位置增量是唯一的元数据 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.... 阅读全文
摘要:
// TermQuery:词条查询。通过对某个词条的指定,实现检索索引中存在该词条的所有文档。 Query query = new TermQuery(New Term("content","java")),区分大小写 // TermRangeQuery:范围查询。这种范围可以是日期,时间,数字,大小等等。可以使用"context:[a to b]"(包含边界)或者"content:{a to b}"(不包含边界) 查询表达式 // PrefixQuery:前缀查询。 可以使用"content:lua*& 阅读全文
摘要:
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) 阅读全文
摘要:
索引操作:
删除索引
indexreader:delete document,删除索引是在indexreader类进行
numDoc,maxDoc,删除索引是在内存先进行索引删除,合并索引后才能更新到磁盘,当删除一个document时,numDoc能及时更新,而maxDoc得等到合并索引后才会更新。
恢复被删除的索引:
undelete方法
更新索引:
删除之后再插入 批量操作 对document某些field加权,降权,
对整个Document加权降权:
Document.java类的下面这个方法: /** Sets a boost factor for hits on any f... 阅读全文
摘要:
最简单的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 阅读全文
摘要:
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.. 阅读全文