使用 Hibernate-Search 进行复杂查询而不是 Criteria API

发布于 2024-10-03 14:40:32 字数 227 浏览 1 评论 0原文

在使用 Wicket+Spring+JPA/Hibernate 堆栈的应用程序中,我有一个收件箱/搜索页面,该页面应该具有相当复杂的搜索功能,其中保存在数据库中的记录使用无数的过滤选项进行过滤。到目前为止,我已经使用 JPA Criteria API 来构建数据库查询,但它变得非常混乱。我想知道 Hibernate-Search 是否适合这个,即使我并不真正需要任何全文搜索功能,我只是觉得(从我读到的内容来看)生成查询可能会更容易一些?

In an app using Wicket+Spring+JPA/Hibernate stack, I have an Inbox/Search page which should have quite complex search capabilities, where records saved in a database are filtered using a myriad of filtering options. So far I've used JPA Criteria API to build the database query but it's getting quite messy. I was wondering if Hibernate-Search would be a good fit for this even though I don't really need any full-text search capabilities, I just feel (from what I read about it) that producing the query might be a bit easier?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风渺 2024-10-10 14:40:32

抱歉,Hibernate Search 基于 Lucence。它不仅仅是一种其他查询语言。

Lucene 不会搜索数据库中的实体,而是搜索 Lucene 索引中的属性。
Hibernate Search 添加了将数据库中的实体连接到 Lucene 索引的功能。

Hibernate Search 和 Lucene 是您需要高级全文搜索时的创建工具。但如果你不需要它,那只是很多不必要的工作(和问题)。

所以,只要你不使用 Lucene,Hibernate Search 就不能满足你的需求。

Sorry, but Hibernate Search is based on Lucence. It is not just an other query language.

Lucene does not serach for entities in your database, it search for attibutes in the Lucene index.
Hibernate Search add the functionality to connect the Entities from your Database to the Lucene Index.

Hibernate Search and Lucene are create tool when you need advanced full text search. But if you don't need it, it is only a lot of unnesseary work (and problems).

So, as long as you do not use Lucene, Hibernate Search does not fit your needs.

念三年u 2024-10-10 14:40:32

Hibernate Search 的主要用例是全文搜索。但是,它也可用于索引/搜索简单属性/标准。编写查询的语法是否比条件查询更简单取决于个人喜好。
如果您不使用全文搜索功能,则必须考虑在应用程序中添加额外的步骤。搜索查询将针对 Lucene 索引运行,该索引将返回实体 id(除非使用投影)。然后将从数据库中获取匹配的实体。
另一方面,一旦您使用 Hibernate Search,就可以通过向某些条件添加一些全文搜索功能(如果可能)来轻松“改进”您的搜索。

无论您是否使用搜索,我认为关键是编写某种框架来以编程方式构建您的查询 - 搜索或条件查询。

The primary use case for Hibernate Search is fulltext search. However, it can also be used to index/search simple attributes/criteria. Whether the syntax for writing the queries is simpler than a criteria query is a matter of taste.
If you are not using the fulltext search capabilities you have to consider that you are adding an additional step in your application. The search query will be run against the Lucene index which will return entity ids (unless projection is used). The matching entities will then be fetched from the database.
On the other hand, once you use Hibernate Search it is easy to "improve" your search by adding some fulltext search capabilities to some of your criteria (if possible).

Whether or not you are using Search, I think the key is to write some sort of framework which programmatically builds your queries - Search or Criteria queries.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文