-->
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.  [ 12 posts ] 
Author Message
 Post subject: Hibernate Search not able to fetch row after manual index
PostPosted: Thu May 28, 2009 9:36 am 
Newbie

Joined: Tue May 19, 2009 4:49 am
Posts: 14
Hello every1,

I am stuck in a strange problem. I am using hibernate search to Query. It works good. But now when I update the an row (index) manually, i.e. by manaul indexing code , although the update in file goes right. But when I search back the updated entry its not able to find it.

While I am able to search the same result with same query , from Lucene ToolBox.

Any idea ??


Top
 Profile  
 
 Post subject: Re: Hibernate Search not able to fetch row after manual index
PostPosted: Thu May 28, 2009 12:21 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Can you give some more details? Which version of Hibernate Search? How does the indexing and searching code look like?
Some log messages might be handy as well.

--Hardy


Top
 Profile  
 
 Post subject: Re: Hibernate Search not able to fetch row after manual index
PostPosted: Thu May 28, 2009 12:37 pm 
Newbie

Joined: Tue May 19, 2009 4:49 am
Posts: 14
Hey Hardy,

Hibernate Details :
hibernate-core.jar - ver 3.3.1.GA
hibernate-search.jar - ver 3.1.0.GA
hibernate-commons-annotations.jar - ver 3.1.0.GA

Now to update the file manually I use this code:
org.hibernate.Transaction tx = session.beginTransaction();
Search.getFullTextSession(session).index( dataObject );
tx.commit();

The above stuff works good enough. And I am able to see the updated data using Lucene tool.
But , now when I search the same updated object using hibernate search , I am getting back the old data object values.

Search code snippet :
org.apache.lucene.search.Query luceneQuery = parser.parse( searchQuery );
org.hibernate.Query fullTextQuery = fullTextSession.createFullTextQuery( luceneQuery );
List query = fullTextQuery.list();

Let me know if more details are required.


Top
 Profile  
 
 Post subject: Re: Hibernate Search not able to fetch row after manual index
PostPosted: Thu May 28, 2009 1:43 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Could it be the analyzer? You are not posting the code where you create the QueryParser, but you should use the same analyzer for indexing and searching. Also you are not showing any session management around the query, but I assume the search happens within a new session and transaction, right?

--Hardy


Top
 Profile  
 
 Post subject: Re: Hibernate Search not able to fetch row after manual index
PostPosted: Mon Jun 01, 2009 7:39 am 
Newbie

Joined: Tue May 19, 2009 4:49 am
Posts: 14
Thanks Hardy ,
It was issue with Analyzer only .

One more help :
Can you tell me a way to update a row in index file. I mean a code snippet.
I do have the the Entity data object , which I need to update in index file.
I am trying the following :
Search.getFullTextSession(session).index( dataObject ); // This is basically the code to do a manual indexing. If you can share any better way, it will be helpful.


Top
 Profile  
 
 Post subject: Re: Hibernate Search not able to fetch row after manual index
PostPosted: Mon Jun 01, 2009 8:12 am 
Hibernate Team
Hibernate Team

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

Code:
Search.getFullTextSession(session).index( dataObject );
is the right way to do an explicit indexing.

Depending on your usecase I recommend you have a look at automatic indexing. In this case each time you create/update Hibernate managed (and indexed) entities the Lucene index gets updated automatically.

--Hardy


Top
 Profile  
 
 Post subject: Re: Hibernate Search not able to fetch row after manual index
PostPosted: Mon Jun 01, 2009 8:37 am 
Newbie

Joined: Tue May 19, 2009 4:49 am
Posts: 14
Hi Hardy,

My usecase flow doesnot permit me to use auto indexing. If would have been , life would be sooo easy :)

Anyway, now when I try doing UPDATE using manual indexing command mentioned earlier. It gets me error :
org.hibernate.HibernateException: More than one row with the given identifier was found

I guess this error comes, because the maual indexing code statement below tries to INSERT a new row , when I am looking for update . Can you suggest some way out?
I mean in case of auto indexing , also how does it work ? Does it internally first makes a purge(DELETE) of row and then adds a new row ? Or is there some other way out ?


Top
 Profile  
 
 Post subject: Re: Hibernate Search not able to fetch row after manual index
PostPosted: Mon Jun 01, 2009 8:58 am 
Hibernate Team
Hibernate Team

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

it would help to see your indexing code and the annotated entities.

Manual indexing does not insert any new records in the database. You have to seperate the database from the Lucene index. In your description I get the feeling you are mixing two concepts up a little.

Regarding autoindexing - Hibernate works as usual, however there is a Search event listnener which will be called if an entity has changed. In this case the matching Lucene document for this entity gets deleted and recreated. This is the Lucene way of updating indexed data.

If this does not make any sense to you, I recommend to read through the online documentation, especially also through the sections describing the inner workings of Hibernare Search. Or even better get a copy of "Hibernate Search in Action" ;-)

--Hardy


Top
 Profile  
 
 Post subject: Re: Hibernate Search not able to fetch row after manual index
PostPosted: Mon Jun 01, 2009 9:36 am 
Newbie

