-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate Search sort order problem
PostPosted: Fri Mar 02, 2012 11:44 am 
Newbie

Joined: Fri Mar 02, 2012 10:55 am
Posts: 10
Here is the situation.

I have a Java jsf code using Lucene Index with Hibernate search. The search sort order is fine after the initial creation of the Lucene indexes. However, after editing an item from the result list, which results database changes, if perform another similar search again, the list is now in different sort order, which it is not expected. In order to see the correct order again, the Lucene indexes need to be reinitated.

Is this a Lucene index issue or Hibernate Search fails to update index with the database changes?

The user requirements are:
- sort order by Status, and ID
- all fields are searchable even the ID field. for example, if the search text is "1", the list will return records with 1 embedded in all fields.

The problem is:
After editing an item from the result list, which results database changes, if perform another similar search again, the list is now in different sort order, which it is not expected.

Lucene indexing code snippet:

FullTextEntityManager manager = Search.getFullTextEntityManager(getEntityManager());
List<Site> sites = manager.createQuery(
"select e from " + Site.class.getName() + " e")
.getResultList();
for (Site s : sites) {
s.getLocation();
s.getTitle();
s.getStatus();
manager.index(s);
}


For search, Query Parser is used:

FullTextEntityManager manager = Search
.getFullTextEntityManager(getEntityManager());
org.apache.lucene.queryParser.QueryParser parser = new QueryParser(
Version.LUCENE_31, "title", new
StandardAnalyzer(Version.LUCENE_31));
FullTextQuery searchLuceneQuery = manager.createFullTextQuery(
wordParserQuery, Site.class);
Sort sort = new Sort( new SortField("status",SortField.LONG.reverse));

The entity:
@Id
@DocumentId
@Basic(optional = false)
@Column(name = "ID")
@SequenceGenerator(name="SITE_ID_SEQ",sequenceName="SITE_ID_SEQ")
@GeneratedValue(generator="SITE_ID_SEQ")
@Field(index=Index.TOKENIZED)
private Long id;

@Field(index=Index.TOKENIZED)
@Column(name = "LOCATION")
private String location;

@Field(index=Index.TOKENIZED)
@Column(name = "STATUS")
private String status;

@Field(index=Index.TOKENIZED)
@Column(name = "TITLE")
private String title;


Any help would be appreciated.


Top
 Profile  
 
 Post subject: Re: Hibernate Search sort order problem
PostPosted: Fri Mar 02, 2012 12:49 pm 
Newbie

Joined: Fri Mar 02, 2012 10:55 am
Posts: 10
Updated new information.

Initial desired sort order before Editting.
Status Completed, ID 1
Status Completed, ID 5
Status Completed, ID 6
Status Incomplete, ID 2
.....

After Editting says Site 1 changing some other value (not Status). The list now looked like this in a new search. Notice that ID 1 is now at the bottome of the Status Completed group order.

Status Completed, ID 5
Status Completed, ID 6
Status Completed, ID 1
Status Incomplete, ID 2
.....

I have also tried to put in customed multi field sort and doesn't help. The only way to fix it is to run the Lucene Indexing again.

Please help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.