-->
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: [Hibernate Search] Indexing and null values
PostPosted: Mon Jun 11, 2007 6:01 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
Hello,

I have a new problem with Indexing and null values.

I have an "Entite" class with a list of "Document" called "documents".

When I insert a new Document (without null values except for id field) and add it to an Entite, I have good index files :

Image

But if one field of the inserted Document is null, all fields are null :

Image

I want to index an object with empty fields. Is it possible ?

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 11, 2007 7:30 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
It should be possible, can you create a JIRA issue with a test case?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 12, 2007 4:58 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
emmanuel wrote:
It should be possible, can you create a JIRA issue with a test case?


Yes it's possible. When I was creating a unit test class, I found where is the problem : FieldBridge !

For exemple, when we have a "Document" class with the field :
Quote:
@Field(index=Index.TOKENIZED, store=Store.YES)
@FieldBridge(impl = PaddedIntegerBridge.class)
private Integer largeur;


And we create a new "Document" object with largeur = null, no index file for this object was created.

This is my PaddedIntegerBridge class :

Quote:
public class PaddedIntegerBridge implements StringBridge
{
private static int PADDING = 10;

public String objectToString(Object object) {
return integerToString((Integer) object);
}

public static String integerToString(int entier)
{
String rawInteger = ""+entier;
if (rawInteger.length() > PADDING)
throw new RuntimeException("Try to pad on a number too big");

StringBuilder paddedInteger = new StringBuilder();
for (int padIndex = rawInteger.length(); padIndex < PADDING; padIndex++ )
{
paddedInteger.append('0');
}

return paddedInteger.append( rawInteger ).toString();
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 12, 2007 5:15 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
The solution is to test if the object is null, and then return null if it is :

Quote:
public String objectToString(Object object) {
if(object == null) return null;
return integerToString((Integer) object);
}


But I think the test should be in HSearch, because it's difficult to know why there is no data in indexes.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 13, 2007 3:01 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
An autoboxing exception should have been raised somewhere, I guess. It's weird that you don't see it.

_________________
Emmanuel


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.