Author: synhershko
Date: Mon Aug 20 21:56:13 2012
New Revision: 1375266
URL: http://svn.apache.org/viewvc?rev=1375266&view=rev
Log:
Catching up tests
Added:
incubator/lucene.net/trunk/test/contrib/Spatial/BBox/
incubator/lucene.net/trunk/test/contrib/Spatial/BBox/TestBBoxStrategy.cs
- copied, changed from r1375265, incubator/lucene.net/trunk/test/contrib/Spatial/Vector/BaseTwoDoublesStrategyTestCase.cs
incubator/lucene.net/trunk/test/contrib/Spatial/Compatibility/TermsFilterTest.cs
incubator/lucene.net/trunk/test/contrib/Spatial/Contrib.Spatial.Tests.csproj
- copied, changed from r1375265, incubator/lucene.net/trunk/test/contrib/Spatial/Contrib.Spatial.Test.csproj
Removed:
incubator/lucene.net/trunk/test/contrib/Spatial/Contrib.Spatial.Test.csproj
incubator/lucene.net/trunk/test/contrib/Spatial/Prefix/BaseRecursivePrefixTreeStrategyTestCase.cs
incubator/lucene.net/trunk/test/contrib/Spatial/Vector/BaseTwoDoublesStrategyTestCase.cs
Modified:
incubator/lucene.net/trunk/build/vs2010/test/Contrib.Spatial.Test.sln
incubator/lucene.net/trunk/test/contrib/Spatial/Prefix/TestRecursivePrefixTreeStrategy.cs
incubator/lucene.net/trunk/test/contrib/Spatial/Prefix/TestTermQueryPrefixGridStrategy.cs
incubator/lucene.net/trunk/test/contrib/Spatial/Prefix/Tree/SpatialPrefixTreeTest.cs
incubator/lucene.net/trunk/test/contrib/Spatial/StrategyTestCase.cs
incubator/lucene.net/trunk/test/contrib/Spatial/Various.cs
incubator/lucene.net/trunk/test/contrib/Spatial/Vector/TestTwoDoublesStrategy.cs
Modified: incubator/lucene.net/trunk/build/vs2010/test/Contrib.Spatial.Test.sln
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/build/vs2010/test/Contrib.Spatial.Test.sln?rev=1375266&r1=1375265&r2=1375266&view=diff
==============================================================================
--- incubator/lucene.net/trunk/build/vs2010/test/Contrib.Spatial.Test.sln (original)
+++ incubator/lucene.net/trunk/build/vs2010/test/Contrib.Spatial.Test.sln Mon Aug 20 21:56:13
2012
@@ -1,44 +1,44 @@

-Microsoft Visual Studio Solution File, Format Version 11.00
-# Visual C# Express 2010
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lucene.Net", "..\..\..\src\core\Lucene.Net.csproj",
"{5D4AD9BE-1FFB-41AB-9943-25737971BF57}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contrib.Spatial", "..\..\..\src\contrib\Spatial\Contrib.Spatial.csproj",
"{35C347F4-24B2-4BE5-8117-A0E3001551CE}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contrib.Spatial.Test", "..\..\..\test\contrib\Spatial\Contrib.Spatial.Test.csproj",
"{19FC2A6B-4DE9-403F-8CEF-10850F57B96E}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contrib.Spatial.Tests", "..\..\..\test\contrib\Spatial\Contrib.Spatial.Tests.csproj",
"{19FC2A6B-4DE9-403F-8CEF-10850F57B96E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug35|Any CPU = Debug35|Any CPU
Debug|Any CPU = Debug|Any CPU
- Release35|Any CPU = Release35|Any CPU
+ Debug35|Any CPU = Debug35|Any CPU
Release|Any CPU = Release|Any CPU
+ Release35|Any CPU = Release35|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {19FC2A6B-4DE9-403F-8CEF-10850F57B96E}.Debug35|Any CPU.ActiveCfg = Debug35|Any CPU
- {19FC2A6B-4DE9-403F-8CEF-10850F57B96E}.Debug35|Any CPU.Build.0 = Debug35|Any CPU
- {19FC2A6B-4DE9-403F-8CEF-10850F57B96E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {19FC2A6B-4DE9-403F-8CEF-10850F57B96E}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {19FC2A6B-4DE9-403F-8CEF-10850F57B96E}.Release35|Any CPU.ActiveCfg = Release35|Any CPU
- {19FC2A6B-4DE9-403F-8CEF-10850F57B96E}.Release35|Any CPU.Build.0 = Release35|Any CPU
- {19FC2A6B-4DE9-403F-8CEF-10850F57B96E}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {19FC2A6B-4DE9-403F-8CEF-10850F57B96E}.Release|Any CPU.Build.0 = Release|Any CPU
- {35C347F4-24B2-4BE5-8117-A0E3001551CE}.Debug35|Any CPU.ActiveCfg = Debug35|Any CPU
- {35C347F4-24B2-4BE5-8117-A0E3001551CE}.Debug35|Any CPU.Build.0 = Debug35|Any CPU
- {35C347F4-24B2-4BE5-8117-A0E3001551CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {35C347F4-24B2-4BE5-8117-A0E3001551CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {35C347F4-24B2-4BE5-8117-A0E3001551CE}.Release35|Any CPU.ActiveCfg = Release35|Any CPU
- {35C347F4-24B2-4BE5-8117-A0E3001551CE}.Release35|Any CPU.Build.0 = Release35|Any CPU
- {35C347F4-24B2-4BE5-8117-A0E3001551CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {35C347F4-24B2-4BE5-8117-A0E3001551CE}.Release|Any CPU.Build.0 = Release|Any CPU
- {5D4AD9BE-1FFB-41AB-9943-25737971BF57}.Debug35|Any CPU.ActiveCfg = Debug35|Any CPU
- {5D4AD9BE-1FFB-41AB-9943-25737971BF57}.Debug35|Any CPU.Build.0 = Debug35|Any CPU
{5D4AD9BE-1FFB-41AB-9943-25737971BF57}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5D4AD9BE-1FFB-41AB-9943-25737971BF57}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {5D4AD9BE-1FFB-41AB-9943-25737971BF57}.Release35|Any CPU.ActiveCfg = Release35|Any CPU
- {5D4AD9BE-1FFB-41AB-9943-25737971BF57}.Release35|Any CPU.Build.0 = Release35|Any CPU
+ {5D4AD9BE-1FFB-41AB-9943-25737971BF57}.Debug35|Any CPU.ActiveCfg = Debug35|Any CPU
+ {5D4AD9BE-1FFB-41AB-9943-25737971BF57}.Debug35|Any CPU.Build.0 = Debug35|Any CPU
{5D4AD9BE-1FFB-41AB-9943-25737971BF57}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5D4AD9BE-1FFB-41AB-9943-25737971BF57}.Release|Any CPU.Build.0 = Release|Any CPU
+ {5D4AD9BE-1FFB-41AB-9943-25737971BF57}.Release35|Any CPU.ActiveCfg = Release35|Any CPU
+ {5D4AD9BE-1FFB-41AB-9943-25737971BF57}.Release35|Any CPU.Build.0 = Release35|Any CPU
+ {35C347F4-24B2-4BE5-8117-A0E3001551CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {35C347F4-24B2-4BE5-8117-A0E3001551CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {35C347F4-24B2-4BE5-8117-A0E3001551CE}.Debug35|Any CPU.ActiveCfg = Debug35|Any CPU
+ {35C347F4-24B2-4BE5-8117-A0E3001551CE}.Debug35|Any CPU.Build.0 = Debug35|Any CPU
+ {35C347F4-24B2-4BE5-8117-A0E3001551CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {35C347F4-24B2-4BE5-8117-A0E3001551CE}.Release|Any CPU.Build.0 = Release|Any CPU
+ {35C347F4-24B2-4BE5-8117-A0E3001551CE}.Release35|Any CPU.ActiveCfg = Release35|Any CPU
+ {35C347F4-24B2-4BE5-8117-A0E3001551CE}.Release35|Any CPU.Build.0 = Release35|Any CPU
+ {19FC2A6B-4DE9-403F-8CEF-10850F57B96E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {19FC2A6B-4DE9-403F-8CEF-10850F57B96E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {19FC2A6B-4DE9-403F-8CEF-10850F57B96E}.Debug35|Any CPU.ActiveCfg = Debug35|Any CPU
+ {19FC2A6B-4DE9-403F-8CEF-10850F57B96E}.Debug35|Any CPU.Build.0 = Debug35|Any CPU
+ {19FC2A6B-4DE9-403F-8CEF-10850F57B96E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {19FC2A6B-4DE9-403F-8CEF-10850F57B96E}.Release|Any CPU.Build.0 = Release|Any CPU
+ {19FC2A6B-4DE9-403F-8CEF-10850F57B96E}.Release35|Any CPU.ActiveCfg = Release35|Any CPU
+ {19FC2A6B-4DE9-403F-8CEF-10850F57B96E}.Release35|Any CPU.Build.0 = Release35|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Copied: incubator/lucene.net/trunk/test/contrib/Spatial/BBox/TestBBoxStrategy.cs (from r1375265,
incubator/lucene.net/trunk/test/contrib/Spatial/Vector/BaseTwoDoublesStrategyTestCase.cs)
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/contrib/Spatial/BBox/TestBBoxStrategy.cs?p2=incubator/lucene.net/trunk/test/contrib/Spatial/BBox/TestBBoxStrategy.cs&p1=incubator/lucene.net/trunk/test/contrib/Spatial/Vector/BaseTwoDoublesStrategyTestCase.cs&r1=1375265&r2=1375266&rev=1375266&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/contrib/Spatial/Vector/BaseTwoDoublesStrategyTestCase.cs
(original)
+++ incubator/lucene.net/trunk/test/contrib/Spatial/BBox/TestBBoxStrategy.cs Mon Aug 20 21:56:13
2012
@@ -15,31 +15,44 @@
* limitations under the License.
*/
-using Lucene.Net.Search;
-using Lucene.Net.Spatial.Util;
-using Lucene.Net.Spatial.Vector;
-using NUnit.Framework;
+using Lucene.Net.Spatial.BBox;
using Spatial4n.Core.Context;
+using NUnit.Framework;
-namespace Lucene.Net.Contrib.Spatial.Test.Vector
+namespace Lucene.Net.Contrib.Spatial.Test.BBox
{
- public abstract class BaseTwoDoublesStrategyTestCase : StrategyTestCase
+ public class TestBBoxStrategy : StrategyTestCase
{
- protected abstract SpatialContext getSpatialContext();
-
[SetUp]
public override void SetUp()
{
base.SetUp();
- this.ctx = getSpatialContext();
- this.strategy = new TwoDoublesStrategy(ctx,
- new NumericFieldInfo(), FieldCache_Fields.NUMERIC_UTILS_DOUBLE_PARSER);
+ this.ctx = SpatialContext.GEO_KM;
+ this.strategy = new BBoxStrategy(ctx, "bbox");
+ }
+
+ [Test]
+ public void testBasicOperaions()
+ {
+ getAddAndVerifyIndexedDocuments(DATA_SIMPLE_BBOX);
+
+ executeQueries(SpatialMatchConcern.EXACT, QTEST_Simple_Queries_BBox);
+ }
+
+ [Test]
+ public void testStatesBBox()
+ {
+ getAddAndVerifyIndexedDocuments(DATA_STATES_BBOX);
+
+ executeQueries(SpatialMatchConcern.FILTER, QTEST_States_IsWithin_BBox);
+ executeQueries(SpatialMatchConcern.FILTER, QTEST_States_Intersects_BBox);
}
[Test]
public void testCitiesWithinBBox()
{
getAddAndVerifyIndexedDocuments(DATA_WORLD_CITIES_POINTS);
+
executeQueries(SpatialMatchConcern.FILTER, QTEST_Cities_IsWithin_BBox);
}
}
Added: incubator/lucene.net/trunk/test/contrib/Spatial/Compatibility/TermsFilterTest.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/contrib/Spatial/Compatibility/TermsFilterTest.cs?rev=1375266&view=auto
==============================================================================
--- incubator/lucene.net/trunk/test/contrib/Spatial/Compatibility/TermsFilterTest.cs (added)
+++ incubator/lucene.net/trunk/test/contrib/Spatial/Compatibility/TermsFilterTest.cs Mon Aug
20 21:56:13 2012
@@ -0,0 +1,109 @@
+using System;
+using System.Collections.Generic;
+using Lucene.Net.Analysis;
+using Lucene.Net.Documents;
+using Lucene.Net.Index;
+using Lucene.Net.Search;
+using Lucene.Net.Spatial.Util;
+using Lucene.Net.Store;
+using Lucene.Net.Util;
+using NUnit.Framework;
+
+namespace Lucene.Net.Contrib.Spatial.Test.Compatibility
+{
+ public class TermsFilterTest : LuceneTestCase
+ {
+ [Test]
+ public void testCachability()
+ {
+ TermsFilter a = new TermsFilter();
+ a.AddTerm(new Term("field1", "a"));
+ a.AddTerm(new Term("field1", "b"));
+ HashSet<Filter> cachedFilters = new HashSet<Filter>();
+ cachedFilters.Add(a);
+ TermsFilter b = new TermsFilter();
+ b.AddTerm(new Term("field1", "a"));
+ b.AddTerm(new Term("field1", "b"));
+
+ Assert.True(cachedFilters.Contains(b), "Must be cached");
+ b.AddTerm(new Term("field1", "a")); //duplicate term
+ Assert.True(cachedFilters.Contains(b), "Must be cached");
+ b.AddTerm(new Term("field1", "c"));
+ Assert.False(cachedFilters.Contains(b), "Must not be cached");
+ }
+
+ [Test]
+ public void testMissingTerms()
+ {
+ String fieldName = "field1";
+ Directory rd = new RAMDirectory();
+ var w = new IndexWriter(rd, new KeywordAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
+ for (int i = 0; i < 100; i++)
+ {
+ var doc = new Document();
+ int term = i*10; //terms are units of 10;
+ doc.Add(new Field(fieldName, "" + term, Field.Store.YES, Field.Index.ANALYZED));
+ w.AddDocument(doc);
+ }
+ IndexReader reader = w.GetReader();
+ w.Close();
+
+ TermsFilter tf = new TermsFilter();
+ tf.AddTerm(new Term(fieldName, "19"));
+ FixedBitSet bits = (FixedBitSet) tf.GetDocIdSet(reader);
+ Assert.AreEqual(0, bits.Cardinality(), "Must match nothing");
+
+ tf.AddTerm(new Term(fieldName, "20"));
+ bits = (FixedBitSet) tf.GetDocIdSet(reader);
+ Assert.AreEqual(1, bits.Cardinality(), "Must match 1");
+
+ tf.AddTerm(new Term(fieldName, "10"));
+ bits = (FixedBitSet) tf.GetDocIdSet(reader);
+ Assert.AreEqual(2, bits.Cardinality(), "Must match 2");
+
+ tf.AddTerm(new Term(fieldName, "00"));
+ bits = (FixedBitSet) tf.GetDocIdSet(reader);
+ Assert.AreEqual(2, bits.Cardinality(), "Must match 2");
+
+ reader.Close();
+ rd.Close();
+ }
+
+ // [Test]
+ // public void testMissingField()
+ // {
+ // String fieldName = "field1";
+ // Directory rd1 = new RAMDirectory();
+ // var w1 = new IndexWriter(rd1, new KeywordAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
+ // var doc = new Document();
+ // doc.Add(new Field(fieldName, "content1", Field.Store.YES, Field.Index.ANALYZED));
+ // w1.AddDocument(doc);
+ // IndexReader reader1 = w1.GetReader();
+ // w1.Close();
+
+ // fieldName = "field2";
+ // Directory rd2 = new RAMDirectory();
+ // var w2 = new IndexWriter(rd2, new KeywordAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
+ // doc = new Document();
+ // doc.Add(new Field(fieldName, "content2", Field.Store.YES, Field.Index.ANALYZED));
+ // w2.AddDocument(doc);
+ // IndexReader reader2 = w2.GetReader();
+ // w2.Close();
+
+ // TermsFilter tf = new TermsFilter();
+ // tf.AddTerm(new Term(fieldName, "content1"));
+
+ // MultiReader multi = new MultiReader(reader1, reader2);
+ // foreach (var reader in multi.Leaves())
+ // {
+ // FixedBitSet bits = (FixedBitSet) tf.GetDocIdSet(reader);
+ // Assert.True(bits.Cardinality() >= 0, "Must be >= 0");
+ // }
+ // multi.Close();
+ // reader1.Close();
+ // reader2.Close();
+ // rd1.Close();
+ // rd2.Close();
+ // }
+ }
+}
Copied: incubator/lucene.net/trunk/test/contrib/Spatial/Contrib.Spatial.Tests.csproj (from
r1375265, incubator/lucene.net/trunk/test/contrib/Spatial/Contrib.Spatial.Test.csproj)
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/contrib/Spatial/Contrib.Spatial.Tests.csproj?p2=incubator/lucene.net/trunk/test/contrib/Spatial/Contrib.Spatial.Tests.csproj&p1=incubator/lucene.net/trunk/test/contrib/Spatial/Contrib.Spatial.Test.csproj&r1=1375265&r2=1375266&rev=1375266&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/contrib/Spatial/Contrib.Spatial.Test.csproj (original)
+++ incubator/lucene.net/trunk/test/contrib/Spatial/Contrib.Spatial.Tests.csproj Mon Aug 20
21:56:13 2012
@@ -118,7 +118,8 @@
<Compile Include="..\..\core\Util\Paths.cs">
<Link>Paths.cs</Link>
</Compile>
- <Compile Include="Prefix\BaseRecursivePrefixTreeStrategyTestCase.cs" />
+ <Compile Include="BBox\TestBBoxStrategy.cs" />
+ <Compile Include="Compatibility\TermsFilterTest.cs" />
<Compile Include="Prefix\TestRecursivePrefixTreeStrategy.cs" />
<Compile Include="Prefix\TestTermQueryPrefixGridStrategy.cs" />
<Compile Include="Prefix\Tree\SpatialPrefixTreeTest.cs" />
@@ -130,7 +131,6 @@
<Compile Include="StrategyTestCase.cs" />
<Compile Include="TestTestFramework.cs" />
<Compile Include="Various.cs" />
- <Compile Include="Vector\BaseTwoDoublesStrategyTestCase.cs" />
<Compile Include="Vector\TestTwoDoublesStrategy.cs" />
</ItemGroup>
<ItemGroup>
@@ -165,9 +165,7 @@
<Name>Lucene.Net</Name>
</ProjectReference>
</ItemGroup>
- <ItemGroup>
- <Folder Include="Compatibility\" />
- </ItemGroup>
+ <ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and
uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Modified: incubator/lucene.net/trunk/test/contrib/Spatial/Prefix/TestRecursivePrefixTreeStrategy.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/contrib/Spatial/Prefix/TestRecursivePrefixTreeStrategy.cs?rev=1375266&r1=1375265&r2=1375266&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/contrib/Spatial/Prefix/TestRecursivePrefixTreeStrategy.cs
(original)
+++ incubator/lucene.net/trunk/test/contrib/Spatial/Prefix/TestRecursivePrefixTreeStrategy.cs
Mon Aug 20 21:56:13 2012
@@ -15,21 +15,188 @@
* limitations under the License.
*/
+using System;
+using System.Collections.Generic;
+using Lucene.Net.Documents;
+using Lucene.Net.Spatial.Prefix;
+using Lucene.Net.Spatial.Prefix.Tree;
+using Lucene.Net.Spatial.Queries;
+using Lucene.Net.Spatial.Util;
using NUnit.Framework;
using Spatial4n.Core.Context;
+using Spatial4n.Core.Distance;
+using Spatial4n.Core.Shapes;
+using Spatial4n.Core.Shapes.Impl;
+using Spatial4n.Core.Util;
namespace Lucene.Net.Contrib.Spatial.Test.Prefix
{
- public class TestRecursivePrefixTreeStrategy : BaseRecursivePrefixTreeStrategyTestCase
+ public class TestRecursivePrefixTreeStrategy : StrategyTestCase
{
- [SetUp]
- public override void SetUp()
+ private int maxLength;
+
+ //Tests should call this first.
+ private void init(int maxLength)
+ {
+ this.maxLength = maxLength;
+ this.ctx = SpatialContext.GEO_KM;
+ var grid = new GeohashPrefixTree(ctx, maxLength);
+ this.strategy = new RecursivePrefixTreeStrategy(grid, GetType().Name);
+ }
+
+ [Test]
+ public void testFilterWithVariableScanLevel()
+ {
+ getAddAndVerifyIndexedDocuments(DATA_WORLD_CITIES_POINTS);
+
+ //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);
+ }
+ }
+
+ [Test]
+ public void geohashRecursiveRandom()
+ {
+ init(12);
+ var random = NewRandom();
+
+ //1. Iterate test with the cluster at some worldly point of interest
+ var clusterCenters = new Point[] { new PointImpl(0, 0), new PointImpl(0, 90), new PointImpl(0,
-90) };
+ foreach (Point clusterCenter in 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.IsTrue(smallDegrees < 1);
+ const double largeDegrees = 20d; //good large size; don't use >=45 for this test code
to work
+ double[] sideDegrees = { largeDegrees, smallDegrees };
+ foreach (double sideDegree in sideDegrees)
+ {
+ //3. Index random points in this cluster box
+ deleteAll();
+ var points = new List<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();
+ Point pt = normPointXY(x, y);
+ 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.
+ foreach (double qcXoff in new double[] { sideDegree, -sideDegree })
+ {//query-center X offset from cluster center
+ foreach (double qcYoff in 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.Count, 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.Count];
+ int ids_sz = 0;
+ for (int i = 0; i < points.Count; i++)
+ {
+ Point point = points[i];
+ if (ctx.GetDistCalc().Distance(queryCenter, point) <= queryDist)
+ ids[ids_sz++] = i;
+ }
+
+ var ids_new = new int[ids_sz]; // will pad with 0's if larger
+ Array.Copy(ids, ids_new, ids_sz);
+ ids = ids_new;
+ //assert ids_sz > 0 (can't because randomness keeps us from being able to)
+
+ checkHits(queryCenter, queryDist, ids.Length, ids);
+ }
+ }
+
+ }//for sideDegree
+
+ }//for clusterCenter
+
+ }//randomTest()
+
+ //TODO can we use super.runTestQueries() ?
+ private void checkHits(Point pt, double dist, int assertNumFound, int[] assertIds)
{
- base.SetUp();
+ Shape shape = ctx.MakeCircle(pt, dist);
+ SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, shape);
+ args.SetDistPrecision(0.0);
+ SearchResults got = executeQuery(strategy.MakeQuery(args), 100);
+ Assert.AreEqual(assertNumFound, got.numFound, "" + shape);
+ if (assertIds != null)
+ {
+ var gotIds = new HashSet<int>();
+ foreach (SearchResult result in got.results)
+ {
+ gotIds.Add(int.Parse(result.document.Get("id")));
+ }
+ foreach (int assertId in assertIds)
+ {
+ Assert.True(gotIds.Contains(assertId), "has " + assertId);
+ }
+ }
}
- protected override SpatialContext getSpatialContext()
+
+ //
+ private Document newDoc(String id, Shape shape)
{
- return SpatialContext.GEO_KM;
+ Document doc = new Document();
+ doc.Add(new Field("id", id, Field.Store.YES, Field.Index.ANALYZED));
+ foreach (var f in strategy.CreateIndexableFields(shape))
+ {
+ doc.Add(f);
+ }
+ if (storeShape)
+ doc.Add(new Field(strategy.GetFieldName(), ctx.ToString(shape), Field.Store.YES, Field.Index.ANALYZED));
+ return doc;
}
+
+ private double[] calcDistRange(Point startPoint, Point targetCenter, double targetSideDegrees)
+ {
+ double min = Double.MaxValue;
+ double max = Double.MinValue;
+ foreach (double xLen in new double[] { targetSideDegrees, -targetSideDegrees })
+ {
+ foreach (double yLen in 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, DistanceUtils.ToRadians(x) };
+ DistanceUtils.NormLatRAD(latLon);
+ DistanceUtils.NormLatRAD(latLon);
+ double x2 = DistanceUtils.ToDegrees(latLon[1]);
+ double y2 = DistanceUtils.ToDegrees(latLon[0]);
+ //overwrite latLon, units is now degrees
+
+ return GeohashUtils.Decode(GeohashUtils.EncodeLatLon(y2, x2, maxLength), ctx);
+ }
+
}
}
Modified: incubator/lucene.net/trunk/test/contrib/Spatial/Prefix/TestTermQueryPrefixGridStrategy.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/contrib/Spatial/Prefix/TestTermQueryPrefixGridStrategy.cs?rev=1375266&r1=1375265&r2=1375266&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/contrib/Spatial/Prefix/TestTermQueryPrefixGridStrategy.cs
(original)
+++ incubator/lucene.net/trunk/test/contrib/Spatial/Prefix/TestTermQueryPrefixGridStrategy.cs
Mon Aug 20 21:56:13 2012
@@ -17,12 +17,11 @@
using System.Collections.Generic;
using Lucene.Net.Documents;
-using Lucene.Net.Spatial;
using Lucene.Net.Spatial.Prefix;
using Lucene.Net.Spatial.Prefix.Tree;
+using Lucene.Net.Spatial.Queries;
using NUnit.Framework;
using Spatial4n.Core.Context;
-using Spatial4n.Core.Query;
using Spatial4n.Core.Shapes;
using Spatial4n.Core.Shapes.Impl;
@@ -33,15 +32,18 @@ namespace Lucene.Net.Contrib.Spatial.Tes
[Test]
public void testNGramPrefixGridLosAngeles()
{
- SimpleSpatialFieldInfo fieldInfo = new SimpleSpatialFieldInfo("geo");
SpatialContext ctx = SpatialContext.GEO_KM;
- TermQueryPrefixTreeStrategy prefixGridStrategy = new TermQueryPrefixTreeStrategy(new QuadPrefixTree(ctx));
+ TermQueryPrefixTreeStrategy prefixGridStrategy = new TermQueryPrefixTreeStrategy(new QuadPrefixTree(ctx),
"geo");
Shape point = new PointImpl(-118.243680, 34.052230);
Document losAngeles = new Document();
losAngeles.Add(new Field("name", "Los Angeles", Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
- losAngeles.Add(prefixGridStrategy.CreateField(fieldInfo, point, true, true));
+ foreach (var indexableField in prefixGridStrategy.CreateIndexableFields(point))
+ {
+ losAngeles.Add(indexableField);
+ }
+ losAngeles.Add(new Field(prefixGridStrategy.GetFieldName(), ctx.ToString(point), Field.Store.YES,
Field.Index.NO));
addDocumentsAndCommit(new List<Document> { losAngeles });
Modified: incubator/lucene.net/trunk/test/contrib/Spatial/Prefix/Tree/SpatialPrefixTreeTest.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/contrib/Spatial/Prefix/Tree/SpatialPrefixTreeTest.cs?rev=1375266&r1=1375265&r2=1375266&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/contrib/Spatial/Prefix/Tree/SpatialPrefixTreeTest.cs (original)
+++ incubator/lucene.net/trunk/test/contrib/Spatial/Prefix/Tree/SpatialPrefixTreeTest.cs Mon
Aug 20 21:56:13 2012
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-using System.Collections.Generic;
using Lucene.Net.Spatial.Prefix.Tree;
using Lucene.Net.Util;
using NUnit.Framework;
Modified: incubator/lucene.net/trunk/test/contrib/Spatial/StrategyTestCase.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/contrib/Spatial/StrategyTestCase.cs?rev=1375266&r1=1375265&r2=1375266&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/contrib/Spatial/StrategyTestCase.cs (original)
+++ incubator/lucene.net/trunk/test/contrib/Spatial/StrategyTestCase.cs Mon Aug 20 21:56:13
2012
@@ -31,6 +31,7 @@ namespace Lucene.Net.Contrib.Spatial.Tes
{
public abstract class StrategyTestCase : SpatialTestCase
{
+ public static readonly String DATA_SIMPLE_BBOX = "simple-bbox.txt";
public static readonly String DATA_STATES_POLY = "states-poly.txt";
public static readonly String DATA_STATES_BBOX = "states-bbox.txt";
public static readonly String DATA_COUNTRIES_POLY = "countries-poly.txt";
@@ -39,8 +40,8 @@ namespace Lucene.Net.Contrib.Spatial.Tes
public static readonly String QTEST_States_IsWithin_BBox = "states-IsWithin-BBox.txt";
public static readonly String QTEST_States_Intersects_BBox = "states-Intersects-BBox.txt";
-
public static readonly String QTEST_Cities_IsWithin_BBox = "cities-IsWithin-BBox.txt";
+ public static readonly String QTEST_Simple_Queries_BBox = "simple-Queries-BBox.txt";
//private Logger log = Logger.getLogger(getClass().getName());
@@ -78,12 +79,9 @@ namespace Lucene.Net.Contrib.Spatial.Tes
document.Add(new Field("id", data.id, Field.Store.YES, Field.Index.ANALYZED));
document.Add(new Field("name", data.name, Field.Store.YES, Field.Index.ANALYZED));
Shape shape = ctx.ReadShape(data.shape);
- foreach (var f in strategy.CreateFields(shape))
+ foreach (var f in strategy.CreateIndexableFields(shape))
{
- if (f != null)
- { // null if incompatibleGeometry && ignore
- document.Add(f);
- }
+ document.Add(f);
}
if (storeShape)
document.Add(strategy.CreateStoredField(shape));
@@ -118,7 +116,7 @@ namespace Lucene.Net.Contrib.Spatial.Tes
if (storeShape && got.numFound > 0)
{
//check stored value is there & parses
- Assert.NotNull(ctx.ReadShape(got.results.Get(0).document.get(strategy.GetFieldName())));
+ Assert.NotNull(ctx.ReadShape(got.results[0].document.Get(strategy.GetFieldName())));
}
if (concern.orderIsImportant)
{
Modified: incubator/lucene.net/trunk/test/contrib/Spatial/Various.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/contrib/Spatial/Various.cs?rev=1375266&r1=1375265&r2=1375266&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/contrib/Spatial/Various.cs (original)
+++ incubator/lucene.net/trunk/test/contrib/Spatial/Various.cs Mon Aug 20 21:56:13 2012
@@ -20,8 +20,6 @@
*/
using System;
-using System.IO;
-using System.Linq;
using Lucene.Net.Analysis;
using Lucene.Net.Documents;
using Lucene.Net.Index;
@@ -29,11 +27,11 @@ using Lucene.Net.Search;
using Lucene.Net.Spatial;
using Lucene.Net.Spatial.Prefix;
using Lucene.Net.Spatial.Prefix.Tree;
+using Lucene.Net.Spatial.Queries;
using Lucene.Net.Store;
using NUnit.Framework;
using Spatial4n.Core.Context;
using Spatial4n.Core.Distance;
-using Spatial4n.Core.Query;
using Spatial4n.Core.Shapes;
using Directory = Lucene.Net.Store.Directory;
@@ -45,8 +43,7 @@ namespace Lucene.Net.Contrib.Spatial.Tes
private Directory _directory;
private IndexSearcher _searcher;
private IndexWriter _writer;
- protected SpatialStrategy<SimpleSpatialFieldInfo> strategy;
- protected SimpleSpatialFieldInfo fieldInfo;
+ protected SpatialStrategy strategy;
protected readonly SpatialContext ctx = SpatialContext.GEO_KM;
protected readonly bool storeShape = true;
private int maxLength;
@@ -55,8 +52,7 @@ namespace Lucene.Net.Contrib.Spatial.Tes
protected void SetUp()
{
maxLength = GeohashPrefixTree.GetMaxLevelsPossible();
- fieldInfo = new SimpleSpatialFieldInfo(GetType().Name);
- strategy = new RecursivePrefixTreeStrategy(new GeohashPrefixTree(ctx, maxLength));
+ strategy = new RecursivePrefixTreeStrategy(new GeohashPrefixTree(ctx, maxLength), GetType().Name);
_directory = new RAMDirectory();
_writer = new IndexWriter(_directory, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED);
@@ -67,13 +63,11 @@ namespace Lucene.Net.Contrib.Spatial.Tes
var doc = new Document();
doc.Add(new Field("name", name, Field.Store.YES, Field.Index.ANALYZED));
Shape shape = ctx.MakePoint(lng, lat);
- foreach (var f in strategy.CreateFields(fieldInfo, shape, true, storeShape))
+ foreach (var f in strategy.CreateIndexableFields(shape))
{
- if (f != null)
- { // null if incompatibleGeometry && ignore
- doc.Add(f);
- }
+ doc.Add(f);
}
+ //if (storeShape) doc.Add(new Field(GetType().Name, ctx.ToString(shape), Field.Store.YES,
Field.Index.NO));
writer.AddDocument(doc);
}
@@ -102,7 +96,7 @@ namespace Lucene.Net.Contrib.Spatial.Tes
private void ExecuteSearch(double lat, double lng, double radius, int expectedResults)
{
- var dq = strategy.MakeQuery(new SpatialArgs(SpatialOperation.IsWithin, ctx.MakeCircle(lng,
lat, radius)), fieldInfo);
+ var dq = strategy.MakeQuery(new SpatialArgs(SpatialOperation.IsWithin, ctx.MakeCircle(lng,
lat, radius)));
Console.WriteLine(dq);
//var dsort = new DistanceFieldComparatorSource(dq.DistanceFilter);
@@ -145,11 +139,11 @@ namespace Lucene.Net.Contrib.Spatial.Tes
// create a distance query
var args = new SpatialArgs(SpatialOperation.IsWithin, ctx.MakeCircle(lng, lat, radius));
- var vs = strategy.MakeValueSource(args, fieldInfo);
+ var vs = strategy.MakeValueSource(args);
var vals = vs.GetValues(_searcher.IndexReader);
args.SetDistPrecision(0.0);
- var dq = strategy.MakeQuery(args, fieldInfo);
+ var dq = strategy.MakeQuery(args);
Console.WriteLine(dq);
TopDocs hits = _searcher.Search(dq, null, 1000, new Sort(new SortField("distance", SortField.SCORE,
true)));
@@ -189,7 +183,7 @@ namespace Lucene.Net.Contrib.Spatial.Tes
// create a distance query
var radius = ctx.GetUnits().Convert(2.0, DistanceUnits.MILES);
- var dq = strategy.MakeQuery(new SpatialArgs(SpatialOperation.IsWithin, ctx.MakeCircle(_lng,
_lat, radius)), fieldInfo);
+ var dq = strategy.MakeQuery(new SpatialArgs(SpatialOperation.IsWithin, ctx.MakeCircle(_lng,
_lat, radius)));
Console.WriteLine(dq);
//var dsort = new DistanceFieldComparatorSource(dq.DistanceFilter);
@@ -203,7 +197,7 @@ namespace Lucene.Net.Contrib.Spatial.Tes
radius = ctx.GetUnits().Convert(1.0, DistanceUnits.MILES);
var spatialArgs = new SpatialArgs(SpatialOperation.IsWithin, ctx.MakeCircle(_lng, _lat,
radius));
- dq = strategy.MakeQuery(spatialArgs, fieldInfo);
+ dq = strategy.MakeQuery(spatialArgs);
Console.WriteLine(dq);
//var dsort = new DistanceFieldComparatorSource(dq.DistanceFilter);
@@ -240,7 +234,7 @@ namespace Lucene.Net.Contrib.Spatial.Tes
// create a distance query
var radius = ctx.GetUnits().Convert(52.0, DistanceUnits.MILES);
- var dq = strategy.MakeQuery(new SpatialArgs(SpatialOperation.IsWithin, ctx.MakeCircle(_lng,
_lat, radius)), fieldInfo);
+ var dq = strategy.MakeQuery(new SpatialArgs(SpatialOperation.IsWithin, ctx.MakeCircle(_lng,
_lat, radius)));
Console.WriteLine(dq);
TopDocs hits = _searcher.Search(dq, 1000);
Modified: incubator/lucene.net/trunk/test/contrib/Spatial/Vector/TestTwoDoublesStrategy.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/test/contrib/Spatial/Vector/TestTwoDoublesStrategy.cs?rev=1375266&r1=1375265&r2=1375266&view=diff
==============================================================================
--- incubator/lucene.net/trunk/test/contrib/Spatial/Vector/TestTwoDoublesStrategy.cs (original)
+++ incubator/lucene.net/trunk/test/contrib/Spatial/Vector/TestTwoDoublesStrategy.cs Mon Aug
20 21:56:13 2012
@@ -15,15 +15,49 @@
* limitations under the License.
*/
+using Lucene.Net.Search;
+using Lucene.Net.Spatial.Queries;
+using Lucene.Net.Spatial.Vector;
+using NUnit.Framework;
using Spatial4n.Core.Context;
+using Spatial4n.Core.Shapes;
+using Spatial4n.Core.Shapes.Impl;
+using Spatial4n.Core.Exceptions;
namespace Lucene.Net.Contrib.Spatial.Test.Vector
{
- public class TestTwoDoublesStrategy : BaseTwoDoublesStrategyTestCase
+ public class TestTwoDoublesStrategy : StrategyTestCase
{
- protected override SpatialContext getSpatialContext()
+ public override void SetUp()
{
- return SpatialContext.GEO_KM;
+ base.SetUp();
+ this.ctx = SpatialContext.GEO_KM;
+ this.strategy = new TwoDoublesStrategy(ctx, GetType().Name);
+ }
+
+ [Test]
+ public void testCircleShapeSupport()
+ {
+ Circle circle = new CircleImpl(new PointImpl(0, 0), 10, this.ctx);
+ SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, circle);
+ Query query = this.strategy.MakeQuery(args);
+
+ Assert.NotNull(query);
+ }
+
+ [Test]
+ public void testInvalidQueryShape()
+ {
+ Point point = new PointImpl(0, 0);
+ var args = new SpatialArgs(SpatialOperation.Intersects, point);
+ Assert.Throws<InvalidShapeException>(() => this.strategy.MakeQuery(args));
+ }
+
+ [Test]
+ public void testCitiesWithinBBox()
+ {
+ getAddAndVerifyIndexedDocuments(DATA_WORLD_CITIES_POINTS);
+ executeQueries(SpatialMatchConcern.FILTER, QTEST_Cities_IsWithin_BBox);
}
}
}
|