-->
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.  [ 4 posts ] 
Author Message
 Post subject: Applying weights to dynamic attributes
PostPosted: Sat Feb 09, 2008 3:45 pm 
Beginner
Beginner

Joined: Fri Oct 27, 2006 3:35 pm
Posts: 21
Hi All,

I'm looking for a way to make Hibernate Search bring results back ordered by "relevance". Relevance is subjective, so I want to be able to configure either the index building or the actual searching so that results are ordered in a way that makes sense to users. It'll probably help at this point if I explain a little about what I'm doing...

I am writing a web app that represents a flexible online shop. The object model consists of Products belonging to Categories. Categories have relevant configurable attributes (stored in Set<CategoryAttribute>), and Products belonging to a Category must provide values for these attributes (stored as member of Product - Set<ProductCategoryAttribute>).

For example a "Books" Category might have the attributes "Author" and "Title" and a Product belonging to the "Books" Category might provide the values "Shakespeare" and "Hamlet" for these attributes respectively. Fairly standard pattern really, so I won't bore you with any more of the details!

I want to be able to configure the weighting that Hibernate Search applies to each of these attributes, such that hits with a search term found in their "Title" attribute (for instance) appear closer to the top of the search results than hits containing this term in their "Description" attribute (again, for instance).

I've seen in the documentation that it's possible to add a 'boost' to properties of an indexed class, but that's not quite what I'm looking for. I need some way of applying a boost to an arbitrary ProductCategoryAttribute contained in a collection belonging to Product. Anyone got any ideas? Would I need to build the index in such a way that the desired biases are taken into account? Or could this weighting be incorporated at "search time"? I'm guessing I would need to do this at index building time, but it's not clear to me exactly how I would go about doing this.

Thanks for taking the time to read this rather lengthy message - any feedback would be much appreciated!

Cheers,
Richard.

Hibernate version: Hibernate: 3.2.3 / Hibernate Search: 3.0.0 GA


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 11, 2008 5:04 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Just to brainstorm a little. One option you could investigate is query time boosting. As you said Hibernate Search allows index time boosting via annotation. However, in your case you probably could work with search time boosts. As you construct your Lucene Query you can apply a boost for each field you include into the search. Check the Lucene API (http://hudson.zones.apache.org/hudson/job/Lucene-trunk/javadoc//org/apache/lucene/search/Query.html).

Alternatively you could implement the SortComparatorSource interface (http://hudson.zones.apache.org/hudson/job/Lucene-trunk/javadoc//org/apache/lucene/search/SortComparatorSource.html). I've used this approach myself before and it worked very well. "Lucene in Action" contains some example code on how to do this.

I hope this helps you getting onto the right track :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 11, 2008 7:40 pm 
Beginner
Beginner

Joined: Fri Oct 27, 2006 3:35 pm
Posts: 21
Hi Hardy,

Thanks for your reply. I did come up with a solution to the problem in the end - I implemented a FieldBridge for the Set of ProductCategoryAttributes inside Product - so for every Product that Lucene indexes, my FieldBridge gets passed a Set<ProductCategoryAttribute>. Inside the 'set' method of my FieldBridge I just iterate over the ProductCategoryAttributes and apply boosts to each field as appropriate.

The downside of this is that if you want to change the search weights you need to rebuild the index, so I think I'm going to investigate your suggestion about boosting at search time.

Cheers,
Richard.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 19, 2008 7:57 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I think the best approach is to mix both ideas.
You need a custom fieldbridge to index your collection in a "smart" way
lets say, index the title ProductCategoryAttribute in a special subfield "attributes.title" ; index the description ProductCategoryAttribute in a special subfield "attributes.description"

From here you can build a query that put more weight on attributes.title and less on attributes.description at runtime. No need to reindex when you want to change the boost factor.

_________________
Emmanuel


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