You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by si...@apache.org on 2012/09/21 19:22:27 UTC
svn commit: r1388574 [30/45] - in /lucene/dev/branches/LUCENE-2878: ./
dev-tools/ dev-tools/eclipse/ dev-tools/eclipse/dot.settings/
dev-tools/idea/ dev-tools/idea/.idea/ dev-tools/idea/.idea/libraries/
dev-tools/idea/lucene/ dev-tools/idea/lucene/anal...
Modified: lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialExample.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialExample.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialExample.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialExample.java Fri Sep 21 17:21:34 2012
@@ -18,7 +18,9 @@ package org.apache.lucene.spatial;
*/
import com.spatial4j.core.context.SpatialContext;
-import com.spatial4j.core.context.simple.SimpleSpatialContext;
+import com.spatial4j.core.distance.DistanceUtils;
+import com.spatial4j.core.io.ShapeReadWriter;
+import com.spatial4j.core.shape.Point;
import com.spatial4j.core.shape.Shape;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
@@ -28,7 +30,6 @@ import org.apache.lucene.index.Directory
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
-import org.apache.lucene.index.IndexableField;
import org.apache.lucene.queries.function.ValueSource;
import org.apache.lucene.search.Filter;
import org.apache.lucene.search.IndexSearcher;
@@ -45,7 +46,6 @@ import org.apache.lucene.spatial.query.S
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.LuceneTestCase;
-import org.apache.lucene.util.Version;
import java.io.IOException;
@@ -75,8 +75,9 @@ public class SpatialExample extends Luce
/**
* The Lucene spatial {@link SpatialStrategy} encapsulates an approach to
- * indexing and searching shapes, and providing relevancy scores for them.
- * It's a simple API to unify different approaches.
+ * indexing and searching shapes, and providing distance values for them.
+ * It's a simple API to unify different approaches. You might use more than
+ * one strategy for a shape as each strategy has its strengths and weaknesses.
* <p />
* Note that these are initialized with a field name.
*/
@@ -85,13 +86,13 @@ public class SpatialExample extends Luce
private Directory directory;
protected void init() {
- //Typical geospatial context with kilometer units.
- // These can also be constructed from a factory: SpatialContextFactory
- this.ctx = SimpleSpatialContext.GEO_KM;
+ //Typical geospatial context
+ // These can also be constructed from SpatialContextFactory
+ this.ctx = SpatialContext.GEO;
- int maxLevels = 10;//results in sub-meter precision for geohash
+ int maxLevels = 11;//results in sub-meter precision for geohash
//TODO demo lookup by detail distance
- // This can also be constructed from a factory: SpatialPrefixTreeFactory
+ // This can also be constructed from SpatialPrefixTreeFactory
SpatialPrefixTree grid = new GeohashPrefixTree(ctx, maxLevels);
this.strategy = new RecursivePrefixTreeStrategy(grid, "myGeoField");
@@ -110,7 +111,7 @@ public class SpatialExample extends Luce
//When parsing a string to a shape, the presence of a comma means it's y-x
// order (lon, lat)
indexWriter.addDocument(newSampleDocument(
- 4, ctx.readShape("-50.7693246, 60.9289094")));
+ 4, new ShapeReadWriter(ctx).readShape("-50.7693246, 60.9289094")));
indexWriter.addDocument(newSampleDocument(
20, ctx.makePoint(0.1,0.1), ctx.makePoint(0, 0)));
@@ -124,7 +125,7 @@ public class SpatialExample extends Luce
//Potentially more than one shape in this field is supported by some
// strategies; see the javadocs of the SpatialStrategy impl to see.
for (Shape shape : shapes) {
- for (IndexableField f : strategy.createIndexableFields(shape)) {
+ for (Field f : strategy.createIndexableFields(shape)) {
doc.add(f);
}
//store it too; the format is up to you
@@ -144,16 +145,15 @@ public class SpatialExample extends Luce
//Search with circle
//note: SpatialArgs can be parsed from a string
SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects,
- ctx.makeCircle(-80.0, 33.0, 200));//200km (since km == ctx.getDistanceUnits
+ ctx.makeCircle(-80.0, 33.0, DistanceUtils.dist2Degrees(200, DistanceUtils.EARTH_MEAN_RADIUS_KM)));
Filter filter = strategy.makeFilter(args);
TopDocs docs = indexSearcher.search(new MatchAllDocsQuery(), filter, 10, idSort);
assertDocMatchedIds(indexSearcher, docs, 2);
}
//--Match all, order by distance
{
- SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects,//doesn't matter
- ctx.makePoint(60, -50));
- ValueSource valueSource = strategy.makeValueSource(args);//the distance
+ Point pt = ctx.makePoint(60, -50);
+ ValueSource valueSource = strategy.makeDistanceValueSource(pt);//the distance (in degrees)
Sort reverseDistSort = new Sort(valueSource.getSortField(false)).rewrite(indexSearcher);//true=asc dist
TopDocs docs = indexSearcher.search(new MatchAllDocsQuery(), 10, reverseDistSort);
assertDocMatchedIds(indexSearcher, docs, 4, 20, 2);
@@ -161,8 +161,8 @@ public class SpatialExample extends Luce
//demo arg parsing
{
SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects,
- ctx.makeCircle(-80.0, 33.0, 200));
- SpatialArgs args2 = new SpatialArgsParser().parse("Intersects(Circle(33,-80 d=200))", ctx);
+ ctx.makeCircle(-80.0, 33.0, 1));
+ SpatialArgs args2 = new SpatialArgsParser().parse("Intersects(Circle(33,-80 d=1))", ctx);
assertEquals(args.toString(),args2.toString());
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java Fri Sep 21 17:21:34 2012
@@ -20,6 +20,7 @@ package org.apache.lucene.spatial;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.RandomIndexWriter;
+import org.apache.lucene.index.StoredDocument;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
@@ -31,14 +32,15 @@ import org.junit.After;
import org.junit.Before;
import java.io.IOException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
public abstract class SpatialTestCase extends LuceneTestCase {
private DirectoryReader indexReader;
private RandomIndexWriter indexWriter;
private Directory directory;
- private IndexSearcher indexSearcher;
+ protected IndexSearcher indexSearcher;
@Override
@Before
@@ -130,11 +132,11 @@ public abstract class SpatialTestCase ex
protected static class SearchResult {
public float score;
- public Document document;
+ public StoredDocument document;
- public SearchResult(float score, Document document) {
+ public SearchResult(float score, StoredDocument storedDocument) {
this.score = score;
- this.document = document;
+ this.document = storedDocument;
}
@Override
Modified: lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.java Fri Sep 21 17:21:34 2012
@@ -19,6 +19,7 @@ package org.apache.lucene.spatial;
*/
import com.spatial4j.core.context.SpatialContext;
+import com.spatial4j.core.io.ShapeReadWriter;
import com.spatial4j.core.io.sample.SampleData;
import com.spatial4j.core.io.sample.SampleDataReader;
import com.spatial4j.core.shape.Shape;
@@ -26,7 +27,11 @@ import org.apache.lucene.document.Docume
import org.apache.lucene.document.Field;
import org.apache.lucene.document.StoredField;
import org.apache.lucene.document.StringField;
-import org.apache.lucene.index.IndexableField;
+import org.apache.lucene.queries.function.FunctionQuery;
+import org.apache.lucene.queries.function.ValueSource;
+import org.apache.lucene.search.CheckHits;
+import org.apache.lucene.search.ScoreDoc;
+import org.apache.lucene.search.TopDocs;
import org.apache.lucene.spatial.query.SpatialArgsParser;
import org.junit.Assert;
@@ -51,7 +56,7 @@ public abstract class StrategyTestCase e
public static final String QTEST_States_IsWithin_BBox = "states-IsWithin-BBox.txt";
public static final String QTEST_States_Intersects_BBox = "states-Intersects-BBox.txt";
- public static final String QTEST_Cities_IsWithin_BBox = "cities-IsWithin-BBox.txt";
+ public static final String QTEST_Cities_Intersects_BBox = "cities-Intersects-BBox.txt";
public static final String QTEST_Simple_Queries_BBox = "simple-Queries-BBox.txt";
private Logger log = Logger.getLogger(getClass().getName());
@@ -84,18 +89,26 @@ public abstract class StrategyTestCase e
Document document = new Document();
document.add(new StringField("id", data.id, Field.Store.YES));
document.add(new StringField("name", data.name, Field.Store.YES));
- Shape shape = ctx.readShape(data.shape);
- for (IndexableField f : strategy.createIndexableFields(shape)) {
- document.add(f);
+ Shape shape = new ShapeReadWriter(ctx).readShape(data.shape);
+ shape = convertShapeFromGetDocuments(shape);
+ if (shape != null) {
+ for (Field f : strategy.createIndexableFields(shape)) {
+ document.add(f);
+ }
+ if (storeShape)
+ document.add(new StoredField(strategy.getFieldName(), ctx.toString(shape)));
}
- if (storeShape)
- document.add(new StoredField(strategy.getFieldName(), ctx.toString(shape)));
documents.add(document);
}
return documents;
}
+ /** Subclasses may override to transform or remove a shape for indexing */
+ protected Shape convertShapeFromGetDocuments(Shape shape) {
+ return shape;
+ }
+
protected Iterator<SampleData> getSampleData(String testDataFile) throws IOException {
return new SampleDataReader(
getClass().getClassLoader().getResourceAsStream("data/"+testDataFile) );
@@ -117,7 +130,7 @@ public abstract class StrategyTestCase e
SearchResults got = executeQuery(strategy.makeQuery(q.args), 100);
if (storeShape && got.numFound > 0) {
//check stored value is there & parses
- assertNotNull(ctx.readShape(got.results.get(0).document.get(strategy.getFieldName())));
+ assertNotNull(new ShapeReadWriter(ctx).readShape(got.results.get(0).document.get(strategy.getFieldName())));
}
if (concern.orderIsImportant) {
Iterator<String> ids = q.ids.iterator();
@@ -159,4 +172,47 @@ public abstract class StrategyTestCase e
}
}
}
+
+ protected void adoc(String id, String shapeStr) throws IOException {
+ Shape shape = shapeStr==null ? null : new ShapeReadWriter(ctx).readShape(shapeStr);
+ addDocument(newDoc(id, shape));
+ }
+ protected void adoc(String id, Shape shape) throws IOException {
+ addDocument(newDoc(id, shape));
+ }
+
+ protected Document newDoc(String id, Shape shape) {
+ Document doc = new Document();
+ doc.add(new StringField("id", id, Field.Store.YES));
+ if (shape != null) {
+ for (Field f : strategy.createIndexableFields(shape)) {
+ doc.add(f);
+ }
+ if (storeShape)
+ doc.add(new StoredField(strategy.getFieldName(), ctx.toString(shape)));
+ }
+ return doc;
+ }
+
+ /** scores[] are in docId order */
+ protected void checkValueSource(ValueSource vs, float scores[], float delta) throws IOException {
+ FunctionQuery q = new FunctionQuery(vs);
+
+// //TODO is there any point to this check?
+// int expectedDocs[] = new int[scores.length];//fill with ascending 0....length-1
+// for (int i = 0; i < expectedDocs.length; i++) {
+// expectedDocs[i] = i;
+// }
+// CheckHits.checkHits(random(), q, "", indexSearcher, expectedDocs);
+
+ TopDocs docs = indexSearcher.search(q, 1000);//calculates the score
+ for (int i = 0; i < docs.scoreDocs.length; i++) {
+ ScoreDoc gotSD = docs.scoreDocs[i];
+ float expectedScore = scores[gotSD.doc];
+ assertEquals("Not equal for doc "+gotSD.doc, expectedScore, gotSD.score, delta);
+ }
+
+ CheckHits.checkExplanations(q, "", indexSearcher);
+ }
+
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/TestTestFramework.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/TestTestFramework.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/TestTestFramework.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/TestTestFramework.java Fri Sep 21 17:21:34 2012
@@ -18,7 +18,6 @@ package org.apache.lucene.spatial;
*/
import com.spatial4j.core.context.SpatialContext;
-import com.spatial4j.core.context.simple.SimpleSpatialContext;
import com.spatial4j.core.shape.Rectangle;
import org.apache.lucene.spatial.query.SpatialArgsParser;
import org.apache.lucene.spatial.query.SpatialOperation;
@@ -40,10 +39,10 @@ public class TestTestFramework extends L
@Test
public void testQueries() throws IOException {
- String name = StrategyTestCase.QTEST_Cities_IsWithin_BBox;
+ String name = StrategyTestCase.QTEST_Cities_Intersects_BBox;
InputStream in = getClass().getClassLoader().getResourceAsStream(name);
- SpatialContext ctx = SimpleSpatialContext.GEO_KM;
+ SpatialContext ctx = SpatialContext.GEO;
Iterator<SpatialTestQuery> iter = SpatialTestQuery.getTestQueries(
new SpatialArgsParser(), ctx, name, in );
List<SpatialTestQuery> tests = new ArrayList<SpatialTestQuery>();
@@ -57,7 +56,7 @@ public class TestTestFramework extends L
Assert.assertEquals( 1, sf.ids.size() );
Assert.assertTrue( sf.ids.get(0).equals( "G5391959" ) );
Assert.assertTrue( sf.args.getShape() instanceof Rectangle);
- Assert.assertEquals( SpatialOperation.IsWithin, sf.args.getOperation() );
+ Assert.assertEquals( SpatialOperation.Intersects, sf.args.getOperation() );
}
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/bbox/TestBBoxStrategy.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/bbox/TestBBoxStrategy.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/bbox/TestBBoxStrategy.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/bbox/TestBBoxStrategy.java Fri Sep 21 17:21:34 2012
@@ -1,60 +1,67 @@
-package org.apache.lucene.spatial.bbox;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import com.spatial4j.core.context.simple.SimpleSpatialContext;
-import org.apache.lucene.spatial.SpatialMatchConcern;
-import org.apache.lucene.spatial.StrategyTestCase;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.io.IOException;
-
-public class TestBBoxStrategy extends StrategyTestCase {
-
- @Before
- @Override
- public void setUp() throws Exception {
- super.setUp();
- this.ctx = SimpleSpatialContext.GEO_KM;
- this.strategy = new BBoxStrategy(ctx, "bbox");
- }
-
- @Test
- public void testBasicOperaions() throws IOException {
- getAddAndVerifyIndexedDocuments(DATA_SIMPLE_BBOX);
-
- executeQueries(SpatialMatchConcern.EXACT, QTEST_Simple_Queries_BBox);
- }
-
- @Test
- public void testStatesBBox() throws IOException {
- getAddAndVerifyIndexedDocuments(DATA_STATES_BBOX);
-
- executeQueries(SpatialMatchConcern.FILTER, QTEST_States_IsWithin_BBox);
- executeQueries(SpatialMatchConcern.FILTER, QTEST_States_Intersects_BBox);
- }
-
- @Test
- public void testCitiesWithinBBox() throws IOException {
- getAddAndVerifyIndexedDocuments(DATA_WORLD_CITIES_POINTS);
-
- executeQueries(SpatialMatchConcern.FILTER, QTEST_Cities_IsWithin_BBox);
- }
-
-}
+package org.apache.lucene.spatial.bbox;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import com.spatial4j.core.context.SpatialContext;
+import com.spatial4j.core.shape.Shape;
+import org.apache.lucene.spatial.SpatialMatchConcern;
+import org.apache.lucene.spatial.StrategyTestCase;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+
+public class TestBBoxStrategy extends StrategyTestCase {
+
+ @Before
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ this.ctx = SpatialContext.GEO;
+ this.strategy = new BBoxStrategy(ctx, "bbox");
+ }
+
+ /* Convert DATA_WORLD_CITIES_POINTS to bbox */
+ @Override
+ protected Shape convertShapeFromGetDocuments(Shape shape) {
+ return shape.getBoundingBox();
+ }
+
+ @Test
+ public void testBasicOperaions() throws IOException {
+ getAddAndVerifyIndexedDocuments(DATA_SIMPLE_BBOX);
+
+ executeQueries(SpatialMatchConcern.EXACT, QTEST_Simple_Queries_BBox);
+ }
+
+ @Test
+ public void testStatesBBox() throws IOException {
+ getAddAndVerifyIndexedDocuments(DATA_STATES_BBOX);
+
+ executeQueries(SpatialMatchConcern.FILTER, QTEST_States_IsWithin_BBox);
+ executeQueries(SpatialMatchConcern.FILTER, QTEST_States_Intersects_BBox);
+ }
+
+ @Test
+ public void testCitiesIntersectsBBox() throws IOException {
+ getAddAndVerifyIndexedDocuments(DATA_WORLD_CITIES_POINTS);
+
+ executeQueries(SpatialMatchConcern.FILTER, QTEST_Cities_Intersects_BBox);
+ }
+
+}
Modified: lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestRecursivePrefixTreeStrategy.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestRecursivePrefixTreeStrategy.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestRecursivePrefixTreeStrategy.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestRecursivePrefixTreeStrategy.java Fri Sep 21 17:21:34 2012
@@ -17,18 +17,12 @@ package org.apache.lucene.spatial.prefix
* limitations under the License.
*/
-import com.spatial4j.core.context.simple.SimpleSpatialContext;
+import com.spatial4j.core.context.SpatialContext;
import com.spatial4j.core.distance.DistanceUtils;
+import com.spatial4j.core.io.GeohashUtils;
import com.spatial4j.core.shape.Point;
import com.spatial4j.core.shape.Rectangle;
import com.spatial4j.core.shape.Shape;
-import com.spatial4j.core.shape.simple.PointImpl;
-import com.spatial4j.core.util.GeohashUtils;
-import org.apache.lucene.document.Document;
-import org.apache.lucene.document.Field;
-import org.apache.lucene.document.StoredField;
-import org.apache.lucene.document.StringField;
-import org.apache.lucene.index.IndexableField;
import org.apache.lucene.spatial.SpatialMatchConcern;
import org.apache.lucene.spatial.StrategyTestCase;
import org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree;
@@ -43,8 +37,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import static java.lang.Math.toRadians;
-
public class TestRecursivePrefixTreeStrategy extends StrategyTestCase {
private int maxLength;
@@ -52,7 +44,7 @@ public class TestRecursivePrefixTreeStra
//Tests should call this first.
private void init(int maxLength) {
this.maxLength = maxLength;
- this.ctx = SimpleSpatialContext.GEO_KM;
+ this.ctx = SpatialContext.GEO;
GeohashPrefixTree grid = new GeohashPrefixTree(ctx, maxLength);
this.strategy = new RecursivePrefixTreeStrategy(grid, getClass().getSimpleName());
}
@@ -65,80 +57,132 @@ public class TestRecursivePrefixTreeStra
//execute queries for each prefix grid scan level
for(int i = 0; i <= maxLength; i++) {
((RecursivePrefixTreeStrategy)strategy).setPrefixGridScanLevel(i);
- executeQueries(SpatialMatchConcern.FILTER, QTEST_Cities_IsWithin_BBox);
+ executeQueries(SpatialMatchConcern.FILTER, QTEST_Cities_Intersects_BBox);
}
}
@Test
+ public void testOneMeterPrecision() {
+ init(GeohashPrefixTree.getMaxLevelsPossible());
+ GeohashPrefixTree grid = (GeohashPrefixTree) ((RecursivePrefixTreeStrategy) strategy).getGrid();
+ //DWS: I know this to be true. 11 is needed for one meter
+ double degrees = DistanceUtils.dist2Degrees(0.001, DistanceUtils.EARTH_MEAN_RADIUS_KM);
+ assertEquals(11, grid.getLevelForDistance(degrees));
+ }
+
+ @Test
+ public void testPrecision() throws IOException{
+ init(GeohashPrefixTree.getMaxLevelsPossible());
+
+ Point iPt = ctx.makePoint(2.8028712999999925, 48.3708044);//lon, lat
+ addDocument(newDoc("iPt", iPt));
+ commit();
+
+ Point qPt = ctx.makePoint(2.4632387000000335, 48.6003516);
+
+ final double KM2DEG = DistanceUtils.dist2Degrees(1, DistanceUtils.EARTH_MEAN_RADIUS_KM);
+ final double DEG2KM = 1 / KM2DEG;
+
+ final double DIST = 35.75;//35.7499...
+ assertEquals(DIST, ctx.getDistCalc().distance(iPt, qPt) * DEG2KM, 0.001);
+
+ //distErrPct will affect the query shape precision. The indexed precision
+ // was set to nearly zilch via init(GeohashPrefixTree.getMaxLevelsPossible());
+ final double distErrPct = 0.025; //the suggested default, by the way
+ final double distMult = 1+distErrPct;
+
+ assertTrue(35.74*distMult >= DIST);
+ checkHits(q(qPt, 35.74 * KM2DEG, distErrPct), 1, null);
+
+ assertTrue(30*distMult < DIST);
+ checkHits(q(qPt, 30 * KM2DEG, distErrPct), 0, null);
+
+ assertTrue(33*distMult < DIST);
+ checkHits(q(qPt, 33 * KM2DEG, distErrPct), 0, null);
+
+ assertTrue(34*distMult < DIST);
+ checkHits(q(qPt, 34 * KM2DEG, distErrPct), 0, null);
+ }
+
+ @Test
public void geohashRecursiveRandom() throws IOException {
init(12);
//1. Iterate test with the cluster at some worldly point of interest
- Point[] clusterCenters = new Point[]{new PointImpl(0,0), new PointImpl(0,90),new PointImpl(0,-90)};
+ Point[] clusterCenters = new Point[]{ctx.makePoint(-180,0), ctx.makePoint(0,90), ctx.makePoint(0,-90)};
for (Point clusterCenter : clusterCenters) {
//2. Iterate on size of cluster (a really small one and a large one)
String hashCenter = GeohashUtils.encodeLatLon(clusterCenter.getY(), clusterCenter.getX(), maxLength);
//calculate the number of degrees in the smallest grid box size (use for both lat & lon)
String smallBox = hashCenter.substring(0,hashCenter.length()-1);//chop off leaf precision
Rectangle clusterDims = GeohashUtils.decodeBoundary(smallBox,ctx);
- double smallDegrees = Math.max(clusterDims.getMaxX()-clusterDims.getMinX(),clusterDims.getMaxY()-clusterDims.getMinY());
- assert smallDegrees < 1;
- double largeDegrees = 20d;//good large size; don't use >=45 for this test code to work
- double[] sideDegrees = {largeDegrees,smallDegrees};
- for (double sideDegree : sideDegrees) {
- //3. Index random points in this cluster box
+ double smallRadius = Math.max(clusterDims.getMaxX()-clusterDims.getMinX(),clusterDims.getMaxY()-clusterDims.getMinY());
+ assert smallRadius < 1;
+ double largeRadius = 20d;//good large size; don't use >=45 for this test code to work
+ double[] radiusDegs = {largeRadius,smallRadius};
+ for (double radiusDeg : radiusDegs) {
+ //3. Index random points in this cluster circle
deleteAll();
List<Point> points = new ArrayList<Point>();
for(int i = 0; i < 20; i++) {
- double x = random().nextDouble()*sideDegree - sideDegree/2 + clusterCenter.getX();
- double y = random().nextDouble()*sideDegree - sideDegree/2 + clusterCenter.getY();
- final Point pt = normPointXY(x, y);
+ //Note that this will not result in randomly distributed points in the
+ // circle, they will be concentrated towards the center a little. But
+ // it's good enough.
+ Point pt = ctx.getDistCalc().pointOnBearing(clusterCenter,
+ random().nextDouble() * radiusDeg, random().nextInt() * 360, ctx, null);
+ pt = alignGeohash(pt);
points.add(pt);
addDocument(newDoc("" + i, pt));
}
commit();
- //3. Use 4 query centers. Each is radially out from each corner of cluster box by twice distance to box edge.
- for(double qcXoff : new double[]{sideDegree,-sideDegree}) {//query-center X offset from cluster center
- for(double qcYoff : new double[]{sideDegree,-sideDegree}) {//query-center Y offset from cluster center
- Point queryCenter = normPointXY(qcXoff + clusterCenter.getX(),
- qcYoff + clusterCenter.getY());
- double[] distRange = calcDistRange(queryCenter,clusterCenter,sideDegree);
- //4.1 query a small box getting nothing
- checkHits(queryCenter, distRange[0]*0.99, 0, null);
- //4.2 Query a large box enclosing the cluster, getting everything
- checkHits(queryCenter, distRange[1]*1.01, points.size(), null);
- //4.3 Query a medium box getting some (calculate the correct solution and verify)
- double queryDist = distRange[0] + (distRange[1]-distRange[0])/2;//average
-
- //Find matching points. Put into int[] of doc ids which is the same thing as the index into points list.
- int[] ids = new int[points.size()];
- int ids_sz = 0;
- for (int i = 0; i < points.size(); i++) {
- Point point = points.get(i);
- if (ctx.getDistCalc().distance(queryCenter, point) <= queryDist)
- ids[ids_sz++] = i;
- }
- ids = Arrays.copyOf(ids, ids_sz);
- //assert ids_sz > 0 (can't because randomness keeps us from being able to)
-
- checkHits(queryCenter, queryDist, ids.length, ids);
+ //3. Use some query centers. Each is twice the cluster's radius away.
+ for(int ri = 0; ri < 4; ri++) {
+ Point queryCenter = ctx.getDistCalc().pointOnBearing(clusterCenter,
+ radiusDeg*2, random().nextInt(360), ctx, null);
+ queryCenter = alignGeohash(queryCenter);
+ //4.1 Query a small box getting nothing
+ checkHits(q(queryCenter, radiusDeg - smallRadius/2), 0, null);
+ //4.2 Query a large box enclosing the cluster, getting everything
+ checkHits(q(queryCenter, radiusDeg*3 + smallRadius/2), points.size(), null);
+ //4.3 Query a medium box getting some (calculate the correct solution and verify)
+ double queryDist = radiusDeg * 2;
+
+ //Find matching points. Put into int[] of doc ids which is the same thing as the index into points list.
+ int[] ids = new int[points.size()];
+ int ids_sz = 0;
+ for (int i = 0; i < points.size(); i++) {
+ Point point = points.get(i);
+ if (ctx.getDistCalc().distance(queryCenter, point) <= queryDist)
+ ids[ids_sz++] = i;
}
+ ids = Arrays.copyOf(ids, ids_sz);
+ //assert ids_sz > 0 (can't because randomness keeps us from being able to)
+
+ checkHits(q(queryCenter, queryDist), ids.length, ids);
}
- }//for sideDegree
+ }//for radiusDeg
}//for clusterCenter
}//randomTest()
- //TODO can we use super.runTestQueries() ?
- private void checkHits(Point pt, double dist, int assertNumFound, int[] assertIds) {
- Shape shape = ctx.makeCircle(pt,dist);
+ /** Query point-distance (in degrees) with zero error percent. */
+ private SpatialArgs q(Point pt, double distDEG) {
+ return q(pt, distDEG, 0.0);
+ }
+
+ private SpatialArgs q(Point pt, double distDEG, double distErrPct) {
+ Shape shape = ctx.makeCircle(pt, distDEG);
SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects,shape);
- args.setDistPrecision(0.0);
+ args.setDistErrPct(distErrPct);
+ return args;
+ }
+
+ private void checkHits(SpatialArgs args, int assertNumFound, int[] assertIds) {
SearchResults got = executeQuery(strategy.makeQuery(args), 100);
- assertEquals(""+shape,assertNumFound,got.numFound);
+ assertEquals("" + args, assertNumFound, got.numFound);
if (assertIds != null) {
Set<Integer> gotIds = new HashSet<Integer>();
for (SearchResult result : got.results) {
@@ -150,42 +194,8 @@ public class TestRecursivePrefixTreeStra
}
}
- //
- private Document newDoc(String id, Shape shape) {
- Document doc = new Document();
- doc.add(new StringField("id", id, Field.Store.YES));
- for (IndexableField f : strategy.createIndexableFields(shape)) {
- doc.add(f);
- }
- if (storeShape)
- doc.add(new StoredField(strategy.getFieldName(), ctx.toString(shape)));
- return doc;
- }
-
- private double[] calcDistRange(Point startPoint, Point targetCenter, double targetSideDegrees) {
- double min = Double.MAX_VALUE;
- double max = Double.MIN_VALUE;
- for(double xLen : new double[]{targetSideDegrees,-targetSideDegrees}) {
- for(double yLen : new double[]{targetSideDegrees,-targetSideDegrees}) {
- Point p2 = normPointXY(targetCenter.getX() + xLen / 2, targetCenter.getY() + yLen / 2);
- double d = ctx.getDistCalc().distance(startPoint, p2);
- min = Math.min(min,d);
- max = Math.max(max,d);
- }
- }
- return new double[]{min,max};
- }
-
- /** Normalize x & y (put in lon-lat ranges) & ensure geohash round-trip for given precision. */
- private Point normPointXY(double x, double y) {
- //put x,y as degrees into double[] as radians
- double[] latLon = {y*DistanceUtils.DEG_180_AS_RADS, toRadians(x)};
- DistanceUtils.normLatRAD(latLon);
- DistanceUtils.normLatRAD(latLon);
- double x2 = Math.toDegrees(latLon[1]);
- double y2 = Math.toDegrees(latLon[0]);
- //overwrite latLon, units is now degrees
-
- return GeohashUtils.decode(GeohashUtils.encodeLatLon(y2, x2, maxLength),ctx);
+ /** NGeohash round-trip for given precision. */
+ private Point alignGeohash(Point p) {
+ return GeohashUtils.decode(GeohashUtils.encodeLatLon(p.getY(), p.getX(), maxLength), ctx);
}
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestTermQueryPrefixGridStrategy.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestTermQueryPrefixGridStrategy.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestTermQueryPrefixGridStrategy.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestTermQueryPrefixGridStrategy.java Fri Sep 21 17:21:34 2012
@@ -18,14 +18,11 @@ package org.apache.lucene.spatial.prefix
*/
import com.spatial4j.core.context.SpatialContext;
-import com.spatial4j.core.context.simple.SimpleSpatialContext;
import com.spatial4j.core.shape.Shape;
-import com.spatial4j.core.shape.simple.PointImpl;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.StoredField;
import org.apache.lucene.document.StringField;
-import org.apache.lucene.index.IndexableField;
import org.apache.lucene.spatial.SpatialTestCase;
import org.apache.lucene.spatial.prefix.tree.QuadPrefixTree;
import org.apache.lucene.spatial.query.SpatialArgsParser;
@@ -39,14 +36,14 @@ public class TestTermQueryPrefixGridStra
@Test
public void testNGramPrefixGridLosAngeles() throws IOException {
- SpatialContext ctx = SimpleSpatialContext.GEO_KM;
+ SpatialContext ctx = SpatialContext.GEO;
TermQueryPrefixTreeStrategy prefixGridStrategy = new TermQueryPrefixTreeStrategy(new QuadPrefixTree(ctx), "geo");
- Shape point = new PointImpl(-118.243680, 34.052230);
+ Shape point = ctx.makePoint(-118.243680, 34.052230);
Document losAngeles = new Document();
losAngeles.add(new StringField("name", "Los Angeles", Field.Store.YES));
- for (IndexableField field : prefixGridStrategy.createIndexableFields(point)) {
+ for (Field field : prefixGridStrategy.createIndexableFields(point)) {
losAngeles.add(field);
}
losAngeles.add(new StoredField(prefixGridStrategy.getFieldName(), ctx.toString(point)));
@@ -57,7 +54,7 @@ public class TestTermQueryPrefixGridStra
SpatialArgsParser spatialArgsParser = new SpatialArgsParser();
// TODO... use a non polygon query
// SpatialArgs spatialArgs = spatialArgsParser.parse(
-// "IsWithin(POLYGON((-127.00390625 39.8125,-112.765625 39.98828125,-111.53515625 31.375,-125.94921875 30.14453125,-127.00390625 39.8125)))",
+// "Intersects(POLYGON((-127.00390625 39.8125,-112.765625 39.98828125,-111.53515625 31.375,-125.94921875 30.14453125,-127.00390625 39.8125)))",
// new SimpleSpatialContext());
// Query query = prefixGridStrategy.makeQuery(spatialArgs, fieldInfo);
Modified: lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/tree/SpatialPrefixTreeTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/tree/SpatialPrefixTreeTest.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/tree/SpatialPrefixTreeTest.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/tree/SpatialPrefixTreeTest.java Fri Sep 21 17:21:34 2012
@@ -17,7 +17,7 @@
package org.apache.lucene.spatial.prefix.tree;
-import com.spatial4j.core.context.simple.SimpleSpatialContext;
+import com.spatial4j.core.context.SpatialContext;
import com.spatial4j.core.shape.Rectangle;
import com.spatial4j.core.shape.Shape;
@@ -28,13 +28,13 @@ import org.junit.Test;
public class SpatialPrefixTreeTest extends LuceneTestCase {
//TODO plug in others and test them
- private SimpleSpatialContext ctx;
+ private SpatialContext ctx;
private SpatialPrefixTree trie;
@Before
public void setUp() throws Exception {
super.setUp();
- ctx = SimpleSpatialContext.GEO_KM;
+ ctx = SpatialContext.GEO;
trie = new GeohashPrefixTree(ctx,4);
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/query/SpatialArgsParserTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/query/SpatialArgsParserTest.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/query/SpatialArgsParserTest.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/query/SpatialArgsParserTest.java Fri Sep 21 17:21:34 2012
@@ -18,7 +18,6 @@ package org.apache.lucene.spatial.query;
*/
import com.spatial4j.core.context.SpatialContext;
-import com.spatial4j.core.context.simple.SimpleSpatialContext;
import com.spatial4j.core.shape.Rectangle;
import org.apache.lucene.util.LuceneTestCase;
import org.junit.Test;
@@ -26,7 +25,7 @@ import org.junit.Test;
public class SpatialArgsParserTest extends LuceneTestCase {
- private SpatialContext ctx = SimpleSpatialContext.GEO_KM;
+ private SpatialContext ctx = SpatialContext.GEO;
//The args parser is only dependent on the ctx for IO so I don't care to test
// with other implementations.
Modified: lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/vector/TestTwoDoublesStrategy.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/vector/TestTwoDoublesStrategy.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/vector/TestTwoDoublesStrategy.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/spatial/src/test/org/apache/lucene/spatial/vector/TestTwoDoublesStrategy.java Fri Sep 21 17:21:34 2012
@@ -17,12 +17,10 @@ package org.apache.lucene.spatial.vector
* limitations under the License.
*/
-import com.spatial4j.core.context.simple.SimpleSpatialContext;
+import com.spatial4j.core.context.SpatialContext;
import com.spatial4j.core.exception.InvalidShapeException;
import com.spatial4j.core.shape.Circle;
import com.spatial4j.core.shape.Point;
-import com.spatial4j.core.shape.simple.CircleImpl;
-import com.spatial4j.core.shape.simple.PointImpl;
import org.apache.lucene.search.Query;
import org.apache.lucene.spatial.SpatialMatchConcern;
import org.apache.lucene.spatial.StrategyTestCase;
@@ -39,13 +37,13 @@ public class TestTwoDoublesStrategy exte
@Override
public void setUp() throws Exception {
super.setUp();
- this.ctx = SimpleSpatialContext.GEO_KM;
+ this.ctx = SpatialContext.GEO;
this.strategy = new TwoDoublesStrategy(ctx, getClass().getSimpleName());
}
@Test
public void testCircleShapeSupport() {
- Circle circle = new CircleImpl(new PointImpl(0, 0), 10, this.ctx);
+ Circle circle = ctx.makeCircle(ctx.makePoint(0, 0), 10);
SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, circle);
Query query = this.strategy.makeQuery(args);
@@ -54,14 +52,14 @@ public class TestTwoDoublesStrategy exte
@Test(expected = InvalidShapeException.class)
public void testInvalidQueryShape() {
- Point point = new PointImpl(0, 0);
+ Point point = ctx.makePoint(0, 0);
SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, point);
this.strategy.makeQuery(args);
}
@Test
- public void testCitiesWithinBBox() throws IOException {
+ public void testCitiesIntersectsBBox() throws IOException {
getAddAndVerifyIndexedDocuments(DATA_WORLD_CITIES_POINTS);
- executeQueries(SpatialMatchConcern.FILTER, QTEST_Cities_IsWithin_BBox);
+ executeQueries(SpatialMatchConcern.FILTER, QTEST_Cities_Intersects_BBox);
}
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/CombineSuggestion.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/CombineSuggestion.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/CombineSuggestion.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/CombineSuggestion.java Fri Sep 21 17:21:34 2012
@@ -30,6 +30,11 @@ public class CombineSuggestion {
*/
public final SuggestWord suggestion;
+ /**
+ * Creates a new CombineSuggestion from a <code>suggestion</code> and
+ * an array of term ids (referencing the indexes to the original terms that
+ * form this combined suggestion)
+ */
public CombineSuggestion (SuggestWord suggestion, int[] originalTermIndexes) {
this.suggestion = suggestion;
this.originalTermIndexes = originalTermIndexes;
Modified: lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/DirectSpellChecker.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/DirectSpellChecker.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/DirectSpellChecker.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/DirectSpellChecker.java Fri Sep 21 17:21:34 2012
@@ -88,6 +88,9 @@ public class DirectSpellChecker {
/** the string distance to use */
private StringDistance distance = INTERNAL_LEVENSHTEIN;
+ /** Creates a DirectSpellChecker with default configuration values */
+ public DirectSpellChecker() {}
+
/** Get the maximum number of Levenshtein edit-distances to draw
* candidate terms from. */
public int getMaxEdits() {
@@ -294,7 +297,7 @@ public class DirectSpellChecker {
*/
public SuggestWord[] suggestSimilar(Term term, int numSug, IndexReader ir,
SuggestMode suggestMode) throws IOException {
- return suggestSimilar(term, numSug, ir, suggestMode, this.accuracy);
+ return suggestSimilar(term, numSug, ir, suggestMode, this.accuracy);
}
/**
Modified: lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/HighFrequencyDictionary.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/HighFrequencyDictionary.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/HighFrequencyDictionary.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/HighFrequencyDictionary.java Fri Sep 21 17:21:34 2012
@@ -42,6 +42,13 @@ public class HighFrequencyDictionary imp
private String field;
private float thresh;
+ /**
+ * Creates a new Dictionary, pulling source terms from
+ * the specified <code>field</code> in the provided <code>reader</code>.
+ * <p>
+ * Terms appearing in less than <code>thresh</code> percentage of documents
+ * will be excluded.
+ */
public HighFrequencyDictionary(IndexReader reader, String field, float thresh) {
this.reader = reader;
this.field = field;
Modified: lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/JaroWinklerDistance.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/JaroWinklerDistance.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/JaroWinklerDistance.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/JaroWinklerDistance.java Fri Sep 21 17:21:34 2012
@@ -27,6 +27,13 @@ import java.util.Arrays;
public class JaroWinklerDistance implements StringDistance {
private float threshold = 0.7f;
+
+ /**
+ * Creates a new distance metric with the default threshold
+ * for the Jaro Winkler bonus (0.7)
+ * @see #setThreshold(float)
+ */
+ public JaroWinklerDistance() {}
private int[] matches(String s1, String s2) {
String max, min;
Modified: lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/LuceneDictionary.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/LuceneDictionary.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/LuceneDictionary.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/LuceneDictionary.java Fri Sep 21 17:21:34 2012
@@ -27,14 +27,15 @@ import java.io.*;
/**
* Lucene Dictionary: terms taken from the given field
* of a Lucene index.
- *
- * When using IndexReader.terms(Term) the code must not call next() on TermEnum
- * as the first call to TermEnum, see: http://issues.apache.org/jira/browse/LUCENE-6
*/
public class LuceneDictionary implements Dictionary {
private IndexReader reader;
private String field;
+ /**
+ * Creates a new Dictionary, pulling source terms from
+ * the specified <code>field</code> in the provided <code>reader</code>
+ */
public LuceneDictionary(IndexReader reader, String field) {
this.reader = reader;
this.field = field;
Modified: lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/LuceneLevenshteinDistance.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/LuceneLevenshteinDistance.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/LuceneLevenshteinDistance.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/LuceneLevenshteinDistance.java Fri Sep 21 17:21:34 2012
@@ -38,6 +38,12 @@ import org.apache.lucene.util.IntsRef;
* for merging results from multiple DirectSpellCheckers.
*/
public final class LuceneLevenshteinDistance implements StringDistance {
+
+ /**
+ * Creates a new comparator, mimicing the behavior of Lucene's internal
+ * edit distance.
+ */
+ public LuceneLevenshteinDistance() {}
@Override
public float getDistance(String target, String other) {
Modified: lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/PlainTextDictionary.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/PlainTextDictionary.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/PlainTextDictionary.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/PlainTextDictionary.java Fri Sep 21 17:21:34 2012
@@ -38,10 +38,20 @@ public class PlainTextDictionary impleme
private BufferedReader in;
+ /**
+ * Creates a dictionary based on a File.
+ * <p>
+ * NOTE: content is treated as UTF-8
+ */
public PlainTextDictionary(File file) throws IOException {
in = new BufferedReader(IOUtils.getDecodingReader(file, IOUtils.CHARSET_UTF_8));
}
+ /**
+ * Creates a dictionary based on an inputstream.
+ * <p>
+ * NOTE: content is treated as UTF-8
+ */
public PlainTextDictionary(InputStream dictFile) {
in = new BufferedReader(IOUtils.getDecodingReader(dictFile, IOUtils.CHARSET_UTF_8));
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/SpellChecker.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/SpellChecker.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/SpellChecker.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/SpellChecker.java Fri Sep 21 17:21:34 2012
@@ -58,7 +58,7 @@ import org.apache.lucene.util.Version;
*
* <p>Example Usage:
*
- * <pre>
+ * <pre class="prettyprint">
* SpellChecker spellchecker = new SpellChecker(spellIndexDirectory);
* // To index a field of a user index:
* spellchecker.indexDictionary(new LuceneDictionary(my_lucene_reader, a_field));
@@ -187,6 +187,10 @@ public class SpellChecker implements jav
this.comparator = comparator;
}
+ /**
+ * Gets the comparator in use for ranking suggestions.
+ * @see #setComparator(Comparator)
+ */
public Comparator<SuggestWord> getComparator() {
return comparator;
}
@@ -283,7 +287,7 @@ public class SpellChecker implements jav
*/
public String[] suggestSimilar(String word, int numSug, IndexReader ir,
String field, SuggestMode suggestMode) throws IOException {
- return suggestSimilar(word, numSug, ir, field, suggestMode, this.accuracy);
+ return suggestSimilar(word, numSug, ir, field, suggestMode, this.accuracy);
}
/**
@@ -498,7 +502,7 @@ public class SpellChecker implements jav
final IndexReader reader = searcher.getIndexReader();
if (reader.maxDoc() > 0) {
- for (final AtomicReaderContext ctx : reader.getTopReaderContext().leaves()) {
+ for (final AtomicReaderContext ctx : reader.leaves()) {
Terms terms = ctx.reader().terms(F_WORD);
if (terms != null)
termsEnums.add(terms.iterator(null));
Modified: lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/SuggestWord.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/SuggestWord.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/SuggestWord.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/SuggestWord.java Fri Sep 21 17:21:34 2012
@@ -28,6 +28,11 @@ package org.apache.lucene.search.spell;
public final class SuggestWord{
/**
+ * Creates a new empty suggestion with null text.
+ */
+ public SuggestWord() {}
+
+ /**
* the score of the word
*/
public float score;
Modified: lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/SuggestWordFrequencyComparator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/SuggestWordFrequencyComparator.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/SuggestWordFrequencyComparator.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/SuggestWordFrequencyComparator.java Fri Sep 21 17:21:34 2012
@@ -20,10 +20,16 @@ import java.util.Comparator;
/**
- * Frequency first, then score. Must have
+ * Frequency first, then score.
*
**/
public class SuggestWordFrequencyComparator implements Comparator<SuggestWord> {
+
+ /**
+ * Creates a new comparator that will compare by {@link SuggestWord#freq},
+ * then by {@link SuggestWord#score}, then by {@link SuggestWord#string}.
+ */
+ public SuggestWordFrequencyComparator() {}
public int compare(SuggestWord first, SuggestWord second) {
// first criteria: the frequency
Modified: lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/SuggestWordQueue.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/SuggestWordQueue.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/SuggestWordQueue.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/SuggestWordQueue.java Fri Sep 21 17:21:34 2012
@@ -31,6 +31,10 @@ import java.util.Comparator;
*
*/
public final class SuggestWordQueue extends PriorityQueue<SuggestWord> {
+ /**
+ * Default comparator: score then frequency.
+ * @see SuggestWordScoreComparator
+ */
public static final Comparator<SuggestWord> DEFAULT_COMPARATOR = new SuggestWordScoreComparator();
Modified: lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/SuggestWordScoreComparator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/SuggestWordScoreComparator.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/SuggestWordScoreComparator.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/SuggestWordScoreComparator.java Fri Sep 21 17:21:34 2012
@@ -24,6 +24,13 @@ import java.util.Comparator;
*
**/
public class SuggestWordScoreComparator implements Comparator<SuggestWord> {
+
+ /**
+ * Creates a new comparator that will compare by {@link SuggestWord#score},
+ * then by {@link SuggestWord#freq}, then by {@link SuggestWord#string}.
+ */
+ public SuggestWordScoreComparator() {}
+
public int compare(SuggestWord first, SuggestWord second) {
// first criteria: the distance
if (first.score > second.score) {
Modified: lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/TermFreqIterator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/TermFreqIterator.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/TermFreqIterator.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/TermFreqIterator.java Fri Sep 21 17:21:34 2012
@@ -28,6 +28,7 @@ import org.apache.lucene.util.BytesRefIt
*/
public interface TermFreqIterator extends BytesRefIterator {
+ /** A term's weight, higher numbers mean better suggestions. */
public long weight();
/**
@@ -37,6 +38,10 @@ public interface TermFreqIterator extend
public static class TermFreqIteratorWrapper implements TermFreqIterator {
private BytesRefIterator wrapped;
+ /**
+ * Creates a new wrapper, wrapping the specified iterator and
+ * specifying a weight value of <code>1</code> for all terms.
+ */
public TermFreqIteratorWrapper(BytesRefIterator wrapped) {
this.wrapped = wrapped;
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/WordBreakSpellChecker.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/WordBreakSpellChecker.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/WordBreakSpellChecker.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/spell/WordBreakSpellChecker.java Fri Sep 21 17:21:34 2012
@@ -40,8 +40,19 @@ public class WordBreakSpellChecker {
private int maxChanges = 1;
private int maxEvaluations = 1000;
+ /** Term that can be used to prohibit adjacent terms from being combined */
public static final Term SEPARATOR_TERM = new Term("", "");
+ /**
+ * Creates a new spellchecker with default configuration values
+ * @see #setMaxChanges(int)
+ * @see #setMaxCombineWordLength(int)
+ * @see #setMaxEvaluations(int)
+ * @see #setMinBreakWordLength(int)
+ * @see #setMinSuggestionFrequency(int)
+ */
+ public WordBreakSpellChecker() {}
+
/**
* <p>
* Determines the order to list word break suggestions
@@ -347,22 +358,43 @@ public class WordBreakSpellChecker {
return word;
}
+ /**
+ * Returns the minimum frequency a term must have
+ * to be part of a suggestion.
+ * @see #setMinSuggestionFrequency(int)
+ */
public int getMinSuggestionFrequency() {
return minSuggestionFrequency;
}
+ /**
+ * Returns the maximum length of a combined suggestion
+ * @see #setMaxCombineWordLength(int)
+ */
public int getMaxCombineWordLength() {
return maxCombineWordLength;
}
+ /**
+ * Returns the minimum size of a broken word
+ * @see #setMinBreakWordLength(int)
+ */
public int getMinBreakWordLength() {
return minBreakWordLength;
}
+ /**
+ * Returns the maximum number of changes to perform on the input
+ * @see #setMaxChanges(int)
+ */
public int getMaxChanges() {
return maxChanges;
}
+ /**
+ * Returns the maximum number of word combinations to evaluate.
+ * @see #setMaxEvaluations(int)
+ */
public int getMaxEvaluations() {
return maxEvaluations;
}
@@ -374,7 +406,7 @@ public class WordBreakSpellChecker {
* {@link SuggestMode#SUGGEST_MORE_POPULAR}
* </p>
*
- * @param minSuggestionFrequency
+ * @see #getMinSuggestionFrequency()
*/
public void setMinSuggestionFrequency(int minSuggestionFrequency) {
this.minSuggestionFrequency = minSuggestionFrequency;
@@ -386,7 +418,7 @@ public class WordBreakSpellChecker {
* terms. Default=20
* </p>
*
- * @param maxCombineWordLength
+ * @see #getMaxCombineWordLength()
*/
public void setMaxCombineWordLength(int maxCombineWordLength) {
this.maxCombineWordLength = maxCombineWordLength;
@@ -397,7 +429,7 @@ public class WordBreakSpellChecker {
* The minimum length to break words down to. Default=1
* </p>
*
- * @param minBreakWordLength
+ * @see #getMinBreakWordLength()
*/
public void setMinBreakWordLength(int minBreakWordLength) {
this.minBreakWordLength = minBreakWordLength;
@@ -409,7 +441,7 @@ public class WordBreakSpellChecker {
* original term(s). Default=1
* </p>
*
- * @param maxChanges
+ * @see #getMaxChanges()
*/
public void setMaxChanges(int maxChanges) {
this.maxChanges = maxChanges;
@@ -422,7 +454,7 @@ public class WordBreakSpellChecker {
* performance.
* </p>
*
- * @param maxEvaluations
+ * @see #getMaxEvaluations()
*/
public void setMaxEvaluations(int maxEvaluations) {
this.maxEvaluations = maxEvaluations;
Modified: lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/BufferingTermFreqIteratorWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/BufferingTermFreqIteratorWrapper.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/BufferingTermFreqIteratorWrapper.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/BufferingTermFreqIteratorWrapper.java Fri Sep 21 17:21:34 2012
@@ -29,11 +29,16 @@ import org.apache.lucene.util.BytesRef;
*/
public class BufferingTermFreqIteratorWrapper implements TermFreqIterator {
// TODO keep this for now
+ /** buffered term entries */
protected BytesRefList entries = new BytesRefList();
+ /** current buffer position */
protected int curPos = -1;
+ /** buffered weights, parallel with {@link #entries} */
protected long[] freqs = new long[1];
private final BytesRef spare = new BytesRef();
private final Comparator<BytesRef> comp;
+
+ /** Creates a new iterator, buffering entries from the specified iterator */
public BufferingTermFreqIteratorWrapper(TermFreqIterator source) throws IOException {
this.comp = source.getComparator();
BytesRef spare;
Modified: lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/FileDictionary.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/FileDictionary.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/FileDictionary.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/FileDictionary.java Fri Sep 21 17:21:34 2012
@@ -41,6 +41,11 @@ public class FileDictionary implements D
private String line;
private boolean done = false;
+ /**
+ * Creates a dictionary based on an inputstream.
+ * <p>
+ * NOTE: content is treated as UTF-8
+ */
public FileDictionary(InputStream dictFile) {
in = new BufferedReader(IOUtils.getDecodingReader(dictFile, IOUtils.CHARSET_UTF_8));
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/Lookup.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/Lookup.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/Lookup.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/Lookup.java Fri Sep 21 17:21:34 2012
@@ -37,9 +37,14 @@ public abstract class Lookup {
* Result of a lookup.
*/
public static final class LookupResult implements Comparable<LookupResult> {
+ /** the key's text */
public final CharSequence key;
+ /** the key's weight */
public final long value;
+ /**
+ * Create a new result from a key+weight pair.
+ */
public LookupResult(CharSequence key, long value) {
this.key = key;
this.value = value;
@@ -86,6 +91,9 @@ public abstract class Lookup {
*/
public static final class LookupPriorityQueue extends PriorityQueue<LookupResult> {
// TODO: should we move this out of the interface into a utility class?
+ /**
+ * Creates a new priority queue of the specified size.
+ */
public LookupPriorityQueue(int size) {
super(size);
}
@@ -109,6 +117,12 @@ public abstract class Lookup {
}
}
+ /**
+ * Sole constructor. (For invocation by subclass
+ * constructors, typically implicit.)
+ */
+ public Lookup() {}
+
/** Build lookup from a dictionary. Some implementations may require sorted
* or unsorted keys from the dictionary's iterator - use
* {@link SortedTermFreqIteratorWrapper} or
Modified: lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/SortedTermFreqIteratorWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/SortedTermFreqIteratorWrapper.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/SortedTermFreqIteratorWrapper.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/SortedTermFreqIteratorWrapper.java Fri Sep 21 17:21:34 2012
@@ -47,10 +47,18 @@ public class SortedTermFreqIteratorWrapp
private final BytesRef scratch = new BytesRef();
private final Comparator<BytesRef> comparator;
+ /**
+ * Calls {@link #SortedTermFreqIteratorWrapper(TermFreqIterator, Comparator, boolean)
+ * SortedTermFreqIteratorWrapper(source, comparator, false)}
+ */
public SortedTermFreqIteratorWrapper(TermFreqIterator source, Comparator<BytesRef> comparator) throws IOException {
this(source, comparator, false);
}
+ /**
+ * Creates a new sorted wrapper. if <code>compareRawBytes</code> is true, then
+ * only the bytes (not the weight) will be used for comparison.
+ */
public SortedTermFreqIteratorWrapper(TermFreqIterator source, Comparator<BytesRef> comparator, boolean compareRawBytes) throws IOException {
this.source = source;
this.comparator = comparator;
@@ -162,6 +170,7 @@ public class SortedTermFreqIteratorWrapp
}
}
+ /** encodes an entry (bytes+weight) to the provided writer */
protected void encode(ByteSequencesWriter writer, ByteArrayDataOutput output, byte[] buffer, BytesRef spare, long weight) throws IOException {
if (spare.length + 8 >= buffer.length) {
buffer = ArrayUtil.grow(buffer, spare.length + 8);
@@ -172,6 +181,7 @@ public class SortedTermFreqIteratorWrapp
writer.write(buffer, 0, output.getPosition());
}
+ /** decodes the weight at the current position */
protected long decode(BytesRef scratch, ByteArrayDataInput tmpInput) {
tmpInput.reset(scratch.bytes);
tmpInput.skipBytes(scratch.length - 8); // suggestion + separator
Modified: lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/UnsortedTermFreqIteratorWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/UnsortedTermFreqIteratorWrapper.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/UnsortedTermFreqIteratorWrapper.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/UnsortedTermFreqIteratorWrapper.java Fri Sep 21 17:21:34 2012
@@ -33,6 +33,10 @@ public class UnsortedTermFreqIteratorWra
private final int[] ords;
private int currentOrd = -1;
private final BytesRef spare = new BytesRef();
+ /**
+ * Creates a new iterator, wrapping the specified iterator and
+ * returning elements in a random order.
+ */
public UnsortedTermFreqIteratorWrapper(TermFreqIterator source) throws IOException {
super(source);
ords = new int[entries.size()];
Modified: lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/BytesRefSorter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/BytesRefSorter.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/BytesRefSorter.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/BytesRefSorter.java Fri Sep 21 17:21:34 2012
@@ -47,5 +47,8 @@ public interface BytesRefSorter {
*/
BytesRefIterator iterator() throws IOException;
+ /**
+ * Comparator used to determine the sort order of entries.
+ */
Comparator<BytesRef> getComparator();
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/FSTCompletion.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/FSTCompletion.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/FSTCompletion.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/FSTCompletion.java Fri Sep 21 17:21:34 2012
@@ -42,7 +42,9 @@ public class FSTCompletion {
* A single completion for a given key.
*/
public static final class Completion implements Comparable<Completion> {
+ /** UTF-8 bytes of the suggestion */
public final BytesRef utf8;
+ /** source bucket (weight) of the suggestion */
public final int bucket;
Completion(BytesRef key, int bucket) {
@@ -95,6 +97,7 @@ public class FSTCompletion {
private boolean higherWeightsFirst;
/**
+ * Constructs an FSTCompletion, specifying higherWeightsFirst and exactFirst.
* @param automaton
* Automaton with completions. See {@link FSTCompletionBuilder}.
* @param higherWeightsFirst
Modified: lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/FSTCompletionBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/FSTCompletionBuilder.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/FSTCompletionBuilder.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/FSTCompletionBuilder.java Fri Sep 21 17:21:34 2012
@@ -152,6 +152,7 @@ public class FSTCompletionBuilder {
}
/**
+ * Creates an FSTCompletion with the specified options.
* @param buckets
* The number of buckets for weight discretization. Buckets are used
* in {@link #add(BytesRef, int)} and must be smaller than the number
Modified: lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/FSTCompletionLookup.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/FSTCompletionLookup.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/FSTCompletionLookup.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/FSTCompletionLookup.java Fri Sep 21 17:21:34 2012
@@ -138,9 +138,6 @@ public class FSTCompletionLookup extends
completion.getFST(), true, exactMatchFirst);
}
- /**
- * {@inheritDoc}
- */
@Override
public void build(TermFreqIterator tfit) throws IOException {
File tempInput = File.createTempFile(
@@ -252,6 +249,10 @@ public class FSTCompletionLookup extends
return results;
}
+ /**
+ * Returns the bucket (weight) as a Long for the provided key if it exists,
+ * otherwise null if it does not.
+ */
public Object get(CharSequence key) {
final int bucket = normalCompletion.getBucket(key);
return bucket == -1 ? null : Long.valueOf(bucket);
Modified: lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/InMemorySorter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/InMemorySorter.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/InMemorySorter.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/InMemorySorter.java Fri Sep 21 17:21:34 2012
@@ -33,6 +33,10 @@ public final class InMemorySorter implem
private boolean closed = false;
private final Comparator<BytesRef> comparator;
+ /**
+ * Creates an InMemorySorter, sorting entries by the
+ * provided comparator.
+ */
public InMemorySorter(Comparator<BytesRef> comparator) {
this.comparator = comparator;
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/Sort.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/Sort.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/Sort.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/Sort.java Fri Sep 21 17:21:34 2012
@@ -37,7 +37,9 @@ import org.apache.lucene.util.PriorityQu
* @lucene.internal
*/
public final class Sort {
+ /** Convenience constant for megabytes */
public final static long MB = 1024 * 1024;
+ /** Convenience constant for gigabytes */
public final static long GB = MB * 1024;
/**
@@ -121,15 +123,26 @@ public final class Sort {
* Sort info (debugging mostly).
*/
public class SortInfo {
+ /** number of temporary files created when merging partitions */
public int tempMergeFiles;
+ /** number of partition merges */
public int mergeRounds;
+ /** number of lines of data read */
public int lines;
+ /** time spent merging sorted partitions (in milliseconds) */
public long mergeTime;
+ /** time spent sorting data (in milliseconds) */
public long sortTime;
+ /** total time spent (in milliseconds) */
public long totalTime;
+ /** time spent in i/o read (in milliseconds) */
public long readTime;
+ /** read buffer size (in bytes) */
public final long bufferSize = ramBufferSize.bytes;
+ /** create a new SortInfo (with empty statistics) for debugging */
+ public SortInfo() {}
+
@Override
public String toString() {
return String.format(Locale.ROOT,
@@ -148,6 +161,7 @@ public final class Sort {
private int maxTempFiles;
private final Comparator<BytesRef> comparator;
+ /** Default comparator: sorts in binary (codepoint) order */
public static final Comparator<BytesRef> DEFAULT_COMPARATOR = BytesRef.getUTF8SortedAsUnicodeComparator();
/**
@@ -160,6 +174,12 @@ public final class Sort {
this(DEFAULT_COMPARATOR, BufferSize.automatic(), defaultTempDir(), MAX_TEMPFILES);
}
+ /**
+ * Defaults constructor with a custom comparator.
+ *
+ * @see #defaultTempDir()
+ * @see BufferSize#automatic()
+ */
public Sort(Comparator<BytesRef> comparator) throws IOException {
this(comparator, BufferSize.automatic(), defaultTempDir(), MAX_TEMPFILES);
}
@@ -401,25 +421,41 @@ public final class Sort {
public static class ByteSequencesWriter implements Closeable {
private final DataOutput os;
+ /** Constructs a ByteSequencesWriter to the provided File */
public ByteSequencesWriter(File file) throws IOException {
this(new DataOutputStream(
new BufferedOutputStream(
new FileOutputStream(file))));
}
+ /** Constructs a ByteSequencesWriter to the provided DataOutput */
public ByteSequencesWriter(DataOutput os) {
this.os = os;
}
+ /**
+ * Writes a BytesRef.
+ * @see #write(byte[], int, int)
+ */
public void write(BytesRef ref) throws IOException {
assert ref != null;
write(ref.bytes, ref.offset, ref.length);
}
+ /**
+ * Writes a byte array.
+ * @see #write(byte[], int, int)
+ */
public void write(byte [] bytes) throws IOException {
write(bytes, 0, bytes.length);
}
+ /**
+ * Writes a byte array.
+ * <p>
+ * The length is written as a <code>short</code>, followed
+ * by the bytes.
+ */
public void write(byte [] bytes, int off, int len) throws IOException {
assert bytes != null;
assert off >= 0 && off + len <= bytes.length;
@@ -446,12 +482,14 @@ public final class Sort {
public static class ByteSequencesReader implements Closeable {
private final DataInput is;
+ /** Constructs a ByteSequencesReader from the provided File */
public ByteSequencesReader(File file) throws IOException {
this(new DataInputStream(
new BufferedInputStream(
new FileInputStream(file))));
}
+ /** Constructs a ByteSequencesReader from the provided DataInput */
public ByteSequencesReader(DataInput is) {
this.is = is;
}
@@ -513,6 +551,7 @@ public final class Sort {
}
}
+ /** Returns the comparator in use to sort entries */
public Comparator<BytesRef> getComparator() {
return comparator;
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/WFSTCompletionLookup.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/WFSTCompletionLookup.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/WFSTCompletionLookup.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/WFSTCompletionLookup.java Fri Sep 21 17:21:34 2012
@@ -52,10 +52,9 @@ import org.apache.lucene.util.fst.Util.M
* then walks the <i>n</i> shortest paths to retrieve top-ranked
* suggestions.
* <p>
- * <b>NOTE</b>: Although the {@link TermFreqIterator} API specifies
- * floating point weights, input weights should be whole numbers.
- * Input weights will be cast to a java integer, and any
- * negative, infinite, or NaN values will be rejected.
+ * <b>NOTE</b>:
+ * Input weights must be between 0 and {@link Integer#MAX_VALUE}, any
+ * other values will be rejected.
*
* @see Util#shortestPaths(FST, FST.Arc, Comparator, int)
* @lucene.experimental
Modified: lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/jaspell/JaspellLookup.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/jaspell/JaspellLookup.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/jaspell/JaspellLookup.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/jaspell/JaspellLookup.java Fri Sep 21 17:21:34 2012
@@ -44,6 +44,12 @@ public class JaspellLookup extends Looku
JaspellTernarySearchTrie trie = new JaspellTernarySearchTrie();
private boolean usePrefix = true;
private int editDistance = 2;
+
+ /**
+ * Creates a new empty trie
+ * @see #build(TermFreqIterator)
+ * */
+ public JaspellLookup() {}
@Override
public void build(TermFreqIterator tfit) throws IOException {
@@ -68,12 +74,22 @@ public class JaspellLookup extends Looku
}
}
+ /**
+ * Adds a new node if <code>key</code> already exists,
+ * otherwise replaces its value.
+ * <p>
+ * This method always returns false.
+ */
public boolean add(CharSequence key, Object value) {
trie.put(key, value);
// XXX
return false;
}
+ /**
+ * Returns the value for the specified key, or null
+ * if the key does not exist.
+ */
public Object get(CharSequence key) {
return trie.get(key);
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/jaspell/JaspellTernarySearchTrie.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/jaspell/JaspellTernarySearchTrie.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/jaspell/JaspellTernarySearchTrie.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/jaspell/JaspellTernarySearchTrie.java Fri Sep 21 17:21:34 2012
@@ -160,6 +160,10 @@ public class JaspellTernarySearchTrie {
this(Locale.ROOT);
}
+ /**
+ * Constructs an empty Ternary Search Trie,
+ * specifying the Locale used for lowercasing.
+ */
public JaspellTernarySearchTrie(Locale locale) {
this.locale = locale;
}
Modified: lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/tst/TSTAutocomplete.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/tst/TSTAutocomplete.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/tst/TSTAutocomplete.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/tst/TSTAutocomplete.java Fri Sep 21 17:21:34 2012
@@ -25,6 +25,8 @@ import java.util.*;
* @see TernaryTreeNode
*/
public class TSTAutocomplete {
+
+ TSTAutocomplete() {}
/**
* Inserting keys in TST in the order middle,small,big (lexicographic measure)
Modified: lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/tst/TSTLookup.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/tst/TSTLookup.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/tst/TSTLookup.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/tst/TSTLookup.java Fri Sep 21 17:21:34 2012
@@ -42,6 +42,12 @@ import org.apache.lucene.util.UnicodeUti
public class TSTLookup extends Lookup {
TernaryTreeNode root = new TernaryTreeNode();
TSTAutocomplete autocomplete = new TSTAutocomplete();
+
+ /**
+ * Creates a new TSTLookup with an empty Ternary Search Tree.
+ * @see #build(TermFreqIterator)
+ */
+ public TSTLookup() {}
@Override
public void build(TermFreqIterator tfit) throws IOException {
@@ -65,12 +71,22 @@ public class TSTLookup extends Lookup {
autocomplete.balancedTree(tokens.toArray(), vals.toArray(), 0, tokens.size() - 1, root);
}
+ /**
+ * Adds a new node if <code>key</code> already exists,
+ * otherwise replaces its value.
+ * <p>
+ * This method always returns true.
+ */
public boolean add(CharSequence key, Object value) {
autocomplete.insert(root, key, value, 0);
// XXX we don't know if a new node was created
return true;
}
+ /**
+ * Returns the value for the specified key, or null
+ * if the key does not exist.
+ */
public Object get(CharSequence key) {
List<TernaryTreeNode> list = autocomplete.prefixCompletion(root, key, 0);
if (list == null || list.isEmpty()) {
Modified: lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/tst/TernaryTreeNode.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/tst/TernaryTreeNode.java?rev=1388574&r1=1388573&r2=1388574&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/tst/TernaryTreeNode.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/suggest/src/java/org/apache/lucene/search/suggest/tst/TernaryTreeNode.java Fri Sep 21 17:21:34 2012
@@ -22,21 +22,24 @@ package org.apache.lucene.search.suggest
*/
public class TernaryTreeNode {
+
+ /** Creates a new empty node */
+ public TernaryTreeNode() {}
/** the character stored by a node. */
- char splitchar;
- /** a reference object to the node containing character smaller than this node's character. */
- TernaryTreeNode loKid;
- /**
- * a reference object to the node containing character next to this node's character as
- * occurring in the inserted token.
- */
- TernaryTreeNode eqKid;
- /** a reference object to the node containing character higher than this node's character. */
- TernaryTreeNode hiKid;
- /**
- * used by leaf nodes to store the complete tokens to be added to suggest list while
- * auto-completing the prefix.
- */
- String token;
- Object val;
+ char splitchar;
+ /** a reference object to the node containing character smaller than this node's character. */
+ TernaryTreeNode loKid;
+ /**
+ * a reference object to the node containing character next to this node's character as
+ * occurring in the inserted token.
+ */
+ TernaryTreeNode eqKid;
+ /** a reference object to the node containing character higher than this node's character. */
+ TernaryTreeNode hiKid;
+ /**
+ * used by leaf nodes to store the complete tokens to be added to suggest list while
+ * auto-completing the prefix.
+ */
+ String token;
+ Object val;
}