LUCENE-4464 polygon almost touch test

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1399185 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
David Wayne Smiley 2012-10-17 11:34:24 +00:00
parent cd6c2fe0a2
commit 3634d6e8ae
3 changed files with 82 additions and 2 deletions

File diff suppressed because one or more lines are too long

View File

@ -34,6 +34,7 @@ import org.apache.lucene.search.TopDocs;
import org.apache.lucene.spatial.query.SpatialArgsParser;
import org.junit.Assert;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
@ -109,8 +110,11 @@ public abstract class StrategyTestCase extends SpatialTestCase {
}
protected Iterator<SampleData> getSampleData(String testDataFile) throws IOException {
return new SampleDataReader(
getClass().getClassLoader().getResourceAsStream("data/"+testDataFile) );
String path = "data/" + testDataFile;
InputStream stream = getClass().getClassLoader().getResourceAsStream(path);
if (stream == null)
throw new FileNotFoundException("classpath resource not found: "+path);
return new SampleDataReader(stream);
}
protected Iterator<SpatialTestQuery> getTestQueries(String testQueryFile, SpatialContext ctx) throws IOException {

View File

@ -0,0 +1,73 @@
package org.apache.lucene.spatial.prefix;
/*
* 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.SpatialContextFactory;
import com.spatial4j.core.shape.Shape;
import org.apache.lucene.spatial.StrategyTestCase;
import org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree;
import org.apache.lucene.spatial.query.SpatialArgs;
import org.apache.lucene.spatial.query.SpatialOperation;
import org.junit.Test;
import java.io.IOException;
import java.util.HashMap;
public class JtsPolygonTest extends StrategyTestCase {
private static final double LUCENE_4464_distErrPct = SpatialArgs.DEFAULT_DISTERRPCT;//DEFAULT 2.5%
public JtsPolygonTest() {
try {
HashMap<String, String> args = new HashMap<String, String>();
args.put("spatialContextFactory",
"com.spatial4j.core.context.jts.JtsSpatialContextFactory");
ctx = SpatialContextFactory.makeSpatialContext(args, getClass().getClassLoader());
} catch (NoClassDefFoundError e) {
assumeTrue("This test requires JTS jar: "+e, false);
}
GeohashPrefixTree grid = new GeohashPrefixTree(ctx, 11);//< 1 meter == 11 maxLevels
this.strategy = new RecursivePrefixTreeStrategy(grid, getClass().getSimpleName());
((RecursivePrefixTreeStrategy)this.strategy).setDistErrPct(LUCENE_4464_distErrPct);//1% radius (small!)
}
@Test
/** LUCENE-4464 */
public void testCloseButNoMatch() throws IOException {
getAddAndVerifyIndexedDocuments("LUCENE-4464.txt");
SpatialArgs args = q(
"POLYGON((-93.18100824442227 45.25676372469945," +
"-93.23182001200654 45.21421290799412," +
"-93.16315546122038 45.23742639412364," +
"-93.18100824442227 45.25676372469945))",
LUCENE_4464_distErrPct);
SearchResults got = executeQuery(strategy.makeQuery(args), 100);
assertEquals(1, got.numFound);
assertEquals("poly2", got.results.get(0).document.get("id"));
//did not find poly 1 !
}
private SpatialArgs q(String shapeStr, double distErrPct) {
Shape shape = ctx.readShape(shapeStr);
SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, shape);
args.setDistErrPct(distErrPct);
return args;
}
}