Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top