The moose likes Object Relational Mapping and the fly likes Hibernate Order By Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "Hibernate Order By" Watch "Hibernate Order By" New topic
Author

Hibernate Order By

Patrick McDonogh
Ranch Hand

Joined: Oct 13, 2005
Posts: 89
Hi there all,

I am really unsure how this is done.
You know how sometimes on web sites you see an order by option like order by relevance and a percentage is retured with how relevant the record is to the entered search criteria.
For instance say i have a table with tow columns Name and Age and 5 records in the table.

NAME AGE
Arthur 5
Adrian 7
Paul 12
Nadeline 9
Adam 5

Say i create a criteria object specified to fetch me rows where name ilike "Ad" with a fetch mode of anywhere or age equals 5.
"where name ilike '%Ad%' or age = '5'"

This would return the following rows:
Arthur 5
Adrian 7
Adam 5
Nadeline 9

I then want to order the results by relevance, so Adam should be first as that row matched both the name and age condition.

Anyone know how to do this or how to get percent matches returned, or where there is some info posted on this.
I would really like to do this at the database level.

Cheers, for the help and have a great day.
saranga rao
Ranch Hand

Joined: Apr 24, 2007
Posts: 49
hi


between, in, and like:


session.createCriteria(Accommodation.class)
.add(Expression.between("availabilityDate",
startDate,
endDate))
.list();

session.createCriteria(Country.class)
.add(Expression.like("A%")).Order.asc("availabilityDate")
.list();

favoriteOwners = new ArrayList();
...
session.createCriteria(Accommodation.class)
.add(Expression.in("owner",
favoriteOwners))
.list();
Patrick McDonogh
Ranch Hand

Joined: Oct 13, 2005
Posts: 89
I dont really understand how this answers the question.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


You know how sometimes on web sites you see an order by option like order by relevance and a percentage is retured with how relevant the record is to the entered search criteria.

Typically relevance grading is being done by a more sophisticated search tool than a relational database (i.e. Lucene).

Using Hibernate, well doing this isn SQL or HQL is going to be difficult. However Hibernate searches return Collections of results, and Collections can be sorted based on Comparators. Could you not define your relevance rules in a Comparator and sort the list like that?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
 
IntelliJ Java IDE
 
subject: Hibernate Order By
 
Threads others viewed
Search Strategy
using rownum with union
collections- Odered,sorted etc
How to handle this large result set
JSTL vs DOM generated HTML Table
MyEclipse, The Clear Choice