3

I have two entities Restaurant and Category, related by a many-to-many relation. I want to search a restaurant by category_name but i am not able to get correct results for my search, even though I can see that list is being populated correctly with the data. The entities are:

@Entity
@Table(name = "restaurant")
@Indexed
public class Restaurant implements Comparable<Restaurant> {
    @ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    @JoinTable(name = "restaurant_category", joinColumns = { @JoinColumn(name = "restaurant_id", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "category_id", nullable = false, updatable = false) })
    @IndexedEmbedded
    private List<Category> listOfCategories;
}

This is the category entity

 @Entity
 @Table(name = "category")
 @Indexed
 public class Category {

 @Column(name = "category_name")
 @Field(index = Index.YES, analyze = Analyze.YES, store = Store.NO)
 private String categoryName;

and this my search query

Query query = queryBuilder.keyword()
            .onFields("listOfCategories.categoryName").matching("Pub")
            .createQuery();


    org.hibernate.Query hibernateQuery = fullTextSession
            .createFullTextQuery(query, Restaurant.class);

    List<Restaurant> searchResults = hibernateQuery.list();

Thanks in Advance!

Hardy
  • 18,659
  • 3
  • 49
  • 65
Android Mason
  • 459
  • 1
  • 6
  • 17
  • Can you describe what results you are getting and what you would expect? With an example? The code itself looks ok. – Hardy Jul 23 '15 at 08:19
  • @Hardy I am getting empty list always, although 'pub' keyword exists in category_name in the DB. – Android Mason Jul 23 '15 at 15:45
  • 1
    You say that the pub keyword exists in the database, but does it also exist in the Lucene index? Did you build the Lucene index (by either inserting some test entities and relying on auto-indexing or by using the explicit indexing API?) If you have an index, have you inspected it with Luke in order to verify the indexed terms? – Hardy Jul 24 '15 at 08:08

0 Answers0