-->
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: dynamic boost
PostPosted: Tue Dec 16, 2008 7:32 pm 
Newbie

Joined: Tue Dec 16, 2008 7:15 pm
Posts: 3
Hi,

I have gone through all the thread until now, but I haven't found how to solve my problem. I have boost values for each record to be indexed in a mysql table. When I perform indexing using
Code:
fulltextsession.index()
, I want these boost values read from the table and added to the document. I am looking to do a document.setBoost() . My class implements LuceneOptions and implements the getBoost() method . The getBoost() receives value from the db table. Will this work ?

I also have Document id which has a Fieldbridge implementing a TwoWayFieldBridge, but the LuceneOptions here are being read from LuceneOptionImpl class and not from my class which implements LuceneOptions.
Code:

@FieldBridge(impl = CompositeIdBridge.class)
@DocumentId
private Id id;



I am guessing that is coming from

Code:
DocumentBuilderContainedEntity.getBoost(XProperty member, org.hibernate.search.annotations.Field fieldAnn)


Is there any other way to do this ?

Kindly advise, I am very new to Hibernate Search , hence need some direction
[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2008 12:34 pm 
Hibernate Team
Hibernate Team

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

I am not quite sure what you mean with "My class implements LuceneOptions". If you are saying that the entity you are trying to index implements LuceneOptions than it will not work. LuceneOptions is not an extension point of Search.

I guess one could achieve what you are after by implementing a ClassBridge. Using a ClassBridge will give you access to the entity to be indexed as well as the document. You have full control on which fields to index and how to boost them.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2008 12:43 pm 
Newbie

Joined: Tue Dec 16, 2008 7:15 pm
Posts: 3
Thanks for the reply Hardy. Yeah I meant the entity I am trying to index implements the Lucene Options. Ok so that can't be done.

I know this might be a very basic question, but I do have confusion as to how to use the ClassBridge for Boost values. Boost value can be set through annotation only like @Boost , how do I assign it a dynamic value being read from the db at indexing time.

I need to do something like

Code:

  public void setBoost()
   {
     boost = entity.getBoost();
   }


Any help is much appreciated


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2008 1:16 pm 
Newbie

Joined: Tue Dec 16, 2008 7:15 pm
Posts: 3
I think I know what to do, just posting it incase someone wants to do something similar

Code:

@ClassBridge(
index=Index.TOKENIZED,
store=Store.YES,
impl = DocumentClassBridge.class
)
public class MyClass
{

  private Float valFromDB;
...

  public Float getBoostValue()
  {
      return valFromDB;
  }
}

public class DocumentClassBridge implements FieldBridge
{

   

   public void set(String name, Object value, Document document, LuceneOptions arg3)
   {
         document.setBoost( ( (MyClass)value ).getBoostValue() );
         
            
   }
}



Top
 Profile  
 
 Post subject: Hi.
PostPosted: Wed Mar 11, 2009 3:49 pm 
Newbie

Joined: Mon Apr 21, 2008 3:27 pm
Posts: 5
I need some help whit this.

I have a document, like this:

Code:
@Indexed
public class Item implements Serializable, Comparable<Item> {

    @DocumentId
    private Long id;

    @Boost(2)
    @Field(analyzer = @Analyzer(impl=SimpleAnalyzer.class), index = Index.TOKENIZED)
    private String name;

    @IndexedEmbedded(depth = 2)
    private Set<ItemDescription> descriptions;

    private Float popularity;

}


I wanna ad the popularity of the item to de boost factor... How can i do this?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 12, 2009 7:45 am 
Hibernate Team
Hibernate Team

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

I think the easiest would be to implement a ClassBridge. Using a ClassBridge will give you access to all properties of your class while adding Fields to the Lucene document.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 12, 2009 8:54 am 
Newbie

Joined: Mon Apr 21, 2008 3:27 pm
Posts: 5
I do something like this:
Code:
public class ItemPopularityBridge extends DefaultHandler implements FieldBridge {
   
    private void set(String name, Object value, Document document, LuceneOptions options) {
        Item item = (Item)value;
        float boost = 1f + item.getPopularity();
        document.setBoost(boost);
    }
}

Thanks. :-)


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.