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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
T
Threatpost
Latest news
Latest news
N
News | PayPal Newsroom
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Help Net Security
Help Net Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
AI
AI
Simon Willison's Weblog
Simon Willison's Weblog
TaoSecurity Blog
TaoSecurity Blog
The Last Watchdog
The Last Watchdog
L
LINUX DO - 热门话题
Google DeepMind News
Google DeepMind News
T
Threat Research - Cisco Blogs
O
OpenAI News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
The Exploit Database - CXSecurity.com
NISL@THU
NISL@THU
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Securelist
小众软件
小众软件
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Martin Fowler
Martin Fowler
S
SegmentFault 最新的问题
Cisco Talos Blog
Cisco Talos Blog
云风的 BLOG
云风的 BLOG
AWS News Blog
AWS News Blog
GbyAI
GbyAI
N
News and Events Feed by Topic
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
美团技术团队
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
S
Schneier on Security
博客园 - 聂微东
V2EX - 技术
V2EX - 技术
T
Troy Hunt's Blog
SecWiki News
SecWiki News
S
Secure Thoughts
B
Blog RSS Feed
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
腾讯CDC
H
Heimdal Security Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Apple Machine Learning Research
Apple Machine Learning Research
月光博客
月光博客
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Privacy International News Feed

博客园 - 菜鸟吴迪

Lucene搜索结果排序问题(按时间倒序排的替代解决方法) (转)Razor引擎学习:RenderBody,RenderPage和RenderSection 读取txt文本,批量插入到数据库中! ASP.NET MVC3 返回多个实体或泛型 MySQL数据库集群Master-Slave模式安装摘要 使用HtmlAgilityPack批量抓取网页数据 Jquery each - 菜鸟吴迪 - 博客园 堆?栈?(转) 数据库并发控制!!! Velocity脚本简明教程 Visual Studio的调试技巧 《C#与.NET3.5高级程序设计(第4版)》笔记10 sql分页问题,老话题!! sql查询连续三天之内都有记录的人员!! Asp.net Mvc Controller接收可控的数组或字典类型的实现方法: SELECT INTO 和 INSERT INTO SELECT 两种表复制语句 (转) httpContext里面的东西!!! c#闭包!! c#新特性!!!
利用Lucene.net搜索引擎进行多条件搜索的做法 (转)
菜鸟吴迪 · 2013-04-26 · via 博客园 - 菜鸟吴迪

(转)http://blog.csdn.net/hehui21/article/details/2874113

Lucene.net是目前在.net环境中被普遍使用的全文索引的开源项目,这次在项目的开发中也使用它进行全文索引。 在开发过程中碰到一些小问题就是对多字段和多索引目录进行搜索。

1 联合两个索引查询,已解决: IndexSearcher[] searchers = new IndexSearcher[2];   searchers[0] = new IndexSearcher(m_indexpath); searchers[1] = new IndexSearcher(m_outindexpath);
MultiSearcher multiSearcher = new MultiSearcher(searchers);
2,还有个进行多条件搜索 and 与 or 的操作———— 用 MultiFieldQueryParser 建议重新封装 MultiFieldQueryParser.Parser(p[],d[],f[],analyer)  成or 与 and操作合一 或者 BooleanQuery m_BooleanQuery = new BooleanQuery(); Query query = QueryParser.Parse(m_SearchText, "INSTRUMENT_NAME", analyzer); Query query2 = QueryParser.Parse(m_SearchText2, "INSTRUMENT_NAME2", analyzer); m_BooleanQuery.Add(query, true, false); m_BooleanQuery.Add(query2, true, false); 3,进行详细解释每个步骤
1、多字段搜索就是同时要一个以上的字段中的内容进行比较搜索,
Lucene.net中的单个字段查询大家都比较熟悉,这里对字段content进行搜索 Query query = QueryParser.Parse(querystr,"content",new ChineseAnalyzer()); Hits hits = searcher.Search(query);
对多个字段查询用到一个MultiFieldQueryParser对象,该对象继承自Query,我们要对字段title,content进行搜索。 string[] fields = {"content","title"}; Query multiquery = MultiFieldQueryParser.Parse(querystr,fields,new ChineseAnalyzer()); Hits hits = searcher.Search(multiquery);
2、多索引目录就是要在多个索引目录的中进行比较搜索, IndexSearcher[] searchers = new IndexSearcher[2]; searchers[0] = new IndexSearcher(IndexPath0); searchers[1] = new IndexSearcher(IndexPath1);
MultiSearcher multisearcher = new MultiSearcher(searchers); TopDocs multitopdocs = multisearcher.Search(query, null, 1000); 这个搜索的结果可能有相同的信息,比如你有一条相同的信息在多个目录中索引,搜索的结果就会出现多次相同的信息。
还有一种搜索方式是用到ParallelMultiSearcher这个对象,它是从MulitSearcher继承而来。 ParallelMultiSearcher parallelmultisearcher = new ParallelMultiSearcher(searchers); TopDocs paralleltopdocs = parallelmultisearcher.Search(query, null, 1000); 这个搜索是对搜索后的结果进行合并,剔除重复的信息。