使用特殊字符“#”的通配符搜索不工作 [英] Wildcard search with special characters "#" not working
问题描述
我在我的网站上使用Lucene.Net 3.0.3.0版本来搜索课程列表。
我的课程很少包含特殊字符#,如C#,C#.Net等等。
但是当我用C#这个词搜索它时会显示0个结果。
我正在使用StandardAnalyzer和MultiFieldQueryParser也允许通配符搜索(AllowLeadingWildcard = true)。
[删除重复代码]
当我用C#这个词搜索时,请告诉我要检索结果我需要做些什么。
谢谢,
Singaravelu R
我的尝试:
I’m using Lucene.Net 3.0.3.0 version in my website to search list of courses.
I have few courses which contains the special character "#" like, C#, C#.Net, etc.
But When I search with the term "C#" it showing 0 results.
I’m using StandardAnalyzer and MultiFieldQueryParser also allowing wildcard search (AllowLeadingWildcard = true).
[duplicate code removed]
Kindly let me know what I have to do to retrieve the result when I search with the term "C#".
Thanks,
Singaravelu R
What I have tried:
var analyzer = new StandardAnalyzer(Version.LUCENE_30, stopWords);
{
BooleanQuery query = new BooleanQuery();
var nameParser = new MultiFieldQueryParser(Version.LUCENE_30, new[] { "Column1", " Column2", " Column3" }, analyzer);
if (!string.IsNullOrEmpty(searchCriteria.CourseName))
{
query.Add(parseQuery(GetTerms(searchCriteria.CourseName.ReplaceDiacritics()), nameParser), Occur.MUST);
}
ScoreDoc[] hits = searcher.Search(query, null, hits_limit, Sort.RELEVANCE).ScoreDocs;
var results = _mapLuceneToDataList(hits, searcher);
analyzer.Close();
searcher.Dispose();
return results;
}
索引:正确索引和存储单词C#。
For indexing: The word "C#" indexed and stored correctly.
doc.Add(new Field("Title",
sampleData.CourseName,
Field.Store.YES,
Field.Index.ANALYZED));
推荐答案
是的我已经根据Lucene问题跟踪器https://issues.apache.org/中提供的建议创建了我自己的分析器jira / browse / LUCENENET-595。
现在它运作良好。
谢谢,
Singaravelu
Yes I have created my own Analyzer by the suggestion provided in the Lucene issue tracker "https://issues.apache.org/jira/browse/LUCENENET-595".
Now its working well.
Thanks,
Singaravelu
这篇关于使用特殊字符“#”的通配符搜索不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!