首页 新闻 会员 周边 捐助

lucene.net 使用通配符 搜索不出数据

0
[已关闭问题] 关闭于 2012-12-10 10:06

下面的是搜索的代码:

QueryParser parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "geoname", new ChineseAnalyzer());
//parser.SetPhraseSlop(10);
Query query = parser.Parse(queryStr);
// QueryParser parserRid = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "rid", new ChineseAnalyzer());
// parserRid.SetAllowLeadingWildcard(true);
//rid = "南宁";
// WildcardQuery queryRid = new Lucene.Net.Search.WildcardQuery(new Lucene.Net.Index.Term("geoname", rid + "*"));//parserRid.Parse(rid + "*"); //
PrefixQuery queryx = new PrefixQuery(new Term("rid", rid));
BooleanQuery booleanQuery
= new Lucene.Net.Search.BooleanQuery();
//BooleanQuery.SetMaxClauseCount(10000);

booleanQuery.Add(query, BooleanClause.Occur.MUST);
booleanQuery.Add(queryx, BooleanClause.Occur.MUST);

ScoreDoc[] hits
= Searcher.Search(booleanQuery, null, 150).scoreDocs;
//1000021
//10000213io3i2oi
//1000021*
if (hits.Length >= 1)

下面是创建索引的代码:

IndexWriter writer = new IndexWriter(FSDirectory.Open(tempDir), new ChineseAnalyzer(), enableCreate, IndexWriter.MaxFieldLength.UNLIMITED);
if (worker != null && worker.CancellationPending)
{

return true;
}
writer.SetUseCompoundFile(
true);
Document doc;
foreach (DataRow dr in dt.Rows)
{
if (worker != null && worker.CancellationPending)
{
return true;
}

doc
= new Document();
string geoname = dr["geoname"].ToString();
string lnt = dr["lnt"].ToString();
string lat = dr["lat"].ToString();
string rid = dr["rid"].ToString();
doc.Add(
new Field("geoname", geoname, Field.Store.YES, Field.Index.ANALYZED));
doc.Add(
new Field("lnt", lnt, Field.Store.YES, Field.Index.NO));
doc.Add(
new Field("lat", lat, Field.Store.YES, Field.Index.NO));
doc.Add(
new Field("rid", rid, Field.Store.YES, Field.Index.ANALYZED));

writer.AddDocument(doc);

}
writer.Optimize();

if (worker != null && worker.CancellationPending)
{
return true;
}
writer.Close();

找不到原因啊, 就是搜索不出数据

需要是说明:

查询的数据是完全正确的,并且包含 通配符 的数据  rid:'2121212*'

问题补充:

没有人知道原因吗?

Michael-Chen的主页 Michael-Chen | 初学一级 | 园豆:2
提问于:2011-05-18 16:23
< >
分享
所有回答(1)
0

rid的ANALYZED改为NOT_ANALYZED.没准可以

Lexy | 园豆:202 (菜鸟二级) | 2014-03-14 15:33
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册