今天在做Lucene检索的时候,做了一个在结果中查询的功能,但是当两个关键字一样的时候,总是出现错误,经过检查,原来错误出现在这里:
TermQuery.cs
public override void ExtractTerms(System.Collections.Hashtable terms)
{
Term term = GetTerm();
terms.Add(term, term);
}
{
Term term = GetTerm();
terms.Add(term, term);
}
应该改成
public override void ExtractTerms(System.Collections.Hashtable terms)
{
Term term = GetTerm();
if (!terms.ContainsKey(term)) //需要做判断
{
terms.Add(term, term);
}
}
{
Term term = GetTerm();
if (!terms.ContainsKey(term)) //需要做判断
{
terms.Add(term, term);
}
}