• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Hibernate Order By

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont really understand how this answers the question.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic