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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - kwklover

给同为.NET开发者普及一点Oracle数据库经验 使用mencoder转换flv为ipad/iphone下能播放的mp4格式 - kwklover Lucene.net常见功能实现知识汇总 众里寻他千百度,蓦然回首,那人却在灯火阑珊处 问题总结:判断MS SQLSERVER临时表是否存在 小技巧:处理ASP提交的参数是经过GB2312 URL编码的 Lucene.net实现自定义排序笔记 模版引擎AderTemplate源代码分析笔记 T-SQL复习总结--用T-SQL创建,修改,管理,删除数据库 面向搜索的中文分词设计 需要整理研究的搜索引擎技术点(目录,无实际价值) 试用了一下Sqlite,总结和整理一下参考资料 数据结构与算法学习记录:快速排序 小总结:DotLucene如何才能快速生成索引? 小总结:如何表达用户是否禁止的概念 ? Web Spider提取编码方法总结 WebSpider的编码问题(乱码)浅析 VS2005 Winform程序不能启动调试,别忘了启动Terminal Services服务[记录] 系统问题解决记录:IIS 500内部错误之解决办法
Lucene 1.9 多目录搜索的的一个bug
kwklover · 2008-03-11 · via 博客园 - kwklover

   这个问题解决有一段时间了。刚才在Lucene的群有朋友提问了这个问题。所以方便其他朋友遇到此问题时,好参考下。特贴出来

在需要搜索多个索引目录,多个字段的时候,发现有错误,提示的大概意思是(具体忘记了),关键词已经存在字典中。研究Lucene的源代码发现,是Lucene.net 1.9 rc1的一个bug :

具体代码在Lucene.Net.Search命名空间下的Query类的Combine method :

修改前的代码如下:

public virtual Query Combine(Query[] queries)
  {
   System.Collections.Hashtable uniques = new System.Collections.Hashtable();
   for (int i = 0; i < queries.Length; i++)
   {
    Query query = queries[i];
    BooleanClause[] clauses = null;
    // check if we can split the query into clauses
    bool splittable = (query is BooleanQuery);
    if (splittable)
    {
     BooleanQuery bq = (BooleanQuery) query;
     splittable = bq.IsCoordDisabled();
     clauses = bq.GetClauses();
     for (int j = 0; splittable && j < clauses.Length; j++)
     {
      splittable = (clauses[j].GetOccur() == BooleanClause.Occur.SHOULD);
     }
    }
    if (splittable)
    {
     for (int j = 0; j < clauses.Length; j++)
     {
                        Query tmp = clauses[j].GetQuery();
      uniques.Add(tmp, tmp);
     }
    }
    else
    {
                    uniques.Add(query, query);
    }
   }
   // optimization: if we have just one query, just return it
   if (uniques.Count == 1)
   {
                return (Query) uniques.GetEnumerator().Current;
   }
   System.Collections.IEnumerator it = uniques.GetEnumerator();
   BooleanQuery result = new BooleanQuery(true);
   while (it.MoveNext())
   {
    result.Add((Query) it.Current, BooleanClause.Occur.SHOULD);
   }
   return result;
  }

修改后的代码(飘红的地方是更改过的):

public virtual Query Combine(Query[] queries)
  {
   System.Collections.Hashtable uniques = new System.Collections.Hashtable();
   for (int i = 0; i < queries.Length; i++)
   {
    Query query = queries[i];
    BooleanClause[] clauses = null;
    // check if we can split the query into clauses
    bool splittable = (query is BooleanQuery);
    if (splittable)
    {
     BooleanQuery bq = (BooleanQuery) query;
     splittable = bq.IsCoordDisabled();
     clauses = bq.GetClauses();
     for (int j = 0; splittable && j < clauses.Length; j++)
     {
      splittable = (clauses[j].GetOccur() == BooleanClause.Occur.SHOULD);
     }
    }
    if (splittable)
    {
     for (int j = 0; j < clauses.Length; j++)
     {
                        Query tmp = clauses[j].GetQuery();
      uniques.Add(tmp, tmp);
     }
    }
    else
    {
                    //uniques.Add(query, query);

                    //modify by kwklover 2008/1/17 bug fixed for 防止加入多个重复的字典项
                    if (uniques.Contains(query) == false)
                    {
                        uniques.Add(query, query);
                    }

    }
   }
   // optimization: if we have just one query, just return it
   if (uniques.Count == 1)
   {
               //return (Query) uniques.GetEnumerator().Current;

                //modify by kwklover 2008/1/17
                System.Collections.IDictionaryEnumerator iter = uniques.GetEnumerator();
                iter.MoveNext();
                return iter.Value as Query;

   }
   System.Collections.IEnumerator it = uniques.GetEnumerator();
   BooleanQuery result = new BooleanQuery(true);
   while (it.MoveNext())
   {
    result.Add((Query) it.Current, BooleanClause.Occur.SHOULD);
   }
   return result;
  }

另外在Lucene 2.0版已经修复了此问题。不过Lucene 2.0 和 Lucene 1.9的 API有比较大的变化