【发布时间】:2017-08-18 04:54:26
【问题描述】:
我正在使用 lucene.net 在我的网站上搜索记录。我有很多带有特殊字符哈希(“#”)的记录,例如“C#”、“C#.Net”等......
但是当我使用术语“C#”搜索时,lucene 没有返回任何结果。我检查了lucene Escaping Special Characters,但是“#”不在这个字符列表中。
有没有在 Lucene.Net 上使用“#”这个词进行搜索的好方法?
【问题讨论】:
-
转义字符因版本而异。您是否尝试过用 \ 转义井号?
-
是的,我已经尝试使用转义序列“\”,但仍然无法正常工作。我正在使用版本 Lucene 3.0.3.0
-
您使用什么分析器来索引数据?最好的猜测是您正在使用一个去除
#字符的字符 - 如果它们不在您的索引中,您将无法匹配它们。请出示您的代码。 -
我正在使用 StandardAnalyzer 进行索引。这是我的代码。 var analyzer = new StandardAnalyzer(Version.LUCENE_30, stopWords); { var nameParser = new MultiFieldQueryParser(Version.LUCENE_30, new[] { "CourseName"}, 分析器); hits = searcher.Search(query, null, hits_limit, Sort.RELEVANCE).ScoreDocs; BooleanQuery query = query.Add(parseQuery(GetTerms(searchCriteria.CourseName), nameParser), Occur.MUST); hits = searcher.Search(query, null, hits_limit, Sort.RELEVANCE).ScoreDocs; var results = _mapLuceneToDataList(点击,搜索者);分析器.Close(); searcher.Dispose();返回结果; }
-
我已经验证了Lucene索引文件,特殊字符“#”被索引了。似乎只有搜索的问题..
标签: c# lucene.net