Hibernate搜索手册索引

时间:2018-05-24 00:46:54

标签: java hibernate lucene hibernate-search

我是Hibernate Search的新手。我正在尝试集成Hibernate Search来搜索地址。我正在使用Hibernate Search 5.5.6.Final。我的地址表有> 1500万条记录。我使用手动索引为现有地址表创建lucene索引。索引完成但是当我通过Luke浏览它时,它的文档少于70,000个。这看起来是对的吗?文件编号不应该比记录数量多吗?有没有办法确保索引遍历所有记录?请帮忙......

这是我的目的:

@Entity
@Table (name = "ADDRESSES_LOOKUP")
@AnalyzerDef(name = "customanalyzer",
        tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
        filters = {
                @TokenFilterDef(factory = LowerCaseFilterFactory.class),
                @TokenFilterDef(factory = SnowballPorterFilterFactory.class, params = {
                        @Parameter(name = "language", value = "English")
                })
        })
@Indexed
public class Address {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column (name = "ADDRESS_ID")
    private String id;

    @Column (name = "BUILDING_NAME")
    @Field(index = Index.YES, analyze = Analyze.YES, store = Store.YES)
    @Analyzer(definition = "customanalyzer")
    private String buildingName;

    @Column (name = "FLAT_NUMBER")
    @Field(index = Index.YES, analyze = Analyze.YES, store = Store.YES)
    private String flatNumber;

    @Column (name = "FLAT_TYPE")
    @Field(index = Index.YES, analyze = Analyze.YES, store = Store.YES)
    private String flatType;

    @Column (name = "LEVEL_NUMBER")
    @Field(index = Index.YES, analyze = Analyze.YES, store = Store.YES)
    private String levelNumber;

    @Column (name = "LEVEL_TYPE")
    @Field(index = Index.YES, analyze = Analyze.YES, store = Store.YES)
    private String levelType;

    @Column (name = "NUMBER_FIRST")
    @Field(index = Index.YES, analyze = Analyze.YES, store = Store.YES)
    private String numberFirst;

    @Column (name = "NUMBER_LAST")
    @Field(index = Index.YES, analyze = Analyze.YES, store = Store.YES)
    private String numberLast;

    @Column (name = "STREET_NAME")
    @Field(index = Index.YES, analyze = Analyze.YES, store = Store.YES)
    private String streetName;

    @Column (name = "STREET_TYPE_CODE")
    @Field(index = Index.YES, analyze = Analyze.YES, store = Store.YES)
    private String streetType;

    @Column (name = "LOCALITY_NAME")
    @Field(index = Index.YES, analyze = Analyze.YES, store = Store.YES)
    private String locality;

    @Column (name = "STATE_ABBREVIATION")
    @Field(index = Index.YES, analyze = Analyze.YES, store = Store.YES)
    private String state;

    @Column (name = "POSTCODE")
    @Field(index = Index.YES, analyze = Analyze.YES, store = Store.YES)
    private String postcode;

    @Column (name = "ADDRESS")
    @Field(index = Index.YES, analyze = Analyze.YES, store = Store.YES)
    @Analyzer(definition = "customanalyzer")
    private String address;

这里是索引编码的代码

public void initializeHibernateSearch() {
    logger.info("Start initialising hibernate search index.");
    try {
        FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
        fullTextEntityManager
                .createIndexer()
                .typesToIndexInParallel( 3 )
                .batchSizeToLoadObjects( 50 )
                .cacheMode( CacheMode.IGNORE )
                .threadsToLoadObjects( 30 )
                .idFetchSize( 150 )
                .transactionTimeout( 1800 )
                .startAndWait();

    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    logger.info("HIBERNATE SEARCH INDEX INITIALISED.");
}

1 个答案:

答案 0 :(得分:0)

一个好的开始是使用ProgressMonitor(SimpleIndexingProgressMonitor或您定义的自定义变量)并逐步进入几种可用的方法,例如OAuth2,它应该告诉您有多少个地址打算索引。还有一种addToTotalCount方法应该可以使您看到一些进度。

printStatusMessage

该表中还有其他列吗?我想知道您是否只有70,000个在这些索引列中实际有数据的人。