LUCENE-2148: Fix best fit bug

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@928860 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Grant Ingersoll 2010-03-29 18:40:21 +00:00
parent 1602a0cf90
commit 61b781d376
4 changed files with 36 additions and 13 deletions

View File

@ -57,6 +57,9 @@ Bug fixes
* LUCENE-2277: QueryNodeImpl threw ConcurrentModificationException on
add(List<QueryNode>). (Frank Wesemann via Robert Muir)
* LUCENE-2184: Fixed bug with handling best fit value when the proper best fit value is
not an indexed field. Note, this change affects the APIs. (Grant Ingersoll)
API Changes

View File

@ -44,9 +44,18 @@ public class CartesianPolyFilterBuilder {
private IProjector projector = new SinusoidalProjector();
private final String tierPrefix;
public CartesianPolyFilterBuilder( String tierPrefix ) {
private int minTier;
private int maxTier;
/**
*
* @param tierPrefix The prefix for the name of the fields containing the tier info
* @param minTierIndexed The minimum tier level indexed
* @param maxTierIndexed The maximum tier level indexed
*/
public CartesianPolyFilterBuilder( String tierPrefix, int minTierIndexed, int maxTierIndexed ) {
this.tierPrefix = tierPrefix;
this.minTier = minTierIndexed;
this.maxTier = maxTierIndexed;
}
public Shape getBoxShape(double latitude, double longitude, double miles)
@ -77,6 +86,11 @@ public class CartesianPolyFilterBuilder {
//System.err.println("getBoxShape:"+latX+"," + longX);
CartesianTierPlotter ctp = new CartesianTierPlotter(2, projector,tierPrefix);
int bestFit = ctp.bestFit(miles);
if (bestFit < minTier){
bestFit = minTier;
} else if (bestFit > maxTier){
bestFit = maxTier;
}
ctp = new CartesianTierPlotter(bestFit, projector,tierPrefix);
Shape shape = new Shape(ctp.getTierFieldName());

View File

@ -44,18 +44,24 @@ public class DistanceQueryBuilder {
* a boundary box wrapper around a more precise
* DistanceFilter.
*
* @param lat
* @param lng
* @param miles
* @param lat The latitude to search around
* @param lng the Longitude to search around
* @param miles The radius to search within
* @param latField The name of the field containing the latitude
* @param lngField The name of the field containing the longitude
* @param tierFieldPrefix The prefix of the tier
* @param needPrecise if true, then distance is calculated in addition to tier info
* @param minTierIndexed The minimum tier level indexed
* @param maxTierIndexed The maximum tier level indexed
*/
public DistanceQueryBuilder (double lat, double lng, double miles,
String latField, String lngField, String tierFieldPrefix, boolean needPrecise) {
String latField, String lngField, String tierFieldPrefix, boolean needPrecise, int minTierIndexed, int maxTierIndexed) {
this.lat = lat;
this.lng = lng;
this.miles = miles;
CartesianPolyFilterBuilder cpf = new CartesianPolyFilterBuilder(tierFieldPrefix);
CartesianPolyFilterBuilder cpf = new CartesianPolyFilterBuilder(tierFieldPrefix, minTierIndexed, maxTierIndexed);
Filter cartesianFilter = cpf.getBoundingArea(lat, lng, miles);
/* create precise distance filter */
@ -77,13 +83,13 @@ public class DistanceQueryBuilder {
* @param miles
*/
public DistanceQueryBuilder (double lat, double lng, double miles,
String geoHashFieldPrefix, String tierFieldPrefix, boolean needPrecise){
String geoHashFieldPrefix, String tierFieldPrefix, boolean needPrecise, int minTierIndexed, int maxTierIndexed){
this.lat = lat;
this.lng = lng;
this.miles = miles;
CartesianPolyFilterBuilder cpf = new CartesianPolyFilterBuilder(tierFieldPrefix);
CartesianPolyFilterBuilder cpf = new CartesianPolyFilterBuilder(tierFieldPrefix, minTierIndexed, maxTierIndexed);
Filter cartesianFilter = cpf.getBoundingArea(lat, lng, miles);
/* create precise distance filter */

View File

@ -175,7 +175,7 @@ public class TestCartesian extends LuceneTestCase {
if (VERBOSE) System.out.println("testAntiM");
// create a distance query
final DistanceQueryBuilder dq = new DistanceQueryBuilder(lat, lng, miles,
latField, lngField, CartesianTierPlotter.DEFALT_FIELD_PREFIX, true);
latField, lngField, CartesianTierPlotter.DEFALT_FIELD_PREFIX, true, 2, 15);
if (VERBOSE) System.out.println(dq);
//create a term query to search against all documents
@ -270,7 +270,7 @@ public class TestCartesian extends LuceneTestCase {
// create a distance query
final DistanceQueryBuilder dq = new DistanceQueryBuilder(lat, lng, miles,
latField, lngField, CartesianTierPlotter.DEFALT_FIELD_PREFIX, true);
latField, lngField, CartesianTierPlotter.DEFALT_FIELD_PREFIX, true, 2, 15);
if (VERBOSE) System.out.println(dq);
//create a term query to search against all documents
@ -367,7 +367,7 @@ public class TestCartesian extends LuceneTestCase {
// create a distance query
final DistanceQueryBuilder dq = new DistanceQueryBuilder(lat, lng, miles,
latField, lngField, CartesianTierPlotter.DEFALT_FIELD_PREFIX, true);
latField, lngField, CartesianTierPlotter.DEFALT_FIELD_PREFIX, true, 2, 15);
if (VERBOSE) System.out.println(dq);
//create a term query to search against all documents
@ -462,7 +462,7 @@ public class TestCartesian extends LuceneTestCase {
// create a distance query
final DistanceQueryBuilder dq = new DistanceQueryBuilder(lat, lng, miles,
geoHashPrefix, CartesianTierPlotter.DEFALT_FIELD_PREFIX, true);
geoHashPrefix, CartesianTierPlotter.DEFALT_FIELD_PREFIX, true, 2, 15);
if (VERBOSE) System.out.println(dq);
//create a term query to search against all documents