i working on search engine built in lucene 5.2.1, having trouble sort updated option search. error while searching sort option:
exception in thread "main" java.lang.illegalstateexception: unexpected docvalues type none field 'stars' (expected=numeric). use uninvertingreader or index docvalues.
@ org.apache.lucene.index.docvalues.checkfield(docvalues.java:208)
@ org.apache.lucene.index.docvalues.getnumeric(docvalues.java:227)
@ org.apache.lucene.search.fieldcomparator$numericcomparator.getnumericdocvalues(fieldcomparator.java:167)
@ org.apache.lucene.search.fieldcomparator$numericcomparator.dosetnextreader(fieldcomparator.java:153)
@ org.apache.lucene.search.simplefieldcomparator.getleafcomparator(simplefieldcomparator.java:36)
@ org.apache.lucene.search.fieldvaluehitqueue.getcomparators(fieldvaluehitqueue.java:183)
@ org.apache.lucene.search.topfieldcollector$nonscoringcollector.getleafcollector(topfieldcollector.java:141)
@ org.apache.lucene.search.indexsearcher.search(indexsearcher.java:762)
@ org.apache.lucene.search.indexsearcher.search(indexsearcher.java:485)
@ org.apache.lucene.search.indexsearcher.search(indexsearcher.java:694)
@ org.apache.lucene.search.indexsearcher.searchafter(indexsearcher.java:679)
@ org.apache.lucene.search.indexsearcher.searchafter(indexsearcher.java:621)
@ org.apache.lucene.search.indexsearcher.search(indexsearcher.java:527)
@ org.apache.lucene.search.indexsearcher.search(indexsearcher.java:577)
@ searchengine.searchbusinessbycategory(searchengine.java:145)
@ tests.searchenginetest(tests.java:137)
@ main.main(main.java:13)
i have indexed document contains double field "stars" need use sort search results (the document highest "stars" value needs on top).
document doc = new document(); doc.add(new doublefield("stars", stars, store.yes)); then implemented search command sort option on "stars" field follows:
sortfield sortfield = new sortfield("stars", sortfield.type.double, true); sort sort = new sort(sortfield); mysearcher.search(query, maxdocs, sort); i have found similar discussions online talk solr (or elastic search) don't provide neither lucene snippet nor more general implementative solution strategy lucene 5. example:
solr uses docvalues , falls wrapping uninvertingreader, if user have not indexed them (with negative startup performance , memory effects). in general, should enable docvalues fields want sort on. (from http://grokbase.com/t/lucene/java-user/152q2jcgzz/lucene-4-x-5-illegalstateexception-while-sorting)
i see have uninvertingreader or docvalues. what?
you need define custom fieldtype since doublefield constructor using not store docvalues.
ex:
private static final fieldtype double_field_type_stored_sorted = new fieldtype(); static { double_field_type_stored_sorted.settokenized(true); double_field_type_stored_sorted.setomitnorms(true); double_field_type_stored_sorted.setindexoptions(indexoptions.docs); double_field_type_stored_sorted .setnumerictype(fieldtype.numerictype.double); double_field_type_stored_sorted.setstored(true); double_field_type_stored_sorted.setdocvaluestype(docvaluestype.numeric); double_field_type_stored_sorted.freeze(); } and add doc using:
document doc = new document(); doc.add(new doublefield("stars", stars, double_field_type_stored_sorted)); when use
new doublefield("stars", stars, stored.yes); you using fieldtype:
public static final fieldtype type_stored = new fieldtype(); static { type_stored.settokenized(true); type_stored.setomitnorms(true); type_stored.setindexoptions(indexoptions.docs); type_stored.setnumerictype(fieldtype.numerictype.double); type_stored.setstored(true); type_stored.freeze(); } which not have docvalues.
Comments
Post a Comment