-->
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.  [ 8 posts ] 
Author Message
 Post subject: [Hibernate Search] Indexing/Searching Collections
PostPosted: Mon Jun 18, 2007 7:40 am 
Newbie

Joined: Mon Jun 18, 2007 7:23 am
Posts: 4
Version: Hibernate Search 3.0.0 Beta2

Hi,
I have the following mapping set up:

@Indexed(index="places")
class Place{
@DocumentId
Long id;

@Field(index=Index.TOKENIZED)
String country;

@IndexEmbedded
List<PlaceAttribute> attributes
}

@Indexed(index="attributes")
class PlaceAttribute{
@Field(index=Index.TOKENIZED)
String name;
@Field(index=Index.TOKENIZED)
String value;
}

What I would like to able to do is search for all places with a named attribute that contains a particular keyword e.g.
find all places where (attributes.name:Description AND attributes.value:London)

Looking at the index what gets stored is an attributes.name and attributes.value for each entry in the attributes list though I can't seem to find any way of associating the name to it's specific value.

Would it be possible to do this type of query using the current mapping or do I need to think about possibly storing a reference to the owner place in the PlaceAttribute class and dropping the IndexEmbedded on Place.attributes?

Many Thanks,
MB


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 18, 2007 11:05 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You're correct, this is not possible.
What I would do is something along those lines:
- query lucene to get the appropriate PlaceAttribute objects
- query with HQL from Place p join p.attributes a where a in (:matchingAttributes)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 18, 2007 4:22 pm 
Newbie

Joined: Mon Jun 18, 2007 7:23 am
Posts: 4
Hi Emmanuel,
Thanks for the reply -
I'm thinking of another approach, possibly having a customised version of the org.hibernate.search.engine.DocumentBuilder that uses the runtime value of PlaceAttribute.name in the Lucene document (e.g. attributes.Description). Do you think this would work? The reason I am thinking this is that my actual Place class has many more fields (in addition to 'country') that I wish to search on in addition to the custom attributes.

Thanks,
MB


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 18, 2007 6:51 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I don't really understand what you mean, how would it work?
note that you can always write a FieldBridge and have access to the Lucene Document during indexing, but I don't know how you want to store the data

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 20, 2007 3:11 pm 
Newbie

Joined: Mon Jun 18, 2007 7:23 am
Posts: 4
Basically I wanted to change the field name used in the Lucene document for the attributes; So instead of having

attribute.name=MyAtt1
attribute.value=Val1
attribute.name=MyAtt2
attribute.value=Val2

I wanted:
MyAtt1=Val1
MyAtt2=Val2


I have managed to do this with the FieldBridge as you suggest...

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 20, 2007 8:15 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Oh I see, interesting.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: important feature
PostPosted: Wed Jul 04, 2007 1:59 pm 
Newbie

Joined: Wed Jul 04, 2007 12:03 pm
Posts: 14
hello

if you use lucene directly it's power is exactly to have very efficient searches on key value pairs linked to a document (the same on a relational database results in much slower queries)

so to me this seems to be like a KEY feature for hibernate search, to efficiently make a MAP (key/value) efficiently searchable.

therefore you want exactly to have MyAtt1=Val1 inside the lucene index.

michael ! if you have a solution, please let us know !!!

emmanuel, in my humble opinion this is pretty key !!!

kind regards

koen


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 11, 2007 10:31 am 
Newbie

Joined: Mon Jun 18, 2007 7:23 am
Posts: 4
Hey koenhandekyn,

As mentioned before I have simply written a custom org.hibernate.search.bridge.FieldBridge implementation that goes through the map and adds each name/value pair to the Lucene document. Its just a matter of iterating over the map enties and adding a new Field to the document.

On the field containing the map you want to store this way put the annotation:

@FieldBridge(impl = CustomBridgeImpl.class)

This has worked fine for me so far...


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