搜索结果归因于 Hibernate 搜索中的字段

发布于 2024-08-14 09:49:24 字数 64 浏览 5 评论 0原文

我有一个 Hibernate 搜索,可以从对象的许多字段中进行搜索。是否可以知道哪些字段与每个结果对象的结果匹配?

I have a Hibernate search that searches from many a field of an object. Is it possible to know which of the fields matched the results for each result object?

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

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

发布评论

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

评论(1

随风而去 2024-08-21 09:49:24

不是开箱即用的。有关匹配字段的一些信息可以从 Lucene Explanation 对象中提取,您可以通过 Hibernate Search 中的投影来检索该对象。问题在于该对象是为搜索结果的视觉检查而设计的,而不是作为编程接口。您可以解析字符串输出,但格式可能在 Lucene 的更高版本中发生变化。

另一种选择是迭代匹配文档并手动(例如通过正则表达式)尝试找出匹配的字段。这也相当棘手,因为根据您的 Lucene 查询,可能很难想出正则表达式。

这取决于您的具体用例。您需要这些信息做什么?也许还有替代解决方案。

Not out of the box. Some information about which fields matched can be extracted from the Lucene Explanation object which you can retrieve via projection in Hibernate Search. The problem is that this object is designed for visual inspection of the search results not as a programmatic interface. You could parse the string output, but the format might change in later versions of Lucene.

Another option would be to iterate the matching documents and manually (eg via regular expressions) try to find out which fields matched. This is quite tricky as well, since depending on your Lucene query it might be quite hard to come up with a regular expression.

It comes down to your concrete usecase. What do you need this information for? Maybe there is an alternative solution.

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