1

I need to select only few columns using hibernate search. Following is the code which works fine

  FullTextSession fts = org.hibernate.search.Search.getFullTextSession(getSession());

  org.apache.lucene.search.BooleanQuery query = prepareQuery(dto);
  fullTextQuery = fts.createFullTextQuery(query, ProfileBean.class);

  fullTextQuery.setFirstResult(dto.getProfileBean().getResultStartIndex());
  fullTextQuery.setMaxResults(dto.getProfileBean().getResultsLimit());

  List<ProfileBean> profiles = fullTextQuery.list();

In the above case I only want to select columns 'firstName' and 'lastName'.

Following code throws an exception

 List<String> projectedFields = new ArrayList<String>();
          projectedFields.add("firstName");
          projectedFields.add("lastName");

org.hibernate.search.SearchException: Projecting an unstored field: firstName

actually i don't want to store the firstName field in lucene any other suggession.?

Sanne
  • 6,027
  • 19
  • 34
Ali
  • 43
  • 1
  • 18

1 Answers1

1

In your class ProfileBean, you'll need to add annotation:

@Field(store=Store.YES)

to fields firstname, lastname

Please find section 5.1.2.5. Projection in Hibernate documentation for details: https://docs.jboss.org/hibernate/search/3.2/reference/en/html/search-query.html#d0e3643

Happy coding!

Ivar
  • 6,138
  • 12
  • 49
  • 61