【问题标题】:Lucene Document Container with Null Fields具有空字段的 Lucene 文档容器
【发布时间】:2013-04-02 23:55:53
【问题描述】:

我有一个桌面应用程序 实现 lucene 3.6.2 搜索引擎 用于数据库搜索。 数据库包含列 具有日期和字符数据类型 .某些列还可以包含空字段。 Datetools 也用于将 Date 转换为 Lucene 分析的字符串 然而看起来像当 lucene 不是 能够从 文档容器的日期列 进行分析。

我在下面展示代码sn-ps:

 doc = new Document();


         if(rs.getDate("DATE_OF_LETTER")== null)
         { doc.add(new Field("date_of_letter","",Field.Store.YES,Field.Index.ANALYZED)); }
         else {
        doc.add(new Field("date_of_letter",DateTools.dateToString(rs.getDate("DATE_OF_LETTER"),
                DateTools.Resolution.DAY),Field.Store.YES,Field.Index.ANALYZED)); 
         }       

        if(rs.getDate("DATE_RECEIVED")== null)
         { doc.add(new Field("date_received","",Field.Store.YES,Field.Index.ANALYZED)); }
        else {
          doc.add(new Field("date_received",DateTools.dateToString(rs.getDate("DATE_RECEIVED"),
                DateTools.Resolution.DAY),Field.Store.YES,Field.Index.ANALYZED));  
        }      

         if(rs.getString("REMARKS")== null)
         { doc.add(new Field("remarks","",Field.Store.YES,Field.Index.ANALYZED)); }
         else {
         doc.add(new Field("remarks",rs.getString("REMARKS"),Field.Store.YES,Field.Index.ANALYZED));  }

          if(rs.getDate("DATE_DISPATCHED")== null)
         { doc.add(new Field("date_dispatched","",Field.Store.YES,Field.Index.ANALYZED)); }
         else {
        doc.add(new Field("date_dispatched",DateTools.dateToString(rs.getDate("DATE_DISPATCHED"),
                DateTools.Resolution.MINUTE),Field.Store.YES,Field.Index.ANALYZED)); 

                }     
           }
         iw.addDocument(doc);
         }



   }   

任何建议。

【问题讨论】:

  • 事后检查索引时是否出现任何错误或字段值是否为空?
  • 我在 netbeans 控制台上没有收到错误,即使有命中但 lucene 不返回任何结果。请我如何检查索引请是 lucene 的新手
  • 有一个工具可以检查索引:getopt.org/luke - 看看它并检查字段是否设置在 lucene 索引中。

标签: java lucene


【解决方案1】:

这一行:

doc.add(new Field("date_received","",Field.Store.YES,Field.Index.ANALYZED));

实际上并没有做任何事情。没有什么可以索引的。它可能会存储该字段(我不确定,马上),但它肯定不会以任何方式被索引,因此无法搜索。 Lucene 对标记进行索引,而空字符串没有标记,因此没有可索引的内容,也没有可搜索的内容。

如果您希望能够搜索空值,您应该为它们索引一个占位符值,例如;

doc.add(new Field("date_received","null",Field.Store.YES,Field.Index.ANALYZED));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多