I am working on a search engine created in Lucene 5.2.1, but I am having problems with the "Sort updates" option for the search. When searching with the Sort option, an error appears:
Exception in thread "main" java.lang.IllegalStateException: unexpected docvalues NONE for the 'stars' fields (expected = NUMERIC). Use a UninvertingReader or index with docvalues.
at org.apache.lucene.index.DocValues.checkField (DocValues.java:208)
at org.apache.lucene.index.DocValues.getNumeric (DocValues.java:227)
at org.apache.lucene.search.FieldComparator $ NumericCompapa .getNumericDocValues (FieldComparator.java:167)
at org.apache.lucene.search.FieldComparator $ NumericComparator.doSetNextReader (FieldComparator.java:153)
at org.apache.lucene.search.SimpleFieldComparator.getLeafComparator Simple )
on 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.secse.secse.secse.secse.sec .search (IndexSearcher.java:485)
on org.apache.lucene.search.IndexSearcher.search (IndexSearcher.java:694)
on org.apache.lucene.search.IndexSearcher.searchAfter (IndexSearcher.java:679)
on org. apache.lucene.search.IndexSearcher.searchAfter (IndexSearcher.java:621)
at org.apache.lucene.search.IndexSearcher.search (IndexSearcher.java∗27)
at org.apache.lucene.search.IndexSearcher.search (IndexSearcher. java: 577)
on SearchEngine.searchBusinessByCategory (SearchEngine.java:145)
in Tests.searchEngineTest (Tests.java:137)
on Main.main (Main.java:13)
I indexed a document that contains a double “star” field, which I need to use to sort the search results (the document with the highest “star” value should be on top).
Document doc = new Document();
doc.add(new DoubleField("stars", stars, Store.YES));
Then I applied the "Search" command with the "Sort" option in the "star" field as follows:
SortField sortfield = new SortField("stars", SortField.Type.DOUBLE, true);
Sort sort = new Sort(sortfield);
mySearcher.search(query, maxdocs, sort);
I found similar discussions on the Internet, but they all talk about SolR (or sometimes Elastic Search), but they don't provide either a Lucene snippet or a more general solution strategy for Lucene 5. For example:
Solr DocValues UninvertingReader, ( ). DocValues , . ( h ttp://grokbase.com/t/lucene/java-user/152q2jcgzz/lucene-4-x-5-illegalstateexception-while-sorting)
, - UninvertingReader DocValues. ?