-->
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: Searching Properties/HashMap field
PostPosted: Thu Nov 12, 2009 6:21 am 
Newbie

Joined: Thu Nov 12, 2009 6:09 am
Posts: 4
HI,

I have an entity class with java.util.Properties field which I am persisting. I am wondering if there is anyway I can search the value of the field using Hibernate Search or Apache Lucene.

Below is the code I am using to search field types, but It doesn't work with java.util.Properties fields.

Code:
   private FullTextQuery searchQuery(String searchQuery, String[] columns) {
      // lucene part
      Map<String, Float> boostPerField = new HashMap<String, Float>(2);
      boostPerField.put(columns[0], (float) 4);
      boostPerField.put(columns[1], (float) 3);

      FullTextSession ftEm = org.hibernate.search.Search
            .getFullTextSession(sessionFactory.getCurrentSession());

      QueryParser parser = new MultiFieldQueryParser(columns, ftEm
            .getSearchFactory().getAnalyzer("customanalyzer"),
            boostPerField);

      org.apache.lucene.search.Query luceneQuery = null;
      try {
         luceneQuery = parser.parse(searchQuery);
      } catch (ParseException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
         return null;
      }

      final FullTextQuery query = ftEm.createFullTextQuery(luceneQuery,
            persistentClass);

      return query;
   }


Thank in advance


Top
 Profile  
 
 Post subject: Re: Searching Properties/HashMap field
PostPosted: Thu Nov 12, 2009 6:32 am 
Hibernate Team
Hibernate Team

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

more interesting than the search code would be how you try to index the Properties field? You will need a custom FieldBridge. Have you already implemented one?
Maybe you can port the annotated entity code.

--Hardy


Top
 Profile  
 
 Post subject: Re: Searching Properties/HashMap field
PostPosted: Thu Nov 12, 2009 9:26 am 
Newbie

Joined: Thu Nov 12, 2009 6:09 am
Posts: 4
Hardy,

Thanks for pointing me where to check, yes, I wasn't actually doing the right FieldBridge

Indexing:
Code:
   @Field(index = Index.TOKENIZED)
   @FieldBridge(impl = CustomPropertyBridge.class)
   private Properties partnerSpec;


CustomPropertyBridge:

Code:
public class CustomPropertyBridge implements FieldBridge {

   /*
    * (non-Javadoc)
    *
    * @see org.hibernate.search.bridge.FieldBridge#set(java.lang.String,
    * java.lang.Object, org.apache.lucene.document.Document,
    * org.hibernate.search.bridge.LuceneOptions)
    */
   public void set(String name, Object value, Document document,
         LuceneOptions luceneOptions) {
      String fieldValue = "";
      Properties properties = (Properties) value;
      Enumeration<?> propertyValues = properties.elements();
      while (propertyValues.hasMoreElements()) {
         String v = (String) propertyValues.nextElement();
         fieldValue += v + " ";
      }
      Field field = new Field(name, fieldValue, luceneOptions.getStore(),
            luceneOptions.getIndex(), luceneOptions.getTermVector());
      field.setBoost(luceneOptions.getBoost());
      document.add(field);

   }

}


again, thanks


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.