While Indexing, I am  storing the following fields:

                doc.add(new StoredField("latitude", latitude));
                doc.add(new StoredField("longitude", longitude));
                doc.add(new LatLonPoint("loc", latitude, longitude));

As suggested, I added the following code:
                Query latlonQuery = LatLonPoint.newDistanceQuery("loc", minLat, 
minLng,
50);
                Sort s = new Sort(LatLonDocValuesField.newDistanceSort("loc", 
minLat,
minLng));
                TopDocs docs = searcher.search(latlonQuery, 50, s);

But it threw exception:

Exception in thread "main" java.lang.IllegalStateException: unexpected
docvalues type NONE for field 'loc' (expected one of [SORTED_NUMERIC,
NUMERIC]). Re-index with correct docvalues type.
        at org.apache.lucene.index.DocValues.checkField(DocValues.java:212)
        at 
org.apache.lucene.index.DocValues.getSortedNumeric(DocValues.java:284)
        at
org.apache.lucene.document.LatLonPointDistanceComparator.getLeafComparator(LatLonPointDistanceComparator.java:163)
        at
org.apache.lucene.search.FieldValueHitQueue.getComparators(FieldValueHitQueue.java:180)
        at
org.apache.lucene.search.TopFieldCollector$SimpleFieldCollector.getLeafCollector(TopFieldCollector.java:100)
        at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:659)
        at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:472)
        at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:591)
        at
org.apache.lucene.search.IndexSearcher.searchAfter(IndexSearcher.java:576)
        at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:503)

Question is should I also store LatLonDocValuesField while Indexing?

                doc.add(new LatLonDocValuesField("loc", latitude, longitude));






--
View this message in context: 
http://lucene.472066.n3.nabble.com/Lucene-GeoNear-Search-and-Sort-Performance-tp4343468p4343978.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
For additional commands, e-mail: java-user-h...@lucene.apache.org

Reply via email to