-->
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.  [ 7 posts ] 
Author Message
 Post subject: [hibernate seach] how to search array in Component?
PostPosted: Mon Jun 16, 2008 6:12 am 
Beginner
Beginner

Joined: Mon Dec 17, 2007 11:08 pm
Posts: 47
hi,

i got a array in a component,

public class place {

@ContainedIn
public address[] getAddress()
{
return //address orf array
}
}

MultiFieldQueryParser parser = new MultiFieldQueryParser( new String[]{ "address"}, new StandardAnalyzer());
Query query = parser.parse( "*road*" );


am i using the right way to query in array ?

i cannot find any result, even the matching text is in database.

please advice !

kiwi

_________________
happy hacking !


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 16, 2008 8:21 am 
Hibernate Team
Hibernate Team

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

here are a few comments. Firstly, I am not sure whether a simple array will work with Hibernate Search. You are better of with a List. Secondly, your example code is not quite complete. @ContainedIn alone won't have any effect. How does the Place and Adress entity look like with all their configuration? Which entity do you want to index?

I recommend you have a look at the online documentation. It contains a working configuration for a relationship Place -> Adress.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 17, 2008 12:42 am 
Beginner
Beginner

Joined: Mon Dec 17, 2007 11:08 pm
Posts: 47
hi, thx for reply.

the example show is just a sample that i wrote out.

imagine a scenario that look like this:

public class X implements Y
{
// what @annotation I should put here ?
public Z[] getYY()
{
// return array if Object Z[]
}
}

since the actual code had a interface (Y) that is return an array of X object instead of List, I not sure how should index this method to make it work. and i can't find an example that use array.

since the interface Y is from third party tool, we can;t just simple chnage the method signature.

I hasd success to index other accept this Field that use array.

any advice ?

kiwi

_________________
happy hacking !


Top
 Profile  
 
 Post subject: problem solved.
PostPosted: Tue Jun 17, 2008 3:23 am 
Beginner
Beginner

Joined: Mon Dec 17, 2007 11:08 pm
Posts: 47
hi, my problem had been solve.

I try to looking at the test case within hibernate search.

Indeed you are right. I had using the wrong @annotation.

I had put @IndexedEmbedded(targetElement=YourInterfaceImpl.class) for my collection of objects (it work in array of object too!).
and within YourInterfaceImpl, put the @Field for field want to index.

now is working like what i want.

thx a lot !

kiwi

_________________
happy hacking !


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 17, 2008 3:56 am 
Hibernate Team
Hibernate Team

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

You have to use @IndexEmbedded and make sure that the class Z in properly annotated as well. @IndexEmbedded tells Hibernate Search that the @Fields of Z are to be included into the index of X.

Assuming that your entity Z has a property called name which is annotated with @Field, an indexed instance of X would then have the Lucene fieldname yy.name.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 17, 2008 4:27 am 
Beginner
Beginner

Joined: Mon Dec 17, 2007 11:08 pm
Posts: 47
[delete duplicate]

_________________
happy hacking !


Last edited by kiwionly on Tue Jun 17, 2008 4:28 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 17, 2008 4:27 am 
Beginner
Beginner

Joined: Mon Dec 17, 2007 11:08 pm
Posts: 47
yes, I following this exactly. it work ok now.

btw, I found that if hibernate search doc can add an example to show how the embedded collection is index (like in code format from test case) maybe will be more understandable. (and faster to understand the concept too !)

anyway, keep up the good work !!

kiwi

_________________
happy hacking !


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