-->
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: Hibernate-Search - Searching from any indexed entity
PostPosted: Mon Apr 22, 2013 6:54 am 
Newbie

Joined: Mon Apr 22, 2013 6:52 am
Posts: 1
The same question as I have posted to SO: http://stackoverflow.com/questions/16143167/hibernate-search-search-from-any-indexed-entity ...

I am using Hibernate-search for searching data in my Jboss application. I have 3 JPA entity classes that all extend BaseEntity class and each are indexed by Lucene. For example:
Code:
@MappedSuperclass
public abstract class BaseEntity implements Serializable {
    @Temporal(TemporalType.TIMESTAMP)
    private Date created;
    public abstract Long getId();
}

@Entity
@Table(name = "DVD")
public class Dvd extends BaseEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @Field
    private String title;
}

@Entity
@Table(name = "BOOK")
public class Book extends BaseEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @Field
    private String author;
}


Now I would like to search for either DVD title or Book author by wildcard search query and get the result list as List. This is what I have this far:

Code:
public List<BaseEntity> search(String query, int firstResult, int maxResults) {
    List<BaseEntity> results = null;
    FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(em);
    Query luceneQuery = new WildcardQuery(new Term("*", "*" + query + "*"));
    FullTextQuery fullTextQuery = fullTextEntityManager.createFullTextQuery(luceneQuery, BaseEntity.class);
    fullTextQuery.setFirstResult(firstResult);
    fullTextQuery.setMaxResults(maxResults);
    results = fullTextQuery.getResultList();
    return results;
}


But with this I am not getting any results. How is it possible to get this to work or is there even way without using buildQueryBuilder for each entity? 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.