I have the following query set up and it is working. However, I cannot get the sort to work. I have basic questions, such as, should I be able to sort across all classes such that I truly see output in title order? I want to order by title first, not title within bestPractices and title within caseSummaries.
Code:
private static List<KnowledgeArticle> searchKnowledgeArticles(String queryString) {
Session session = HibernateUtil.getSession();
FullTextSession fullTextSession = Search.getFullTextSession(session);
QueryBuilder queryBuilder = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(KnowledgeArticle.class).get();
org.apache.lucene.search.Query luceneQuery = queryBuilder.keyword()
.fuzzy()
.withThreshold( .8f )
.withPrefixLength( 1 )
.onFields("articleNumber","bestPractices.title","caseSummaries.title","bestPractices.summary","caseSummaries.summary","caseSummaries.resolution","bestPractices.bestPractice").matching(queryString).createQuery();
// wrap Lucene query in a javax.persistence.Query
org.hibernate.search.FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(luceneQuery, KnowledgeArticle.class, BestPractice.class, CaseSummary.class);
/* org.apache.lucene.search.Sort sort = new Sort(
new SortField("bestPractices.title", SortField.STRING));
fullTextQuery.setSort(sort);*/