tags:

views:

812

answers:

1

Hi all,

I am using Hibernate - Lucene Search.

I have the following Runtime Exception while sorting when no data available in index file/table.

This is my code:

.......... .......... query.setFirstResult(startIndex); query.setMaxResults(displayCount);

              Sort sort = null;
      SortField sortField = new SortField**("vendorName",!true);
      sort = new Sort(sortField);
      query.setSort(sort);

      objList = query.setProjection(searchFields).setResultTransformer(objSavantAliasToBeanResultTransformer).list();

........ ........

java.lang.RuntimeException: no terms in field vendorName - cannot determine sort type at org.apache.lucene.search.ExtendedFieldCacheImpl$5.createValue(ExtendedFieldCacheImpl.java:139) at org.apache.lucene.search.FieldCacheImpl$Cache.get(FieldCacheImpl.java:71) at org.apache.lucene.search.ExtendedFieldCacheImpl.getAuto(ExtendedFieldCacheImpl.java:127) at org.apache.lucene.search.FieldSortedHitQueue.comparatorAuto(FieldSortedHitQueue.java:487) at org.apache.lucene.search.FieldSortedHitQueue$1.createValue(FieldSortedHitQueue.java:184) at org.apache.lucene.search.FieldCacheImpl$Cache.get(FieldCacheImpl.java:71) at org.apache.lucene.search.FieldSortedHitQueue.getCachedComparator(FieldSortedHitQueue.java:167) at org.apache.lucene.search.FieldSortedHitQueue.(FieldSortedHitQueue.java:55) at org.apache.lucene.search.TopFieldDocCollector.(TopFieldDocCollector.java:43) at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:121) at org.apache.lucene.search.Searcher.search(Searcher.java:86) at org.hibernate.search.query.QueryHits.updateTopDocs(QueryHits.java:103) at org.hibernate.search.query.QueryHits.(QueryHits.java:61) at org.hibernate.search.query.FullTextQueryImpl.getQueryHits(FullTextQueryImpl.java:354) at org.hibernate.search.query.FullTextQueryImpl.list(FullTextQueryImpl.java:270) at com.tis.purchasedetails.dao.PurchaseDetailsDAO.getAllPurchaseDetails(PurchaseDetailsDAO.java:1025) at org.apache.jsp.jsp.PurchaseDetails.purchaseDetailsList_jsp._jspService(purchaseDetailsList_jsp.java:275) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672) at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:463) at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:398)

A: 

You have to use a different SortField constructor. Use the one where you specify also the type. See also https://issues.apache.org/jira/browse/LUCENE-1729

Hardy