【问题标题】:Indexing POJO in Lucene在 Lucene 中索引 POJO
【发布时间】:2013-04-05 04:43:56
【问题描述】:

有没有一个很好的例子来说明如何在 Lucene 中为 POJO 建立索引——就像 JIRA 对问题所做的一样?

例如,如果你有类似的东西

class Book {
  private String author;
  private String title;
}

我希望在 Lucene 中对作者和标题字段的文本进行索引,以便我可以搜索它们。

我知道这是可能的,但还没有找到一个很好的简洁示例。

我使用的是 EclipseLink,而不是 Hibernate,所以 Hibernate Search 不是一个选项。

【问题讨论】:

    标签: lucene eclipselink pojo


    【解决方案1】:

    1) 案例 1:

    如果可以通过 getter 暴露 POJO 的所有要索引的内部属性。

    public interface Indexable{}
    
    class Book implements Indexable{}
    
    public interface POJOToLuceneDocumentConverter{    
          Document convert(Indexable obj);    
    }
    
    public class BookToLuceneDocumentConverter{
        public Document convert(Indexable obj){
        // build the Lucene document.
     }
    }
    

    2) 案例 2:

    如果您被限制不能通过 getter 公开所有要索引的数据。

    a) 为每个要索引的 POJO 创建一个内部类。

    b) 在该内部类中有一个从父类读取属性的方法

    c) 构建 Lucene 文档并返回。

    上述方法很幼稚。如果您正在寻找先进的、基于框架的、自动化的等,我不确定..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多