我在我的搜索引擎中使用来自 lucene 的标准分析器来搜索德语单词这是我的代码:
private IList<Document> GetFromLucene(string terme, string FieldName)
{
TopDocs hits;
CustomAnalyzer standardAnalyzer = new CustomAnalyzer(Lucene.Net.Util.Version.LUCENE_29);
List<Document> matches = new List<Document>();
IndexSearcher indexSearcher = new IndexSearcher(FSDirectory.Open(new System.IO.DirectoryInfo(MainDoc + DocIndex)), true);
if (terme.Contains(" "))
{
BooleanQuery finalQuery = new BooleanQuery();
string[] terms = terme.Split(' ');
#region AND
QueryParser queryParser = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, FieldName, standardAnalyzer)
{
DefaultOperator = QueryParser.Operator.AND
};
#endregion
#region Contains
Query querys = queryParser.Parse("" + terme + "*");
finalQuery.Add(querys, Occur.MUST);
#endregion
hits = indexSearcher.Search(finalQuery, int.MaxValue);
}
else
{
WildcardQuery query;
query = new WildcardQuery(new Term(FieldName, "*" + terme + "*"));
hits = indexSearcher.Search(query, int.MaxValue);
}
matches = hits.ScoreDocs.Select(scoreDoc => indexSearcher.Doc(scoreDoc.Doc)).ToList();
return matches;
}
它似乎没有找到包含“ü”和“ä”的单词。 我怎样才能做到这一点?
最佳答案
Lucene 使用所谓的分析器类来检查文本中的索引术语并生成标记流。要实现不区分重音的搜索,您可以将 Lucene 使用的默认分析器替换为将重音字符替换为相应的非重音字符的分析器。 Sitefinity CMS 有一个示例:https://www.progress.com/documentation/sitefinity-cms/for-developers-search-with-accented-characters
关于c# - 如何在 lucene 搜索中添加特殊字符? C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72561514/