Lazy loaded property isn't indexed properly

Description

@Column(name = "CONTENT")
@Length(min = 0, max = 32768)
@Basic(fetch = FetchType.LAZY) // Lazy loaded through bytecode instrumentation
@org.hibernate.search.annotations.Field(index = org.hibernate.search.annotations.Index.TOKENIZED)
private String content;

I use fulltextSession.index(o) and I only get two terms indexed "text" and "edit". I don't know where these are coming from actually, no object has these content values.

If I trigger an o.getContent() before fulltextSession.index(o), the content is loaded with sequential selects for the lazy property and correctly indexed.

Activity

Show:

Emmanuel BernardAugust 8, 2007 at 3:42 PM

Hi Alexander, can you open a new JIRA issue and provide a test case for the problem you are experiencing. The problem seems different than the one described here.

Alexander ChebanenkoAugust 8, 2007 at 5:01 AM

There is a problem with DocumentBuilder, getDocument method. It uses "entity.getClass()" instead of "Hibernate.getClass(entity)", thus resulting document has "_hibernate_class" field value equal to hibernate proxy class, not entity class. No search could be performed later on such an index, since search injects criteria "_hibernate_class:Entity".

Emmanuel BernardJuly 31, 2007 at 7:55 PM

The code does not lose the last row. I have it working in the test suite

FullTextSession s = Search.createFullTextSession( openSession() );
Transaction tx = s.beginTransaction();
int loop = 14;
for (int i = 0; i < loop; i++) {
s.connection().createStatement().executeUpdate( "insert into Email(id, title, body, header) values( + "
+ ( i + 1 ) + ", 'Bob Sponge', 'Meet the guys who create the software', 'nope')" );
}
tx.commit();
s.close();

//check non created object does get found!!1
s = new FullTextSessionImpl( openSession() );
tx = s.beginTransaction();
ScrollableResults results = s.createCriteria( Email.class ).scroll( ScrollMode.FORWARD_ONLY );
int index = 0;
while ( results.next() ) {
index++;
s.index( results.get( 0 ) );
if ( index % 5 == 0 ) s.clear();
}
tx.commit();
s.clear();
tx = s.beginTransaction();
QueryParser parser = new QueryParser( "id", new StopAnalyzer() );
List result = s.createFullTextQuery( parser.parse( "body:create" ) ).list();
assertEquals( 14, result.size() );
for (Object object : result) {
s.delete( object );
}
tx.commit();
s.close();

Christian BauerJune 12, 2007 at 9:34 AM

I am using this as a workaround, seems to be smarter anyway because it doesn't trigger the sequential selects:

ScrollableResults cursor = session.createQuery("select o from " + entityClass.getName() + " o fetch all properties").scroll();

Christian BauerJune 12, 2007 at 9:16 AM

Documentation example is also wrong for batching (yeah it is also wrong in the H3 reference docs), the batch misses the last row:

transaction = fullTextSession.beginTransaction();
//Scrollable results will avoid loading too many objects in memory
ScrollableResults results = fullTextSession.createCriteria( Email.class ).scroll( ScrollMode.FORWARD_ONLY );
int index = 0;
while( results.next() ) {
index++;
fullTextSession.index( results.get(0) ); //index each element
if (index % batchSize == 0) s.clear(); //clear every batchSize since the queue is processed
}
transaction.commit();

Should be:

transaction = fullTextSession.beginTransaction();
//Scrollable results will avoid loading too many objects in memory
ScrollableResults results = fullTextSession.createCriteria( Email.class ).scroll( ScrollMode.FORWARD_ONLY );
int index = 0;
while( true ) {
index++;
fullTextSession.index( results.get(0) ); //index each element
if (index % batchSize == 0) s.clear(); //clear every batchSize since the queue is processed

if (results.isLast())
break;
else
results.next();
}
transaction.commit();

Out of Date

Details

Assignee

Reporter

Components

Affects versions

Priority

Created June 12, 2007 at 9:07 AM
Updated May 7, 2011 at 8:59 PM
Resolved May 7, 2011 at 8:59 PM

Flag notifications