1. <i id='xGV7Z'><tr id='xGV7Z'><dt id='xGV7Z'><q id='xGV7Z'><span id='xGV7Z'><b id='xGV7Z'><form id='xGV7Z'><ins id='xGV7Z'></ins><ul id='xGV7Z'></ul><sub id='xGV7Z'></sub></form><legend id='xGV7Z'></legend><bdo id='xGV7Z'><pre id='xGV7Z'><center id='xGV7Z'></center></pre></bdo></b><th id='xGV7Z'></th></span></q></dt></tr></i><div id='xGV7Z'><tfoot id='xGV7Z'></tfoot><dl id='xGV7Z'><fieldset id='xGV7Z'></fieldset></dl></div>
      <legend id='xGV7Z'><style id='xGV7Z'><dir id='xGV7Z'><q id='xGV7Z'></q></dir></style></legend>

      <small id='xGV7Z'></small><noframes id='xGV7Z'>

        <bdo id='xGV7Z'></bdo><ul id='xGV7Z'></ul>

        <tfoot id='xGV7Z'></tfoot>

        Lucene 和特殊字符

        Lucene and Special Characters(Lucene 和特殊字符)
        <i id='H9BBl'><tr id='H9BBl'><dt id='H9BBl'><q id='H9BBl'><span id='H9BBl'><b id='H9BBl'><form id='H9BBl'><ins id='H9BBl'></ins><ul id='H9BBl'></ul><sub id='H9BBl'></sub></form><legend id='H9BBl'></legend><bdo id='H9BBl'><pre id='H9BBl'><center id='H9BBl'></center></pre></bdo></b><th id='H9BBl'></th></span></q></dt></tr></i><div id='H9BBl'><tfoot id='H9BBl'></tfoot><dl id='H9BBl'><fieldset id='H9BBl'></fieldset></dl></div>
          <bdo id='H9BBl'></bdo><ul id='H9BBl'></ul>

                <tbody id='H9BBl'></tbody>
              <tfoot id='H9BBl'></tfoot>

                  <small id='H9BBl'></small><noframes id='H9BBl'>

                  <legend id='H9BBl'><style id='H9BBl'><dir id='H9BBl'><q id='H9BBl'></q></dir></style></legend>

                  本文介绍了Lucene 和特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 Lucene.Net 2.0 来索引数据库表中的某些字段.其中一个字段是允许特殊字符的名称"字段.当我执行搜索时,它找不到包含带有特殊字符的术语的文档.

                  I am using Lucene.Net 2.0 to index some fields from a database table. One of the fields is a 'Name' field which allows special characters. When I perform a search, it does not find my document that contains a term with special characters.

                  我这样索引我的字段:

                  Directory DALDirectory = FSDirectory.GetDirectory(@"C:IndexesName", false);
                  Analyzer analyzer = new StandardAnalyzer();
                  IndexWriter indexWriter = new IndexWriter(DALDirectory, analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED);
                  
                  Document doc = new Document();
                  doc.Add(new Field("Name", "Test (Test)", Field.Store.YES, Field.Index.TOKENIZED));
                  indexWriter.AddDocument(doc);
                  
                  indexWriter.Optimize();
                  indexWriter.Close();
                  

                  我搜索执行以下操作:

                  value = value.Trim().ToLower();
                  value = QueryParser.Escape(value);
                  
                  Query searchQuery = new TermQuery(new Term(field, value));
                  Searcher searcher = new IndexSearcher(DALDirectory);
                  
                  TopDocCollector collector = new TopDocCollector(searcher.MaxDoc());
                  searcher.Search(searchQuery, collector);
                  ScoreDoc[] hits = collector.TopDocs().scoreDocs;
                  

                  如果我搜索名称"字段和测试"值,它会找到文档.如果我执行与名称"相同的搜索和与测试(测试)"相同的值,那么它不会找到该文档.

                  If I perform a search for field as 'Name' and value as 'Test', it finds the document. If I perform the same search as 'Name' and value as 'Test (Test)', then it does not find the document.

                  更奇怪的是,如果我删除 QueryParser.Escape 行搜索 GUID(当然,其中包含连字符),它会找到 GUID 值匹配的文档,但执行与测试"值相同的搜索(Test)' 仍然没有结果.

                  Even more strange, if I remove the QueryParser.Escape line do a search for a GUID (which, of course, contains hyphens) it finds documents where the GUID value matches, but performing the same search with the value as 'Test (Test)' still yields no results.

                  我不确定我做错了什么.我正在使用 QueryParser.Escape 方法来转义特殊字符并存储字段并通过 Lucene.Net 的示例进行搜索.

                  I am unsure what I am doing wrong. I am using the QueryParser.Escape method to escape the special characters and am storing the field and searching by the Lucene.Net's examples.

                  有什么想法吗?

                  推荐答案

                  StandardAnalyzer 在索引过程中去除特殊字符.您可以传入明确的停用词列表(不包括您想要的停用词).

                  StandardAnalyzer strips out the special characters during indexing. You can pass in a list of explicit stopwords (excluding the ones you want in).

                  这篇关于Lucene 和特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  C# namespace alias - what#39;s the point?(C# 命名空间别名 - 有什么意义?)
                  Using Xpath With Default Namespace in C#(在 C# 中使用具有默认命名空间的 Xpath)
                  Generating an EDMX from a DB2 Database(从 DB2 数据库生成 EDMX)
                  IBM .NET Data Provider Connection String issue with Library List(库列表的 IBM .NET 数据提供程序连接字符串问题)
                  .NET DB2 OLEDB pre-requisites(.NET DB2 OLEDB 先决条件)
                  Referring to Code in IBM.Data.DB2 makes that Assembly Unavailable to the rest of my Solution(引用 IBM.Data.DB2 中的代码使该程序集对我的解决方案的其余部分不可用)

                      <i id='hEoWE'><tr id='hEoWE'><dt id='hEoWE'><q id='hEoWE'><span id='hEoWE'><b id='hEoWE'><form id='hEoWE'><ins id='hEoWE'></ins><ul id='hEoWE'></ul><sub id='hEoWE'></sub></form><legend id='hEoWE'></legend><bdo id='hEoWE'><pre id='hEoWE'><center id='hEoWE'></center></pre></bdo></b><th id='hEoWE'></th></span></q></dt></tr></i><div id='hEoWE'><tfoot id='hEoWE'></tfoot><dl id='hEoWE'><fieldset id='hEoWE'></fieldset></dl></div>
                        <tbody id='hEoWE'></tbody>
                    • <tfoot id='hEoWE'></tfoot>

                        <bdo id='hEoWE'></bdo><ul id='hEoWE'></ul>
                        <legend id='hEoWE'><style id='hEoWE'><dir id='hEoWE'><q id='hEoWE'></q></dir></style></legend>

                            <small id='hEoWE'></small><noframes id='hEoWE'>