-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to index field with comma-separated text value?
PostPosted: Sat Apr 28, 2012 2:08 pm 
Beginner
Beginner

Joined: Mon Oct 27, 2008 6:26 am
Posts: 36
I am implementing a book search function based on hibernate search3.2.

Book object contains a field called authornames. Authornames value is a list of names and comma is the splitter, say "John Will, Robin Rod, James Timerberland"

@Field(index = org.hibernate.search.annotations.Index.UN_TOKENIZED,store=Store.YES)
@FieldBridge(impl=CollectionToCSVBridge.class)
private Set<String> authornames;

I need each of names to be UN_TOKENIZED, so that user search book by single author name: John Will, Robin Rod or James Timerberland.

I used Luke to check indexs, and value in authornames field is stored as "John Will, Robin Rod, James Timerberland", but I can not get result by querying "authornames:John Will"

Anybody can tell me how can I do it?


Top
 Profile  
 
 Post subject: Re: How to index field with comma-separated text value?
PostPosted: Wed May 02, 2012 1:05 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
sorry for the delay. Just implement a FieldBridge which adds each element separately, not using commas to concatenate the string:

Code:
@Override
   public void set(String name, Object value, Document document, LuceneOptions luceneOptions) {
      if ( value == null ) {
         return;
      }
      if ( !( value instanceof Collection ) ) {
         throw new IllegalArgumentException( "This FieldBridge only supports collections." );
      }
      Collection<?> objects = (Collection<?>) value;

      for ( Object object : objects ) {
         luceneOptions.addFieldToDocument( name, objectToString( object ), document ); //objectToString depends on your type..
      }
   }

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: How to index field with comma-separated text value?
PostPosted: Wed May 02, 2012 1:09 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Also found on StackOverflow: http://stackoverflow.com/questions/1036 ... 1#10418471

_________________
Sanne
http://in.relation.to/


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