简体   繁体   English

如何配置Hibernate Search批量获取数据库行?

[英]How to configure Hibernate Search to batch fetching rows in database?

I'm using Hibernate Search to implement a full text search.我正在使用 Hibernate 搜索来实现全文搜索。 My database is SQL Server.我的数据库是 SQL 服务器。 Unfortunately, when my full text search retrieves too much documents, I face the limitation of SQL Server:不幸的是,当我的全文搜索检索到太多文档时,我面临 SQL 服务器的限制:

The incoming request has too many parameters. The server supports a maximum of 2100 parameters The incoming request has too many parameters. The server supports a maximum of 2100 parameters . The incoming request has too many parameters. The server supports a maximum of 2100 parameters

Indeed, after having found matching documents, Hibernate Search tries to load corresponding entities from the database, with a single query and a too big IN clause.实际上,在找到匹配的文档后,Hibernate 搜索会尝试使用单个查询和一个太大的 IN 子句从数据库中加载相应的实体。

So my question is, is it possible to configure Hibernate Search to fetch entities in batches from the database?所以我的问题是,是否可以配置 Hibernate Search 从数据库中批量获取实体?

You'd probably want to check the fetch size from loading options which allow you to set how many entities are loaded in a single trip to DB, something like:您可能希望从加载选项中检查获取大小,这些选项允许您设置在单次访问数据库时加载了多少实体,例如:

SearchResult<Book> result = searchSession.search( Book.class ) 
        .where( f -> f.match()
                .field( "title" )
                .matching( "robot" ) )
        .loading( o -> o.fetchSize( 50 ) ) 
        .fetch( 200 ); 

Also, if you expect to work with large result sets, you might want to check the scrolling instead.此外,如果您希望使用大型结果集,则可能需要检查滚动

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM