• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Order By

 
Patrick McDonogh
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont really understand how this answers the question.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic