You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@lucene.apache.org by mi...@apache.org on 2009/07/16 17:38:07 UTC
svn commit: r794721 - in /lucene/java/trunk: contrib/
contrib/spatial/src/java/org/apache/lucene/spatial/
contrib/spatial/src/java/org/apache/lucene/spatial/tier/
contrib/spatial/src/test/org/apache/lucene/spatial/tier/
src/java/org/apache/lucene/util/
Author: mikemccand
Date: Thu Jul 16 15:38:06 2009
New Revision: 794721
URL: http://svn.apache.org/viewvc?rev=794721&view=rev
Log:
LUCENE-1505: switch local lucene to use trie's NumericUtils for mapping doubles to strings
Removed:
lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/NumberUtils.java
Modified:
lucene/java/trunk/contrib/CHANGES.txt
lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/BoundaryBoxFilter.java
lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/CartesianShapeFilter.java
lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/LatLongDistanceFilter.java
lucene/java/trunk/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.java
lucene/java/trunk/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestDistance.java
lucene/java/trunk/src/java/org/apache/lucene/util/NumericUtils.java
Modified: lucene/java/trunk/contrib/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/CHANGES.txt?rev=794721&r1=794720&r2=794721&view=diff
==============================================================================
--- lucene/java/trunk/contrib/CHANGES.txt (original)
+++ lucene/java/trunk/contrib/CHANGES.txt Thu Jul 16 15:38:06 2009
@@ -4,7 +4,10 @@
Changes in runtime behavior
- (None)
+ 1. LUCENE-1505: Local lucene now uses org.apache.lucene.util.NumericUtils for all
+ number conversion. You'll need to fully re-index any previously created indexes.
+ This isn't a break in back-compatibility because local Lucene has not yet
+ been released. (Mike McCandless)
API Changes
Modified: lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/BoundaryBoxFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/BoundaryBoxFilter.java?rev=794721&r1=794720&r2=794721&view=diff
==============================================================================
--- lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/BoundaryBoxFilter.java (original)
+++ lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/BoundaryBoxFilter.java Thu Jul 16 15:38:06 2009
@@ -26,7 +26,7 @@
import org.apache.lucene.index.TermDocs;
import org.apache.lucene.index.TermEnum;
import org.apache.lucene.search.Filter;
-import org.apache.lucene.spatial.NumberUtils;
+import org.apache.lucene.util.NumericUtils;
@@ -158,11 +158,11 @@
buffer.append(":");
buffer.append(includeLower ? "[" : "{");
if (null != lowerTerm) {
- buffer.append(NumberUtils.SortableStr2double(lowerTerm));
+ buffer.append(NumericUtils.prefixCodedToDouble(lowerTerm));
}
buffer.append("-");
if (null != upperTerm) {
- buffer.append(NumberUtils.SortableStr2double(upperTerm));
+ buffer.append(NumericUtils.prefixCodedToDouble(upperTerm));
}
buffer.append(includeUpper ? "]" : "}");
return buffer.toString();
Modified: lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/CartesianShapeFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/CartesianShapeFilter.java?rev=794721&r1=794720&r2=794721&view=diff
==============================================================================
--- lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/CartesianShapeFilter.java (original)
+++ lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/CartesianShapeFilter.java Thu Jul 16 15:38:06 2009
@@ -25,7 +25,7 @@
import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermDocs;
import org.apache.lucene.search.Filter;
-import org.apache.lucene.spatial.NumberUtils;
+import org.apache.lucene.util.NumericUtils;
public class CartesianShapeFilter extends Filter {
@@ -56,9 +56,8 @@
// iterate through each boxid
for (int i =0; i< sz; i++) {
double boxId = area.get(i).doubleValue();
-
termDocs.seek(new Term(fieldName,
- NumberUtils.double2sortableStr(boxId)));
+ NumericUtils.doubleToPrefixCoded(boxId)));
// iterate through all documents
// which have this boxId
Modified: lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/LatLongDistanceFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/LatLongDistanceFilter.java?rev=794721&r1=794720&r2=794721&view=diff
==============================================================================
--- lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/LatLongDistanceFilter.java (original)
+++ lucene/java/trunk/contrib/spatial/src/java/org/apache/lucene/spatial/tier/LatLongDistanceFilter.java Thu Jul 16 15:38:06 2009
@@ -27,7 +27,7 @@
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.TermDocs;
import org.apache.lucene.search.FieldCache;
-import org.apache.lucene.spatial.NumberUtils;
+import org.apache.lucene.util.NumericUtils;
import org.apache.lucene.spatial.tier.DistanceHandler.Precision;
@@ -91,8 +91,8 @@
// TODO: Why is this a WeakHashMap?
WeakHashMap<String,Double> cdistance = new WeakHashMap<String,Double>(maxdocs);
long start = System.currentTimeMillis();
- String[] latIndex = FieldCache.DEFAULT.getStrings(reader, latField);
- String[] lngIndex = FieldCache.DEFAULT.getStrings(reader, lngField);
+ double[] latIndex = FieldCache.DEFAULT.getDoubles(reader, latField);
+ double[] lngIndex = FieldCache.DEFAULT.getDoubles(reader, lngField);
/* store calculated distances for reuse by other components */
distances = new HashMap<Integer,Double>(maxdocs);
@@ -105,11 +105,8 @@
while(td.next()) {
int doc = td.doc();
- String sx = latIndex[doc];
- String sy = lngIndex[doc];
-
- double x = NumberUtils.SortableStr2double(sx);
- double y = NumberUtils.SortableStr2double(sy);
+ double x = latIndex[doc];
+ double y = lngIndex[doc];
// round off lat / longs if necessary
// x = DistanceHandler.getPrecision(x, precise);
@@ -168,8 +165,8 @@
}
long start = System.currentTimeMillis();
- String[] latIndex = FieldCache.DEFAULT.getStrings(reader, latField);
- String[] lngIndex = FieldCache.DEFAULT.getStrings(reader, lngField);
+ double[] latIndex = FieldCache.DEFAULT.getDoubles(reader, latField);
+ double[] lngIndex = FieldCache.DEFAULT.getDoubles(reader, lngField);
/* loop over all set bits (hits from the boundary box filters) */
int i = bits.nextSetBit(0);
@@ -186,10 +183,8 @@
// filter chain, lat / lngs can be retrived from
// memory rather than document base.
- String sx = latIndex[i];
- String sy = lngIndex[i];
- x = NumberUtils.SortableStr2double(sx);
- y = NumberUtils.SortableStr2double(sy);
+ x = latIndex[i];
+ y = lngIndex[i];
// round off lat / longs if necessary
// x = DistanceHandler.getPrecision(x, precise);
Modified: lucene/java/trunk/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.java?rev=794721&r1=794720&r2=794721&view=diff
==============================================================================
--- lucene/java/trunk/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.java (original)
+++ lucene/java/trunk/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.java Thu Jul 16 15:38:06 2009
@@ -37,7 +37,7 @@
import org.apache.lucene.search.function.CustomScoreQuery;
import org.apache.lucene.search.function.FieldScoreQuery;
import org.apache.lucene.search.function.FieldScoreQuery.Type;
-import org.apache.lucene.spatial.NumberUtils;
+import org.apache.lucene.util.NumericUtils;
import org.apache.lucene.spatial.geohash.GeoHashUtils;
import org.apache.lucene.spatial.tier.projections.CartesianTierPlotter;
import org.apache.lucene.spatial.tier.projections.IProjector;
@@ -96,8 +96,8 @@
doc.add(new Field("name", name,Field.Store.YES, Field.Index.TOKENIZED));
// convert the lat / long to lucene fields
- doc.add(new Field(latField, NumberUtils.double2sortableStr(lat),Field.Store.YES, Field.Index.UN_TOKENIZED));
- doc.add(new Field(lngField, NumberUtils.double2sortableStr(lng),Field.Store.YES, Field.Index.UN_TOKENIZED));
+ doc.add(new Field(latField, NumericUtils.doubleToPrefixCoded(lat),Field.Store.YES, Field.Index.UN_TOKENIZED));
+ doc.add(new Field(lngField, NumericUtils.doubleToPrefixCoded(lng),Field.Store.YES, Field.Index.UN_TOKENIZED));
// add a default meta field to make searching all documents easy
doc.add(new Field("metafile", "doc",Field.Store.YES, Field.Index.TOKENIZED));
@@ -106,7 +106,7 @@
for (int i =0; i < ctpsize; i++){
CartesianTierPlotter ctp = ctps.get(i);
doc.add(new Field(ctp.getTierFieldName(),
- NumberUtils.double2sortableStr(ctp.getTierBoxId(lat,lng)),
+ NumericUtils.doubleToPrefixCoded(ctp.getTierBoxId(lat,lng)),
Field.Store.YES,
Field.Index.NO_NORMS));
@@ -212,8 +212,8 @@
Document d = hits.doc(i);
String name = d.get("name");
- double rsLat = NumberUtils.SortableStr2double(d.get(latField));
- double rsLng = NumberUtils.SortableStr2double(d.get(lngField));
+ double rsLat = NumericUtils.prefixCodedToDouble(d.get(latField));
+ double rsLng = NumericUtils.prefixCodedToDouble(d.get(lngField));
Double geo_distance = distances.get(hits.id(i));
double distance = DistanceUtils.getInstance().getDistanceMi(lat, lng, rsLat, rsLng);
@@ -296,8 +296,8 @@
Document d = hits.doc(i);
String name = d.get("name");
- double rsLat = NumberUtils.SortableStr2double(d.get(latField));
- double rsLng = NumberUtils.SortableStr2double(d.get(lngField));
+ double rsLat = NumericUtils.prefixCodedToDouble(d.get(latField));
+ double rsLng = NumericUtils.prefixCodedToDouble(d.get(lngField));
Double geo_distance = distances.get(hits.id(i));
double distance = DistanceUtils.getInstance().getDistanceMi(lat, lng, rsLat, rsLng);
Modified: lucene/java/trunk/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestDistance.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestDistance.java?rev=794721&r1=794720&r2=794721&view=diff
==============================================================================
--- lucene/java/trunk/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestDistance.java (original)
+++ lucene/java/trunk/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestDistance.java Thu Jul 16 15:38:06 2009
@@ -29,7 +29,7 @@
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.Filter;
import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.spatial.NumberUtils;
+import org.apache.lucene.util.NumericUtils;
import org.apache.lucene.spatial.tier.LatLongDistanceFilter;
import org.apache.lucene.store.RAMDirectory;
@@ -69,8 +69,8 @@
doc.add(new Field("name", name,Field.Store.YES, Field.Index.TOKENIZED));
// convert the lat / long to lucene fields
- doc.add(new Field(latField, NumberUtils.double2sortableStr(lat),Field.Store.YES, Field.Index.UN_TOKENIZED));
- doc.add(new Field(lngField, NumberUtils.double2sortableStr(lng),Field.Store.YES, Field.Index.UN_TOKENIZED));
+ doc.add(new Field(latField, NumericUtils.doubleToPrefixCoded(lat),Field.Store.YES, Field.Index.UN_TOKENIZED));
+ doc.add(new Field(lngField, NumericUtils.doubleToPrefixCoded(lng),Field.Store.YES, Field.Index.UN_TOKENIZED));
// add a default meta field to make searching all documents easy
doc.add(new Field("metafile", "doc",Field.Store.YES, Field.Index.TOKENIZED));
Modified: lucene/java/trunk/src/java/org/apache/lucene/util/NumericUtils.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/util/NumericUtils.java?rev=794721&r1=794720&r2=794721&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/util/NumericUtils.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/util/NumericUtils.java Thu Jul 16 15:38:06 2009
@@ -260,6 +260,14 @@
}
/**
+ * Convenience method: this just returns:
+ * longToPrefixCoded(doubleToSortableLong(val))
+ */
+ public static String doubleToPrefixCoded(double val) {
+ return longToPrefixCoded(doubleToSortableLong(val));
+ }
+
+ /**
* Converts a sortable <code>long</code> back to a <code>double</code>.
* @see #doubleToSortableLong
*/
@@ -269,6 +277,14 @@
}
/**
+ * Convenience method: this just returns:
+ * sortableLongToDouble(prefixCodedToLong(val))
+ */
+ public static double prefixCodedToDouble(String val) {
+ return sortableLongToDouble(prefixCodedToLong(val));
+ }
+
+ /**
* Converts a <code>float</code> value to a sortable signed <code>int</code>.
* The value is converted by getting their IEEE 754 floating-point "float format"
* bit layout and then some bits are swapped, to be able to compare the result as int.
@@ -282,6 +298,14 @@
}
/**
+ * Convenience method: this just returns:
+ * intToPrefixCoded(floatToSortableInt(val))
+ */
+ public static String floatToPrefixCoded(float val) {
+ return intToPrefixCoded(floatToSortableInt(val));
+ }
+
+ /**
* Converts a sortable <code>int</code> back to a <code>float</code>.
* @see #floatToSortableInt
*/
@@ -291,6 +315,14 @@
}
/**
+ * Convenience method: this just returns:
+ * sortableIntToFloat(prefixCodedToInt(val))
+ */
+ public static float prefixCodedToFloat(String val) {
+ return sortableIntToFloat(prefixCodedToInt(val));
+ }
+
+ /**
* Expert: Splits a long range recursively.
* You may implement a builder that adds clauses to a
* {@link org.apache.lucene.search.BooleanQuery} for each call to its