惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
有赞技术团队
有赞技术团队
H
Help Net Security
V
Visual Studio Blog
F
Fortinet All Blogs
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 司徒正美
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
腾讯CDC
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Stack Overflow Blog
Stack Overflow Blog
I
InfoQ
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
L
LangChain Blog
N
Netflix TechBlog - Medium
罗磊的独立博客
The GitHub Blog
The GitHub Blog
云风的 BLOG
云风的 BLOG
Hugging Face - Blog
Hugging Face - Blog
A
About on SuperTechFans
aimingoo的专栏
aimingoo的专栏
Recent Announcements
Recent Announcements

博客园 - 单摆

MongoDB相关 [转]开源非关系型数据库Hibari发布 Solution to have multiple SSL sites on port 443 in IIS 清除MSSQL日志的方法 Flex学习相关 [转]travian建筑及资源升级所需资源的预测公式 【转】Travian]战斗伤亡计算——从入门到精通 网页游戏未来发展的一些趋势 【转】游戏开发商应开发网页游戏的电视版 【转】浅谈中国网页游戏分类 研究网页游戏几个重要的链接 2007年卓越雇主-网龙公司大量招人啦 代友招聘内网网络监控开发人员 晕,我的随笔也被盗用,还成了别人的专利了 使用Mencoder进行视频转换遇到的问题和相关解决方案 Unicode转汉字的实现 利用ffmpeg+mencoder视频转换的总结(C#) 策划已久的亿趣工作网今天终于上线了 无法更新Norton病毒库的原因
信息检索的函数库Lucene的使用总结
单摆 · 2007-06-22 · via 博客园 - 单摆

简单介绍:
Lucene是一个信息检索的函数库(Library),利用它你可以为你的应用加上索引和搜索的功能.

Lucene的使用者不需要深入了解有关全文检索的知识,仅仅学会使用库中的一个类,你就为你的应用实现全文检索的功能.

不过千万别以为Lucene是一个google那样的搜索引擎,Lucene甚至不是一个应用程序,它仅仅是一个工具,一个Library.你也可以把它理解为一个将索引,搜索功能封装的很好的一套简单易用的API.利用这套API你可以做很多有关搜索的事情,而且很方便。

发展历史:参见《.NET 的 Lucene 》

详细使用帮助:http://www.lucene.com.cn/net.htm (包含了建立索引/对索引进行搜索/删除索引中的文档/更新索引中的文档/查询语句/多个条件查询)

90%的语法在上述使用帮助都可以找到答案。

上面的使用帮助对排序说明的比较少,补充如下:
可以通过 SortField 的构造参数,我们可以设置排序字段,排序条件,以及倒排。

Sort sort = new Sort(new SortField(FieldName, SortField.DOC, false));

IndexSearcher searcher = new IndexSearcher(reader);
Hits hits = searcher.Search(query, sort);

排序对搜索速度影响还是很大的,尽可能不要使用多个排序条件。

Lucene.Net的语言处理包中Lucene.Net.Analysis.Cn的Bug :

http://www.cnblogs.com/dudu/archive...6/22/17783.aspx

如何联合两个索引查询 / 分布搜索:
我们可以使用 MultiReader 或 MultiSearcher 搜索多个索引库。

MultiReader reader = new MultiReader(new IndexReader[] { IndexReader.Open(@"c:\index"), IndexReader.Open(@"\\server\index") });
IndexSearcher searcher = new IndexSearcher(reader);
Hits hits = searcher.Search(query);

IndexSearcher searcher1 = new IndexSearcher(reader1);
IndexSearcher searcher2 = new IndexSearcher(reader2);
MultiSearcher searcher = new MultiSearcher(new Searchable[] { searcher1, searcher2 });
Hits hits = searcher.Search(query);

还可以使用 ParallelMultiSearcher 进行多线程并行搜索。

如何合并索引库?
将 directory1 合并到 directory2 中。
Directory directory1 = FSDirectory.GetDirectory("index1", false);
Directory directory2 = FSDirectory.GetDirectory("index2", false);

IndexWriter writer = new IndexWriter(directory2, analyzer, false);
writer.AddIndexes(new Directory[] { directory });
Console.WriteLine(writer.DocCount());
writer.Close();

关于IndexWriter和IndexReader
Add Optimize Merge操作都是由IndexWriter来做的
Delete则是通过IndexReader完成
文档有一句话“即同一时间只允许IndexWriterIndexReader打开同一份索引.不能允许两个同时打开一份索引

记住IndexReader并不是查询索引的时候要用的,从字面含有好像是读取,所以可以同时查询索引和写入索引。

我的使用Lucene.net成功案例:http://video.5913.com/

使用过程如遇到问题,请留言,我将尽我所能解答!