gpt4 book ai didi

java - Hibernate 搜索手动索引

转载 作者:太空宇宙 更新时间:2023-11-04 10:26:11 24 4
gpt4 key购买 nike

我是 Hibernate 搜索新手。我正在尝试集成 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.");
}

最佳答案

一个好的起点是使用 ProgressMonitor(SimpleIndexingProgressMonitor 或您定义的自定义监视器)并逐步使用一些可用的方法,例如 addTotalCount ,它应该告诉您它打算索引多少个地址。还有一个 printStatusMessage 方法可以为您提供一些进度可见性。

SimpleIndexingProgressMonitor progressMonitor = new SimpleIndexingProgressMonitor();
fullTextSession
.createIndexer(Address.class)
.typesToIndexInParallel(1)
.batchSizeToLoadObjects(50)
.cacheMode(CacheMode.IGNORE)
.threadsToLoadObjects(30)
.idFetchSize(150)
.progressMonitor(progressMonitor)
.startAndWait();

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

关于java - Hibernate 搜索手动索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50499354/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com