我正在使用 PerFieldAnalyzer 将 ExactTitle 设置为使用新的 LowercaseKeywordAnalyzer:
private Analyzer GetDefaultAnalyzer()
{
var perFieldAnalyzer = new PerFieldAnalyzerWrapper(new StandardAnalyzer(Version.LUCENE_30));
perFieldAnalyzer.AddAnalyzer(ReportFields.ExactTitle, new LowercaseKeywordAnalyzer());
...
我正在构建索引,在字段中添加:
var exactTitleField = new Field(ReportFields.ExactTitle, report.PortalReportTitle, Field.Store.NO,
Field.Index.NOT_ANALYZED);
exactTitleField.Boost = 10.0f;
reportDoc.Add(exactTitleField);
当我使用 2 字示例“test abc”对其进行搜索时,当我对它进行 TermQuery 搜索时找不到它:
var term = new Term(exactField, "test abc");
var exactQuery = new TermQuery(term);
query.Add(exactQuery,Occur.SHOULD);
var hits = searcher.Search(query, null, HitsLimit, Sort.RELEVANCE);
如果我搜索“Test Abc”,它会起作用。我该怎么做才能使这种不区分大小写的关键字/术语搜索工作?
这是分析器:
public class LowercaseKeywordAnalyzer : Analyzer
{
public override TokenStream TokenStream(string fieldName, System.IO.TextReader reader)
{
TokenStream tokenStream = new KeywordTokenizer(reader);
tokenStream = new LowerCaseFilter(tokenStream);
return tokenStream;
}
}
提前致谢。