Help coderanch get a
new server
by contributing to the fundraiser
  • 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:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Lucene search/sort question

 
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We're extending JForum's search page, and stumbled upon some strange behavior. Basically, sorting the results by date does not actually sort them by date, but some other way that isn't obviously sorted at all. Looking at the source code, I see the following in LuceneSearch.getSorter:

I suspect that the first parameter should be "SearchFields.Keyword.DATE", not "SearchFields.Keyword.POST_ID". Can someone confirm this, or am I not thinking straight?
[originally posted on jforum.net by udittmer]
 
Migrated From Jforum.net
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm part of the 'we' extending the software udittmer referred to. I figured out what was going on. Lucene is returning the correct values. (post id are date should be equivalent here)

Then GenericLuceneDAO.getPostsData generates the following SQL:


Which the database is NOT guaranteed to return in the order the in clause specifies. In our case (postgresql 8.2), the results were returned in a different order. Therefore the results return to the users unsorted.

I fixed it in our local installation by adding a call to the following method at the end of getPostsData().

[originally posted on jforum.net by boyarsky]
 
Migrated From Jforum.net
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good to know, this bug was new for me.

About your code, just adding an ORDER BY clause to the original sql query wouldn't fix the problem?

Rafael
[originally posted on jforum.net by Rafael Steil]
 
Migrated From Jforum.net
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rafael Steil wrote:About your code, just adding an ORDER BY clause to the original sql query wouldn't fix the problem?


No. The DAO is called regardless of sort order. In JForum, the options are relevance and date. Date/post id could potentially use order by with an API change to tell the DAO what to sort by. However, this isn't useful because relevance can't be sorted at the database end.

I'm reasonably confident the relevance sort has the same problem - that items within a page aren't sorted correctly. It's much harder to prove or disprove that of course! And as I have a fix, it's not really worth it at this point.

-Jeanne

[edited to fix double quoting]
[originally posted on jforum.net by boyarsky]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic