-->
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.  [ 1 post ] 
Author Message
 Post subject: Using Hibernate Search with MultiFieldQueryParser
PostPosted: Wed Sep 10, 2008 9:29 pm 
Newbie

Joined: Wed Sep 10, 2008 9:10 pm
Posts: 3
Hi, Everyone,
I begin to use Hibernate Search these days and it's really a great tool. And I have some questions for the usage of it:

I have two indexed entities in my project: Clazz and Registrations. A Registration must belong to one Clazz. And a Clazz contains zero or more Registrations. And this relationship also mapped in hibernate search:

Code:
@Entity
@Indexed
public class Clazz {

   @Id
   @DocumentId
   @GeneratedValue(generator = "hibernate-uuid.hex")
   @GenericGenerator(name = "hibernate-uuid.hex", strategy = "uuid.hex")
   private String id;

   @Field(index = Index.TOKENIZED, store = Store.YES)
   private String clazzName;

   @OneToMany(mappedBy = "clazz", fetch = FetchType.EAGER)
   @OrderBy(clause = "username asc")
   @ContainedIn
   private Set<Registration> registrations = new HashSet<Registration>();
...


and

Code:
@Entity
@Indexed
public class Registration {

   @Id
   @DocumentId
   @GeneratedValue(generator = "hibernate-uuid.hex")
   @GenericGenerator(name = "hibernate-uuid.hex", strategy = "uuid.hex")
   private String id;

...

   @ManyToOne(fetch = FetchType.EAGER)
   @JoinColumn(name = "clazz_id", nullable = false)
   @IndexedEmbedded(prefix="inClazz_")
   private Clazz clazz;
...


and the embedded object can be successfully searched by "+inClazz_clazzName:xxx "

It's perfect and nothing wrong. But what makes me confused is, that I'm using lucene's MultiFieldQueryParser to do the search:

Code:
   @Transactional(readOnly = true)
   public List search(final String keyword) {
      return getJpaTemplate().executeFind(new JpaCallback() {
         public Object doInJpa(EntityManager entityManager) {
            FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search
                  .createFullTextEntityManager(entityManager);
            MultiFieldQueryParser parser = new MultiFieldQueryParser(
                  new String[] { "id", "username" },
                  new StandardAnalyzer());
            org.apache.lucene.search.Query query;
            try {
               query = parser.parse(keyword);
               return fullTextEntityManager.createFullTextQuery(query,
                     Registration.class).getResultList();
            } catch (ParseException e) {
               e.printStackTrace();
               return null;
            }
         }
      });
   }


please note that I just assign two fields for search in MultiFieldQueryParser: "id" and "username" and there's no "clazz" in it.

But why the search like 'inClazz_clazzName" still works? I've also checked the doc of Lucene but don't have much idea on it.

I'm a newbie to Lucene and Hibernate Search. I'm not sure whether is proper to post this question here or maybe in Lucene forum. Can anyone help me? Thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.