We're updating the issue view to help you get more done. 

Improve resulting error message when applying the wrong Sort Type

Description

When using Lucene's SortField.Type.INT to sort on a field which was not indexed as a NumericField, the resulting error message is confusing:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 java.lang.IllegalStateException: Type mismatch: ageForIntSorting was indexed with multiple values per document, use SORTED_SET instead at org.apache.lucene.uninverting.FieldCacheImpl$SortedDocValuesCache.createValue(FieldCacheImpl.java:679) at org.apache.lucene.uninverting.FieldCacheImpl$Cache.get(FieldCacheImpl.java:190) at org.apache.lucene.uninverting.FieldCacheImpl.getTermsIndex(FieldCacheImpl.java:647) at org.apache.lucene.uninverting.FieldCacheImpl.getTermsIndex(FieldCacheImpl.java:627) at org.apache.lucene.uninverting.UninvertingReader.getSortedDocValues(UninvertingReader.java:257) at org.apache.lucene.index.DocValues.getSorted(DocValues.java:262) at org.apache.lucene.search.FieldComparator$TermOrdValComparator.getSortedDocValues(FieldComparator.java:757) at org.apache.lucene.search.FieldComparator$TermOrdValComparator.getLeafComparator(FieldComparator.java:762) at org.apache.lucene.search.FieldValueHitQueue.getComparators(FieldValueHitQueue.java:183) at org.apache.lucene.search.TopFieldCollector$NonScoringCollector.getLeafCollector(TopFieldCollector.java:141) at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:762) at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:485) at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:473) at org.hibernate.search.query.engine.impl.LazyQueryState.search(LazyQueryState.java:100) at org.hibernate.search.query.engine.impl.QueryHits.updateTopDocs(QueryHits.java:250) at org.hibernate.search.query.engine.impl.QueryHits.<init>(QueryHits.java:145) at org.hibernate.search.query.engine.impl.QueryHits.<init>(QueryHits.java:123) at org.hibernate.search.query.engine.impl.HSQueryImpl.getQueryHits(HSQueryImpl.java:447) at org.hibernate.search.query.engine.impl.HSQueryImpl.queryEntityInfos(HSQueryImpl.java:268)

Wondering if we could improve on that, as this might be a migration issue: it seems previously - before Lucene 5 - this was more lenient (probably gave the wrong sort order, but it would not throw an exception).

A starting point it the test org.hibernate.search.test.sorting.SortingTest (about to be committed).

The opposite problem will result in something like:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 java.lang.IllegalStateException: Type mismatch: age was indexed with multiple values per document, use SORTED_SET instead at org.apache.lucene.uninverting.FieldCacheImpl$SortedDocValuesCache.createValue(FieldCacheImpl.java:679) ~[lucene-misc-5.2.1.jar:5.2.1 1684708 - shalin - 2015-06-10 23:11:46] at org.apache.lucene.uninverting.FieldCacheImpl$Cache.get(FieldCacheImpl.java:190) ~[lucene-misc-5.2.1.jar:5.2.1 1684708 - shalin - 2015-06-10 23:11:46] at org.apache.lucene.uninverting.FieldCacheImpl.getTermsIndex(FieldCacheImpl.java:647) ~[lucene-misc-5.2.1.jar:5.2.1 1684708 - shalin - 2015-06-10 23:11:46] at org.apache.lucene.uninverting.FieldCacheImpl.getTermsIndex(FieldCacheImpl.java:627) ~[lucene-misc-5.2.1.jar:5.2.1 1684708 - shalin - 2015-06-10 23:11:46] at org.apache.lucene.uninverting.UninvertingReader.getSortedDocValues(UninvertingReader.java:257) ~[lucene-misc-5.2.1.jar:5.2.1 1684708 - shalin - 2015-06-10 23:11:46] at org.apache.lucene.index.DocValues.getSorted(DocValues.java:262) ~[lucene-core-5.2.1.jar:5.2.1 1684708 - shalin - 2015-06-10 23:11:06] at org.apache.lucene.search.FieldComparator$TermOrdValComparator.getSortedDocValues(FieldComparator.java:757) ~[lucene-core-5.2.1.jar:5.2.1 1684708 - shalin - 2015-06-10 23:11:06] at org.apache.lucene.search.FieldComparator$TermOrdValComparator.getLeafComparator(FieldComparator.java:762) ~[lucene-core-5.2.1.jar:5.2.1 1684708 - shalin - 2015-06-10 23:11:06] at org.apache.lucene.search.FieldValueHitQueue.getComparators(FieldValueHitQueue.java:183) ~[lucene-core-5.2.1.jar:5.2.1 1684708 - shalin - 2015-06-10 23:11:06] at org.apache.lucene.search.TopFieldCollector$NonScoringCollector.getLeafCollector(TopFieldCollector.java:141) ~[lucene-core-5.2.1.jar:5.2.1 1684708 - shalin - 2015-06-10 23:11:06] at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:762) ~[lucene-core-5.2.1.jar:5.2.1 1684708 - shalin - 2015-06-10 23:11:06] at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:485) ~[lucene-core-5.2.1.jar:5.2.1 1684708 - shalin - 2015-06-10 23:11:06] at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:473) ~[lucene-core-5.2.1.jar:5.2.1 1684708 - shalin - 2015-06-10 23:11:06] at org.hibernate.search.query.engine.impl.LazyQueryState.search(LazyQueryState.java:100) ~[hibernate-search-engine-5.5.0-SNAPSHOT.jar:5.5.0-SNAPSHOT] at org.hibernate.search.query.engine.impl.QueryHits.updateTopDocs(QueryHits.java:250) ~[hibernate-search-engine-5.5.0-SNAPSHOT.jar:5.5.0-SNAPSHOT] at org.hibernate.search.query.engine.impl.QueryHits.<init>(QueryHits.java:145) ~[hibernate-search-engine-5.5.0-SNAPSHOT.jar:5.5.0-SNAPSHOT] at org.hibernate.search.query.engine.impl.QueryHits.<init>(QueryHits.java:114) ~[hibernate-search-engine-5.5.0-SNAPSHOT.jar:5.5.0-SNAPSHOT] at org.hibernate.search.query.engine.impl.HSQueryImpl.getQueryHits(HSQueryImpl.java:452) ~[hibernate-search-engine-5.5.0-SNAPSHOT.jar:5.5.0-SNAPSHOT] at org.hibernate.search.query.engine.impl.HSQueryImpl.queryEntityInfos(HSQueryImpl.java:268) ~[hibernate-search-engine-5.5.0-SNAPSHOT.jar:5.5.0-SNAPSHOT]

I suspect in this case the field was indexed as NumericField, but it's being queried as SortField.Type.STRING

Environment

None

Status

Assignee

Davide D'Alto

Reporter

Sanne Grinovero

Labels

None

Suitable for new contributors

None

Feedback Requested

None

Fix versions

Priority

Major