-->
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.  [ 5 posts ] 
Author Message
 Post subject: Fields not being indexed
PostPosted: Thu Oct 22, 2009 8:43 am 
Pro
Pro

Joined: Wed Oct 03, 2007 2:31 pm
Posts: 205
Hi

I am encountering a problem and i was wondering if I could get some help. Basically I have a object called Risk and an Object called Contract. The contract has some transient fields that are set by some external source. What I am trying to do is set the values on the transient fields onn contract and index the Risk object (by the way Contract is set as @IndexEmbedded on Risk and Risk has @ContainedIn in Contract).

The problem I am finding is that the values from the transient fields are not set even though the store strategy is YES. Basically I am doing something like this:

Code:
//simulating contract document from external source(different index)
Document contractDocument = new Document();
        contractDocument.add(new Field("id", "id", Store.YES, Index.ANALYZED));
        contractDocument.add(new Field("contract.values", "contract-values 1", Store.YES, Index.ANALYZED));
        contractDocument.add(new Field("contract.values", "contract-values 2", Store.YES, Index.ANALYZED));
        contractDocument.add(new Field("contract.values", "contract-values 3", Store.YES, Index.ANALYZED));
        contractDocument.add(new Field("reinsured-company", "reinsured-company", Store.YES, Index.ANALYZED));
        contractDocument.add(new Field("ref", "reference-xyz", Store.YES, Index.ANALYZED));
       
        Util.populateRiskWithData(contractDocument, contract);
       
        FullTextSession fullTextSession = Search.getFullTextSession(session);
       
        Transaction tx = fullTextSession.beginTransaction();
        fullTextSession.index(riskLoaded);
        fullTextSession.flushToIndexes();
        tx.commit();


The Util class basically takes the Lucene Doucment from a different source and copies the relevant feilds to the transient fields on the contract. After indexing the Risk I try to look for the fields in the document but don't see any. Am i doing something wrong?


Cheeer


Top
 Profile  
 
 Post subject: Re: Fields not being indexed
PostPosted: Thu Oct 22, 2009 12:53 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
To be honest I am not quite sure what you mean. Maybe you can provide the the code for the annotated entities. Also more information on what's happening here would be good. What is Util.populateRiskWithData doing and where is riskLoaded coming from?

--Hardy


Top
 Profile  
 
 Post subject: Re: Fields not being indexed
PostPosted: Thu Oct 22, 2009 2:38 pm 
Pro
Pro

Joined: Wed Oct 03, 2007 2:31 pm
Posts: 205
Hi

Apologies if what I posted did not make sense. Basically this is the situation:

We have a class called Risk which has an reference to a Contract. The contract has some transient fields which I want to index. The transient fields in the contract object will be populated from some other source. So the object structure with anntoation looks like this:
Code:
@Indexed
public class Risk {
    @IndexedEmbedded
    private Contract contract;
}

public class Contract {
  @ContainedIn
  private Risk risk;

@Field(name="valueA")
private transient String valueA;

@Field(name="valueB")
private transient String valueB;

..getters and setters for valueA and valueB
}


So what I'm doing is initiating a manual index of that Risk when an external source publishes an event which contains the data that I need to set for the transient fields in the Contract object. What the util class is essentially doing is
Code:
  contract.setValueA(document.get("fieldA");
  contract.setValueB(document.get("fieldB");


After populating the contract which I get from the risk I am try indexing the risk, the below gives an idea:
Code:
Risk riskLoaded = getRiskFromDao(riskId);
Contract contract = risk.getContract();
//renamed to make it clearer
Util.populateContractWithDataFromLuceneDocument(luceneDocument, contract);

FullTextSession fullTextSession = Search.getFullTextSession(session);
Transaction tx = fullTextSession.beginTransaction();
fullTextSession.index(riskLoaded);
fullTextSession.flushToIndexes();
tx.commit();


What I'm finding is that I don't see the values that are set on the transient fields indexed in the Risk lucene document and I can't search for them. I presume I should be able to index transient fields even though they are not being saved. The transient fields have the Store strategy to YES. The document that I am passing into the util method has the correct data and fields so I know it's not an issue with the document that I am passing into the util method.

Hope that makes more sense now.


Top
 Profile  
 
 Post subject: Re: Fields not being indexed
PostPosted: Fri Oct 23, 2009 3:34 am 
Pro
Pro

Joined: Wed Oct 03, 2007 2:31 pm
Posts: 205
Update:

I removed the transient keyword from the fields in contract and it works. I haven't mapped the fields in the hbm.xml file and I know they are not being persisted. This is strange. Does Hibernate search not index transient fields?


Cheers
Amin


Top
 Profile  
 
 Post subject: Re: Fields not being indexed
PostPosted: Fri Oct 23, 2009 5:23 am 
Hibernate Team
Hibernate Team

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

first I recommend you to add the following to your logging configuration:

Code:
log4j.logger.org.hibernate.search.backend.impl.lucene.works.AddWorkDelegate=trace


This will dump the content of the generated Lucene document just before it get added to the index.
Generally it should be no problem to index a transient field. What could explain your problem is if at some stage before the actual indexing occurs you merge/reload the saved entity. In this case the transient fields would be nulled or set to their default values. Is your example code exactly what you are doing? Where exactly start/end the sessions and transactions?

--Hardy


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