-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 13 posts ] 
Author Message
 Post subject: Search result sort order different in environments
PostPosted: Fri Apr 27, 2012 7:23 pm 
Newbie

Joined: Fri Mar 02, 2012 10:55 am
Posts: 10
This is driving me nut all day.

I have same set of code, same database. The sort order showed up differIently in my local environment than in the server.

I have tried all the tricks - delete the local index files or copied the index files from the server to make both environment looked the same, but once i re-indexed my local environment, the index changed and the sort order looked different.

for example:

in local: ID 160000 was in document #132 before re-index, after re-index it changed to document #133 for no reason. There is no database changes.
in the server: ID 160000 was in document #132 before and after re-index.

Can someone please give a clue?


Top
 Profile  
 
 Post subject: Re: Search result sort order different in environments
PostPosted: Mon Apr 30, 2012 7:44 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
the Document_ID is not deterministic, but this shouldn't matter as you won't sort queries by document id ?

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Search result sort order different in environments
PostPosted: Mon Apr 30, 2012 5:55 pm 
Newbie

Joined: Fri Mar 02, 2012 10:55 am
Posts: 10
I have ID 160000 on doc #132 and 170000 on doc #131.

The query sorted by ID, which is annotated as "@NumericField".

This is what I expect to see in my local env - order by ID in descending order.

ID
140000
150000
160000
170000

instead, I got something like this:

ID
140000
150000
170000
160000
180000
....


The same code ran on the server has the right order I wanted. Just don't understand why it looked different in local.


Top
 Profile  
 
 Post subject: Re: Search result sort order different in environments
PostPosted: Mon Apr 30, 2012 8:47 pm 
Newbie

Joined: Fri Mar 02, 2012 10:55 am
Posts: 10
Can you help me understand why the sort order on the server is different from the sort order running on local?

it looks like on the local host, hibernate sorts by document # instead of the ID value.

What should i do to make the query to ignore the document #?


Top
 Profile  
 
 Post subject: Re: Search result sort order different in environments
PostPosted: Tue May 01, 2012 6:34 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
What Sort are you specifying?

The default Sort is by relevance, but relevance isn't very meaningfull when searching for numbers for example; so unless you have some similarty scoring to do on free text, you would need to specify a field on which to sort on. If you don't, the results are a bit unpredictable as the natural order in which they might be returned in the index would match the stored order, which is depending on timing and thread interleaving during index creation.

Code:
org.hibernate.search.FullTextQuery query = s.createFullTextQuery( query, Book.class );
org.apache.lucene.search.Sort sort = new Sort(
    new SortField("title", SortField.STRING));
query.setSort(sort);
List results = query.list();

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Search result sort order different in environments
PostPosted: Wed May 02, 2012 7:28 am 
Newbie

Joined: Fri Mar 02, 2012 10:55 am
Posts: 10
We have the sort criteria on 2 numeric fields: sorting Order_id within Order_number. Order_number seems to be sorted correctly, but the order_ID is not.

Sort sort = new Sort(
new SortField("order_number", SortField.LONG),
new SortField("id", SorField.LONG));

Any clue please?


Top
 Profile  
 
 Post subject: Re: Search result sort order different in environments
PostPosted: Wed May 02, 2012 10:29 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
do you have a unit test you could share so we can see the full picture and debug it?

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Search result sort order different in environments
PostPosted: Wed May 02, 2012 10:34 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
also, is the field mapped as
Code:
new SortField("order_number", SortField.LONG),


annotated with @NumericField and is a double ?

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Search result sort order different in environments
PostPosted: Wed May 02, 2012 12:35 pm 
Newbie

Joined: Fri Mar 02, 2012 10:55 am
Posts: 10
Thanks for helping. Here are some code snippets:

entity:

Order ID is also a primary key in the database.

@Entity
@Table(name = "ORDER"
@NameQueries.....
@Indexed
Public class Order ....

// Order ID is a primary key in the database and we also want it searchable and sorted.
@Id
@DocumentId
@Basic(optional = false)
@Column(name = "ID")
@GeneratedValue(generator="...seq")
@SequenceGenerator(name="...", sequenceName="....")
@Field(index=Index.TOKENIZED) // we want the ID searchable
@NumericField
private Long ID;

// brigde to Order_Status
@JoinColumn (name = "ORDER_STATUS", referencedColumnName = "ORDER_STATUS")
@ManyToOne
@IndexedEmbedded
private OrderStatus orderStatus;

In Order_Status entity: question, do we need annotation @Index in OrderStatus class? We didn't code one, but the sort on order_status is not a problem. The problem is having ID to sort within order_status.

@Entity
@Table(name...)
@Namedqueries(....)
public class OrderStatus....
.....
@Column(name="ORDER_STATUS")
@Field(index=Index.UN_TOKENIZED)
@NumericField
private Long order_status;

In DAO:

Sort sort = new Sort( new SortField("orderStatus.order_status",SortField.LONG),
new SortField("ID",SortField.LONG));


Top
 Profile  
 
 Post subject: Re: Search result sort order different in environments
PostPosted: Wed May 02, 2012 12:46 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
thanks.

A field you're sorting on should never be TOKENIZED. Could you try removing the TOKENIZED ?

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Search result sort order different in environments
PostPosted: Wed May 02, 2012 2:23 pm 
Newbie

Joined: Fri Mar 02, 2012 10:55 am
Posts: 10
I changed to UN_TOKENIZED on the ID field. Rebuilt the indexes, and run the app again.
....
@Field(index=Index.UN_TOKENIZED)
@NumericField
private Long ID;

It doesn't make any differences. I am still seeing the following incorrect format. I am expecting to see 1,2,3,4,5,6,7 within 100.

Order_Status ID
100 1
100 2
100 4
100 3
100 5
100 7
100 6
200 ....
200 ....

Please help.


Top
 Profile  
 
 Post subject: Re: Search result sort order different in environments
PostPosted: Thu May 03, 2012 9:24 pm 
Newbie

Joined: Fri Mar 02, 2012 10:55 am
Posts: 10
Any more help on this one please?


Top
 Profile  
 
 Post subject: Re: Search result sort order different in environments
PostPosted: Fri May 04, 2012 9:16 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

I did a quick check whether there is a problem w/ sorting numeric fields in general, but I could not reproduce your problem. The best would be if you could create a test case we can run on our side.

Circling back to your original post as well. You were saying that this problem is also environment dependent? It works on your development machine, but not on the server you are deploying to? Is this still the case? What operating systems are involved and which Java runtime environments? Which version of Search are you using?

--Hardy


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 13 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.