Joined: Tue May 19, 2009 4:49 am
Posts: 14
Hi ,

My Entity :
public class Search{

@Fields({
@Field(name="fName"),
@Field(name="fName_phonetic", analyzer=@Analyzer(definition="phonetic"))
})
protected String fName;

@Fields({
@Field(name="lName"),
@Field(name="lName_phonetic", analyzer=@Analyzer(definition="phonetic"))
})
protected String lName;

@DocumentId
@Field
@Analyzer(impl = WhitespaceAnalyzer.class)
protected String primKey;

//setter & getter for each . I use XML based configuration . So rest annotations are there.

}

My Indexing code :

// getting the session,analyzer etc
session = sessionFactory.openSession();
FullTextSession fullTextSession = Search.getFullTextSession(session);
SearchFactory searchFactory = fullTextSession.getSearchFactory();
Analyzer phoneticAnalyzer = searchFactory.getAnalyzer(SearchData.class);
org.apache.lucene.queryParser.QueryParser parser =
new QueryParser("primKey",phoneticAnalyzer);

searchQuery = "primKey:" + dataDO.getPrimKey();
org.apache.lucene.search.Query luceneQuery = parser.parse(searchQuery);
org.hibernate.Query fullTextQuery = fullTextSession.createFullTextQuery( luceneQuery );

// search result list will have only one object , becasue unique primary key
List query = fullTextQuery.list();

if(query !=null){
// Updating the data object retrieved from Lucene index with the latest DO
Search searchResultDO = (Search)query.get(0);
searchResultDO.setLName(dataDO.getLName());
searchResultDO.setFName(dataDO.getFName());

session.setFlushMode(FlushMode.MANUAL);
session.setCacheMode(CacheMode.IGNORE);
org.hibernate.Transaction tx = session.beginTransaction();
// saving the changes in lucene index
Search.getFullTextSession(session).index( searchResultDO );
tx.commit();
}


Dues to my usecase & business logic the Search DO is mapped to a VIEW . And dataDO is mapped to another TABLE.

hardy.ferentschik wrote:
Hi,

Manual indexing does not insert any new records in the database. You have to seperate the database from the Lucene index. In your description I get the feeling you are mixing two concepts up a little.

--Hardy


I didnt mean that a new row is to be added to database. I meant adding new row to lucene index only. So in case of automatic indexing, Hibernate Search is also deleting & then adding a new row in index file. I can aslo follow the same in my application by doing a purge before executing my index statement.
I am just afraid about the performace of this, once we have bulk of users together working out.


Top
 Profile  
 
 Post subject: Re: Hibernate Search not able to fetch row after manual index
PostPosted: Mon Jun 01, 2009 12:23 pm 
Hibernate Team
Hibernate Team

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

here are a few comments. First of all I would give automatc indexing a go. Manual indexing is intended for initial index creation. If indexing performace becomes an issue than a master/slave setup is probably the way to go, since you are then offloading the indexing to the master while the search clients can still serve search requests.

Regarding your annotations. It seems your document id (and maybe even your hibernate id) have also some business logic. This is not recommended. It would probably better to have a seperate id (primary key). Either way you should plave the analyzer to use for primKey into the @Field annotation. I think that would be clearer.

In your indexing code you are then searching using 'primKey'. This means you might get multiple results in your result query since phonetically several lucene documents could match. However, you are just updating the first entry. Maybe that's your usecase, but it seems very suspect.

I also think you should get the terminology right. There are no rows in the Lucene index. There we are dealing with Lucene documents. As said, have a thorough read through the manual first. I am sure things will become clearer then.

--Hardy


Top
 Profile  
 
 Post subject: Re: Hibernate Search not able to fetch row after manual index
PostPosted: Tue Jun 02, 2009 12:10 pm 
Newbie

Joined: Tue May 19, 2009 4:49 am
Posts: 14
Hey Hardy ,

I cannot opt for Auto Indexing ,a s my search (RETRIEVE) and update (INSERT/UPDATE) Data objects are of different class. As its the older existing application code, I cant make much changes on that. So have to opt for Manual indexing only.

While trying to query on the primKey , with SimpleAnalzer I was not able to retrieve results. So I tried theis WhiteSpace anaylzer and it worked. I have no business logic on the primKey(document id) .

I can understand that phonetic search would result in multiple results with same primKey. I was just thinking how would hibernate Auto Index take care of such scenario (update). i.e. will it also delete all the documents with same primKey and then add them again. Does it internally calls purge(Class entityType, Serializable id) ? Can you throw light on this ?

Regardins terminologies, yes I did went wrong. I have started going through the book thorougly ro get better insight :)


Top
 Profile  
 
 Post subject: Re: Hibernate Search not able to fetch row after manual index
PostPosted: Tue Jun 02, 2009 2:07 pm 
Newbie

Joined: Tue May 19, 2009 4:49 am
Posts: 14
Just to add up, I ahev two types of DataObject i.e. one for RETRIEVE and other for UPDATE/INSERT is beacause while RETIEVE the data comes from a VIEW which is combination of coulmns from many tables. While on UPDATE the data is updated in a single table only.


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