JPQL:按“最佳匹配”对查询结果进行排序可能的?
我有以下问题:
我正在使用 JPQL(JPA 2.0 和 eclipselink),我想创建一个查询,为我提供按以下方式排序的结果: 首先,结果按最佳匹配升序排序。之后应该会出现较差的比赛。 我的对象基于一个名为“Person”的简单类,其属性如下:
{String Id,
String forename,
String name}
例如,如果我正在搜索“Picol”,结果应如下所示:
[{129, Picol, Newman}, {23, Johnny, Picol},{454, Picolori, Newta}, {4774, Picolatus, Larimus}...]
PS:我已经考虑过使用两个查询,第一个是使用“equals”进行搜索”,第二个是“like”,尽管我不太确定如何连接两个查询结果......?
希望您的帮助并提前致谢, 弗洛里安
I have the following question/problem:
I'm using JPQL (JPA 2.0 and eclipselink) and I wanna create a query that gives me the results sorted the following way:
At first the results sorted ascending by the best matches. After that should appear the inferior matches.
My objects are based on a simple class called 'Person' with the attributes:
{String Id,
String forename,
String name}
For example if I'm searching for "Picol" the result should look like:
[{129, Picol, Newman}, {23, Johnny, Picol},{454, Picolori, Newta}, {4774, Picolatus, Larimus}...]
PS: I already thought about using two queries, the first is searching with "equals" and the second with "like", although I'm not quite sure how to connect both queryresults...?
Hope for your help and thanks in advance,
Florian
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果,正如您的问题似乎暗示的那样,您只有两个组(第一组:名字或名称等于搜索字符串;第二组:名字或名称包含搜索字符串),并且如果给定组的所有人员都具有相同的“匹配” Score”,那么使用两个查询确实是一个很好的解决方案。
第一个查询:
第二个查询:
执行两个查询(每个查询返回一个
List
),并将第二个列表的所有元素添加到第一个列表中(使用addAll()
代码>方法)If, as your question seem to imply, you only have two groups (first group : forename or name equals searched string; second group : forename or name contains searched string), and if all the persons of a given group have the same "match score", then using two queries is indeed a good solution.
First query :
Second query :
Execute both queries (each returning a
List<Person>
), and add all the elements of the second list to the first one (using theaddAll()
method)