문제

i dont understand how sort by distance has been achieved using below mentioned code.

Please explain me...how lucene handles sortfield if sortfield is ""?

   DistanceQueryBuilder queryBuilder = new DistanceQueryBuilder(latitude, longitude, radius, "lat", "lon", CartesianTierPlotter.DEFALT_FIELD_PREFIX, true);
   DistanceFieldComparatorSource distComp = new DistanceFieldComparatorSource(queryBuilder.getDistanceFilter());
   Sort distSort = new Sort(new SortField("", distComp,false));

EDIT1:

TopDocs topDocs = searcher.search(query, queryBuilder.getFilter(), 20,distSort);

PS: i am using lucene 3.0.3

도움이 되었습니까?

해결책

The SortField essentially is just going to pass the field name along to the Comparator, and let it handle getting the correct values and doing the comparison. As such, the DistanceFieldComparatorSource just tosses the field name out anyway. This makes a measure of sense, since that comparator needs to accesses two fields (lat and lon in this case) to perform its comparison, rather than just one.

Instead, the DistanceFilter wraps up the field names the comparator needs to access, as well as some other attendant data.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top