You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by sy...@apache.org on 2014/04/22 04:53:24 UTC
[52/59] git commit: Merging trunk changes into 3.0.3
Merging trunk changes into 3.0.3
git-svn-id: https://svn.apache.org/repos/asf/lucene.net/branches/3.0.3@1389190 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/6bcb249d
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/6bcb249d
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/6bcb249d
Branch: refs/heads/master
Commit: 6bcb249d4fd6e49007e4f64a5f9978996c4245b2
Parents: 44ef738
Author: Prescott Nasser <pn...@apache.org>
Authored: Mon Sep 24 03:02:22 2012 +0000
Committer: Prescott Nasser <pn...@apache.org>
Committed: Mon Sep 24 03:02:22 2012 +0000
----------------------------------------------------------------------
.../Spatial.NTS/Lucene.Net.Spatial.NTS.nuspec | 47 ----
build/scripts/Spatial.NTS/document.targets | 31 ---
build/scripts/Spatial.NTS/project.targets | 66 -----
src/contrib/Spatial/BBox/DistanceSimilarity.cs | 63 +++++
.../Spatial/Prefix/PrefixCellsTokenizer.cs | 92 -------
src/contrib/Spatial/Util/OpenBitSetIterator.cs | 193 ---------------
.../Spatial/Vector/TwoDoublesStrategy.cs | 240 ------------------
test-files/spatial/cities-IsWithin-BBox.txt | 7 -
.../Spatial/Contrib.Spatial.NTS.Tests.csproj | 178 -------------
.../Spatial/Contrib.Spatial.Tests.csproj | 13 +-
test/contrib/Spatial/Various.cs | 248 -------------------
11 files changed, 70 insertions(+), 1108 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6bcb249d/build/scripts/Spatial.NTS/Lucene.Net.Spatial.NTS.nuspec
----------------------------------------------------------------------
diff --git a/build/scripts/Spatial.NTS/Lucene.Net.Spatial.NTS.nuspec b/build/scripts/Spatial.NTS/Lucene.Net.Spatial.NTS.nuspec
deleted file mode 100644
index 8c88514..0000000
--- a/build/scripts/Spatial.NTS/Lucene.Net.Spatial.NTS.nuspec
+++ /dev/null
@@ -1,47 +0,0 @@
-<?xml version="1.0"?>
-<!--
-
- 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.
-
--->
-<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
- <metadata>
- <id>Lucene.Net.Spatial.NTS</id>
- <version>$version$</version>
- <title>Lucene.Net Spatial NTS Library</title>
- <authors>Lucene.Net Community</authors>
- <owners>The Apache Software Foundation</owners>
- <iconUrl>http://incubator.apache.org/lucene.net/media/lucene-net-ico-128x128.png</iconUrl>
- <licenseUrl>http://www.apache.org/licenses/LICENSE-2.0.html</licenseUrl>
- <projectUrl>http://incubator.apache.org/lucene.net/</projectUrl>
- <requireLicenseAcceptance>false</requireLicenseAcceptance>
- <description>Lucene.Net is a port of the Lucene search engine library, written in C# and targeted at .NET runtime users.
-
-**This package contains only the Spatial NTS Contrib Lucene.Net assembly.</description>
- <summary>Lucene.Net is a port of the Lucene search engine library, written in C# and targeted at .NET runtime users.</summary>
- <tags>lucene.net core search information retrieval lucene apache</tags>
- <dependencies>
- <dependency id="Lucene.Net" version="3.0.3" />
- <dependency id="NetTopologySuite" version="1.12.0" />
- <dependency id="GeoAPI" version="1.6.0" />
- </dependencies>
- </metadata>
- <files>
- <file src="..\..\bin\contrib\Spatial.NTS\Release\**\Lucene.Net.Contrib.Spatial.NTS.dll" target="lib" />
- <file src="..\..\bin\contrib\Spatial.NTS\Release\**\Lucene.Net.Contrib.Spatial.NTS.XML" target="lib" />
- </files>
-
-</package>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6bcb249d/build/scripts/Spatial.NTS/document.targets
----------------------------------------------------------------------
diff --git a/build/scripts/Spatial.NTS/document.targets b/build/scripts/Spatial.NTS/document.targets
deleted file mode 100644
index 510591d..0000000
--- a/build/scripts/Spatial.NTS/document.targets
+++ /dev/null
@@ -1,31 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
-<!--
-
- 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.
-
--->
-<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
- <PropertyGroup>
- <DocumentationSources>
- <DocumentationSource sourceFile="..\bin\contrib\Spatial.NTS\Release\NET40\Lucene.Net.Contrib.Spatial.dll" />
- <DocumentationSource sourceFile="..\bin\contrib\Spatial.NTS\Release\NET40\Lucene.Net.Contrib.Spatial.XML" />
- </DocumentationSources>
- <HtmlHelpName>Lucene.Net.Contrib.Spatial.NTS</HtmlHelpName>
- <HelpTitle>Spatial.NTS Class Library</HelpTitle>
- <WorkingPath>..\artifacts\Spatial.NTS\working\</WorkingPath>
- <OutputPath>..\artifacts\Spatial.NTS\docs\</OutputPath>
- </PropertyGroup>
-</Project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6bcb249d/build/scripts/Spatial.NTS/project.targets
----------------------------------------------------------------------
diff --git a/build/scripts/Spatial.NTS/project.targets b/build/scripts/Spatial.NTS/project.targets
deleted file mode 100644
index b73ba78..0000000
--- a/build/scripts/Spatial.NTS/project.targets
+++ /dev/null
@@ -1,66 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
-<!--
-
- 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.
-
--->
-<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
- <!--
- Core Projects Are:
- Lucene.Net,
- Lucene.Net.Test,
- -->
- <PropertyGroup>
- <SpatialNTSFolder>$(BinFolder)\contrib\Spatial.NTS\$(Configuration)</SpatialNTSFolder>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Area)' == 'spatialnts'">
- <LocalBinFolder>$(BinFolder)\contrib\Spatial.NTS\$(Configuration)</LocalBinFolder>
- <ArtifactsFolder>$(BuildFolder)\artifacts\Spatial.NTS</ArtifactsFolder>
- </PropertyGroup>
-
- <Target Name="_spatial_nts_build">
- <ItemGroup>
- <SpatialProjectFiles Include="$(SourceFolder)\Contrib\Spatial\*.csproj" />
- <SpatialProjectFiles Include="$(TestFolder)\Contrib\Spatial\*.csproj" />
- </ItemGroup>
-
- <MSBuild Projects="@(SpatialProjectFiles)" Properties="Configuration=$(Configuration);ExternalConstants=$(ExternalConstants)" />
- <!-- Add "35" to the end of configuration to build .NET35 projects -->
- <MSBuild Projects="@(SpatialProjectFiles)" Properties="Configuration=$(Configuration)35;ExternalConstants=$(ExternalConstants)" />
- </Target>
-
- <Target Name="_spatial_nts_properties">
- <ItemGroup>
- <!-- Binaries To Copy in case we which to store all build items -->
- <BuildItems Include="$(SpatialNTSFolder)\**\*.*" />
-
- <!-- Assemblies To Test -->
- <TestFiles Include="$(SpatialNTSFolder)\**\Lucene.Net.Contrib.Spatial.NTS.Test.dll" />
-
- <!-- Files To Release -->
- <ReleaseFiles Include="$(SpatialNTSFolder)\**\Lucene.Net.Contrib.Spatial.NTS.dll" />
- <ReleaseFiles Include="$(SpatialNTSFolder)\**\Lucene.Net.Contrib.Spatial.NTS.XML" />
-
- <!-- Files to Analysis -->
- <AnalysisFiles Include="$(SpatialNTSFolder)\**\Lucene.Net.Contrib.Spatial.NTS.dll" />
- </ItemGroup>
- </Target>
-
- <Target Name="BuildSpatialNTS">
- <CallTarget Targets="_spatial_nts_build" />
- <CallTarget Targets="_spatial_nts_properties" />
- </Target>
-</Project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6bcb249d/src/contrib/Spatial/BBox/DistanceSimilarity.cs
----------------------------------------------------------------------
diff --git a/src/contrib/Spatial/BBox/DistanceSimilarity.cs b/src/contrib/Spatial/BBox/DistanceSimilarity.cs
new file mode 100644
index 0000000..98273f4
--- /dev/null
+++ b/src/contrib/Spatial/BBox/DistanceSimilarity.cs
@@ -0,0 +1,63 @@
+/*
+ * 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.
+ */
+
+using Lucene.Net.Search;
+using Spatial4n.Core.Context;
+using Spatial4n.Core.Distance;
+using Spatial4n.Core.Shapes;
+
+namespace Lucene.Net.Spatial.BBox
+{
+ /// <summary>
+ /// Returns the distance between the center of the indexed rectangle and the
+ /// query shape.
+ /// </summary>
+ public class DistanceSimilarity : BBoxSimilarity
+ {
+ private readonly Point queryPoint;
+ private readonly DistanceCalculator distCalc;
+ private readonly double nullValue;
+
+ public DistanceSimilarity(SpatialContext ctx, Point queryPoint)
+ {
+ this.queryPoint = queryPoint;
+ this.distCalc = ctx.GetDistCalc();
+ this.nullValue = (ctx.IsGeo() ? 180 : double.MaxValue);
+ }
+
+ public double Score(Rectangle indexRect, Explanation exp)
+ {
+ double score;
+ if (indexRect == null)
+ {
+ score = nullValue;
+ }
+ else
+ {
+ score = distCalc.Distance(queryPoint, indexRect.GetCenter());
+ }
+ if (exp != null)
+ {
+ exp.Value = (float) score;
+ exp.Description = GetType().Name;
+ exp.AddDetail(new Explanation(-1f, "" + queryPoint));
+ exp.AddDetail(new Explanation(-1f, "" + indexRect));
+ }
+ return score;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6bcb249d/src/contrib/Spatial/Prefix/PrefixCellsTokenizer.cs
----------------------------------------------------------------------
diff --git a/src/contrib/Spatial/Prefix/PrefixCellsTokenizer.cs b/src/contrib/Spatial/Prefix/PrefixCellsTokenizer.cs
deleted file mode 100644
index beb4b34..0000000
--- a/src/contrib/Spatial/Prefix/PrefixCellsTokenizer.cs
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * 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.
- */
-
-using Lucene.Net.Analysis;
-using Lucene.Net.Analysis.Tokenattributes;
-
-namespace Lucene.Net.Spatial.Prefix
-{
- public class PrefixCellsTokenizer : Tokenizer
- {
- private readonly TermAttribute termAtt;
-
- public PrefixCellsTokenizer()
- {
- termAtt = AddAttribute<TermAttribute>();
- }
-
- public override bool IncrementToken()
- {
- ClearAttributes();
- int length = 0;
- char[] buffer = termAtt.TermBuffer();
- while (true)
- {
- char c = (char)input.Read();
- if (c < 0) break;
- if (c == 'a' || c == 'A')
- {
- buffer[length++] = 'A';
- continue;
- }
- if (c == 'b' || c == 'B')
- {
- buffer[length++] = 'B';
- continue;
- }
- if (c == 'c' || c == 'C')
- {
- buffer[length++] = 'C';
- continue;
- }
- if (c == 'd' || c == 'D')
- {
- buffer[length++] = 'D';
- continue;
- }
- if (c == '*')
- {
- buffer[length++] = '*';
- continue;
- }
- if (c == '+')
- {
- buffer[length++] = '+';
- continue;
- }
-
- if (length > 0)
- {
- // Skip any other character
- break;
- }
- }
-
- termAtt.SetTermLength(length);
- return length > 0; // should only happen at the end
- }
-
- public override void End()
- {
- }
-
- public override void Reset(System.IO.TextReader input)
- {
- base.Reset(input);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6bcb249d/src/contrib/Spatial/Util/OpenBitSetIterator.cs
----------------------------------------------------------------------
diff --git a/src/contrib/Spatial/Util/OpenBitSetIterator.cs b/src/contrib/Spatial/Util/OpenBitSetIterator.cs
deleted file mode 100644
index eaeebad..0000000
--- a/src/contrib/Spatial/Util/OpenBitSetIterator.cs
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * 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.
- */
-
-using Lucene.Net.Search;
-using Lucene.Net.Util;
-
-namespace Lucene.Net.Spatial.Util
-{
-
- /// <summary>An iterator to iterate over set bits in an OpenBitSet.
- /// This is faster than nextSetBit() for iterating over the complete set of bits,
- /// especially when the density of the bits set is high.
- ///
- /// </summary>
- /// <version> $Id$
- /// </version>
- public class OpenBitSetIterator : DocIdSetIterator
- {
-
- // The General Idea: instead of having an array per byte that has
- // the offsets of the next set bit, that array could be
- // packed inside a 32 bit integer (8 4 bit numbers). That
- // should be faster than accessing an array for each index, and
- // the total array size is kept smaller (256*sizeof(int))=1K
- protected internal static readonly uint[] bitlist = new uint[]{0x0, 0x1, 0x2, 0x21, 0x3, 0x31, 0x32, 0x321, 0x4, 0x41, 0x42, 0x421, 0x43, 0x431, 0x432, 0x4321, 0x5, 0x51, 0x52, 0x521, 0x53, 0x531, 0x532, 0x5321, 0x54, 0x541, 0x542, 0x5421, 0x543, 0x5431, 0x5432, 0x54321, 0x6, 0x61, 0x62, 0x621, 0x63, 0x631, 0x632, 0x6321, 0x64, 0x641, 0x642, 0x6421, 0x643, 0x6431, 0x6432, 0x64321, 0x65, 0x651, 0x652, 0x6521, 0x653, 0x6531, 0x6532, 0x65321, 0x654, 0x6541, 0x6542, 0x65421, 0x6543, 0x65431, 0x65432, 0x654321, 0x7, 0x71, 0x72, 0x721, 0x73, 0x731, 0x732, 0x7321, 0x74, 0x741, 0x742, 0x7421, 0x743, 0x7431, 0x7432, 0x74321, 0x75, 0x751, 0x752, 0x7521, 0x753, 0x7531, 0x7532, 0x75321, 0x754, 0x7541, 0x7542, 0x75421, 0x7543, 0x75431, 0x75432, 0x754321, 0x76, 0x761, 0x762, 0x7621, 0x763, 0x7631, 0x7632, 0x76321, 0x764, 0x7641, 0x7642, 0x76421, 0x7643, 0x76431, 0x76432, 0x764321, 0x765, 0x7651, 0x7652, 0x76521, 0x7653, 0x76531, 0x76532, 0x765321, 0x7654, 0x76541, 0x76542, 0x765421, 0x76543, 0x
765431, 0x765432, 0x7654321, 0x8, 0x81, 0x82, 0x821, 0x83, 0x831, 0x832, 0x8321, 0x84, 0x841, 0x842, 0x8421, 0x843, 0x8431, 0x8432, 0x84321, 0x85, 0x851, 0x852, 0x8521, 0x853, 0x8531, 0x8532, 0x85321, 0x854, 0x8541, 0x8542, 0x85421, 0x8543, 0x85431, 0x85432, 0x854321, 0x86, 0x861, 0x862, 0x8621, 0x863, 0x8631, 0x8632, 0x86321, 0x864, 0x8641, 0x8642, 0x86421, 0x8643, 0x86431, 0x86432, 0x864321, 0x865, 0x8651, 0x8652, 0x86521, 0x8653, 0x86531, 0x86532, 0x865321, 0x8654, 0x86541, 0x86542, 0x865421, 0x86543, 0x865431, 0x865432, 0x8654321, 0x87, 0x871, 0x872, 0x8721, 0x873, 0x8731, 0x8732, 0x87321, 0x874, 0x8741, 0x8742, 0x87421, 0x8743, 0x87431, 0x87432, 0x874321, 0x875, 0x8751, 0x8752, 0x87521, 0x8753, 0x87531, 0x87532, 0x875321, 0x8754, 0x87541, 0x87542, 0x875421, 0x87543, 0x875431, 0x875432, 0x8754321, 0x876, 0x8761, 0x8762, 0x87621, 0x8763, 0x87631, 0x87632, 0x876321, 0x8764, 0x87641, 0x87642, 0x876421, 0x87643, 0x876431, 0x876432, 0x8764321, 0x8765, 0x87651, 0x87652, 0x876521, 0x87
653, 0x876531, 0x876532, 0x8765321, 0x87654,
- 0x876541, 0x876542, 0x8765421, 0x876543, 0x8765431, 0x8765432, 0x87654321};
- /// <summary>** the python code that generated bitlist
- /// def bits2int(val):
- /// arr=0
- /// for shift in range(8,0,-1):
- /// if val & 0x80:
- /// arr = (arr << 4) | shift
- /// val = val << 1
- /// return arr
- /// def int_table():
- /// tbl = [ hex(bits2int(val)).strip('L') for val in range(256) ]
- /// return ','.join(tbl)
- /// ****
- /// </summary>
-
- // hmmm, what about an iterator that finds zeros though,
- // or a reverse iterator... should they be separate classes
- // for efficiency, or have a common root interface? (or
- // maybe both? could ask for a SetBitsIterator, etc...
-
- private readonly long[] arr;
- private readonly int words;
- private int i = -1;
- private long word;
- private int wordShift;
- private int indexArray;
- private int curDocId = -1;
-
- public OpenBitSetIterator(OpenBitSet obs)
- : this(obs.Bits, obs.NumWords)
- {
- }
-
- public OpenBitSetIterator(long[] bits, int numWords)
- {
- arr = bits;
- words = numWords;
- }
-
- // 64 bit shifts
- private void Shift()
- {
- if ((int)word == 0)
- {
- wordShift += 32; word = (long)((ulong)word >> 32);
- }
- if ((word & 0x0000FFFF) == 0)
- {
- wordShift += 16; word = (long)((ulong)word >> 16);
- }
- if ((word & 0x000000FF) == 0)
- {
- wordShift += 8; word = (long)((ulong)word >> 8);
- }
- indexArray = (int)bitlist[word & 0xff];
- }
-
- /*/// <summary>** alternate shift implementations
- /// // 32 bit shifts, but a long shift needed at the end
- /// private void shift2() {
- /// int y = (int)word;
- /// if (y==0) {wordShift +=32; y = (int)(word >>>32); }
- /// if ((y & 0x0000FFFF) == 0) { wordShift +=16; y>>>=16; }
- /// if ((y & 0x000000FF) == 0) { wordShift +=8; y>>>=8; }
- /// indexArray = bitlist[y & 0xff];
- /// word >>>= (wordShift +1);
- /// }
- /// private void shift3() {
- /// int lower = (int)word;
- /// int lowByte = lower & 0xff;
- /// if (lowByte != 0) {
- /// indexArray=bitlist[lowByte];
- /// return;
- /// }
- /// shift();
- /// }
- /// ****
- /// </summary>*/
-
- public override int NextDoc()
- {
- if (indexArray == 0)
- {
- if (word != 0)
- {
- word = (long)((ulong)word >> 8);
- wordShift += 8;
- }
-
- while (word == 0)
- {
- if (++i >= words)
- {
- return curDocId = NO_MORE_DOCS;
- }
- word = arr[i];
- wordShift = -1; // loop invariant code motion should move this
- }
-
- // after the first time, should I go with a linear search, or
- // stick with the binary search in shift?
- Shift();
- }
-
- int bitIndex = (indexArray & 0x0f) + wordShift;
- indexArray = (int)((uint)indexArray >> 4);
- // should i<<6 be cached as a separate variable?
- // it would only save one cycle in the best circumstances.
- return curDocId = (i << 6) + bitIndex;
- }
-
- public override int Advance(int target)
- {
- indexArray = 0;
- i = target >> 6;
- if (i >= words)
- {
- word = 0; // setup so next() will also return -1
- return curDocId = NO_MORE_DOCS;
- }
- wordShift = target & 0x3f;
- word = (long)((ulong)arr[i] >> wordShift);
- if (word != 0)
- {
- wordShift--; // compensate for 1 based arrIndex
- }
- else
- {
- while (word == 0)
- {
- if (++i >= words)
- {
- return curDocId = NO_MORE_DOCS;
- }
- word = arr[i];
- }
- wordShift = -1;
- }
-
- Shift();
-
- int bitIndex = (indexArray & 0x0f) + wordShift;
- indexArray = (int)((uint)indexArray >> 4);
- // should i<<6 be cached as a separate variable?
- // it would only save one cycle in the best circumstances.
- return curDocId = (i << 6) + bitIndex;
- }
-
- public override int DocID()
- {
- return curDocId;
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6bcb249d/src/contrib/Spatial/Vector/TwoDoublesStrategy.cs
----------------------------------------------------------------------
diff --git a/src/contrib/Spatial/Vector/TwoDoublesStrategy.cs b/src/contrib/Spatial/Vector/TwoDoublesStrategy.cs
deleted file mode 100644
index e494d8f..0000000
--- a/src/contrib/Spatial/Vector/TwoDoublesStrategy.cs
+++ /dev/null
@@ -1,240 +0,0 @@
-/*
- * 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.
- */
-
-using System;
-using Lucene.Net.Documents;
-using Lucene.Net.Search;
-using Lucene.Net.Search.Function;
-using Lucene.Net.Spatial.Queries;
-using Lucene.Net.Spatial.Util;
-using Spatial4n.Core.Context;
-using Spatial4n.Core.Exceptions;
-using Spatial4n.Core.Shapes;
-
-namespace Lucene.Net.Spatial.Vector
-{
- public class TwoDoublesStrategy : SpatialStrategy
- {
- public static String SUFFIX_X = "__x";
- public static String SUFFIX_Y = "__y";
-
- private readonly String fieldNameX;
- private readonly String fieldNameY;
-
- public int precisionStep = 8; // same as solr default
-
- public TwoDoublesStrategy(SpatialContext ctx, String fieldNamePrefix)
- : base(ctx, fieldNamePrefix)
- {
- this.fieldNameX = fieldNamePrefix + SUFFIX_X;
- this.fieldNameY = fieldNamePrefix + SUFFIX_Y;
- }
-
- public void SetPrecisionStep(int p)
- {
- precisionStep = p;
- if (precisionStep <= 0 || precisionStep >= 64)
- precisionStep = int.MaxValue;
- }
-
- public string GetFieldNameX()
- {
- return fieldNameX;
- }
-
- public string GetFieldNameY()
- {
- return fieldNameY;
- }
-
- public override AbstractField[] CreateIndexableFields(Shape shape)
- {
- var point = shape as Point;
- if (point != null)
- {
- var f = new AbstractField[2];
-
- var f0 = new NumericField(fieldNameX, precisionStep, Field.Store.NO, true)
- {OmitNorms = true, OmitTermFreqAndPositions = true};
- f0.SetDoubleValue(point.GetX());
- f[0] = f0;
-
- var f1 = new NumericField(fieldNameY, precisionStep, Field.Store.NO, true)
- {OmitNorms = true, OmitTermFreqAndPositions = true};
- f1.SetDoubleValue(point.GetY());
- f[1] = f1;
-
- return f;
- }
- if (!ignoreIncompatibleGeometry)
- {
- throw new ArgumentException("TwoDoublesStrategy can not index: " + shape);
- }
- return new AbstractField[0]; // nothing (solr does not support null)
- }
-
- public override ValueSource MakeValueSource(SpatialArgs args)
- {
- Point p = args.GetShape().GetCenter();
- return new DistanceValueSource(this, p, ctx.GetDistCalc());
- }
-
- public override Query MakeQuery(SpatialArgs args)
- {
- // For starters, just limit the bbox
- var shape = args.GetShape();
- if (!(shape is Rectangle || shape is Circle))
- throw new InvalidShapeException("Only Rectangles and Circles are currently supported, found ["
- + shape.GetType().Name + "]");//TODO
-
- Rectangle bbox = shape.GetBoundingBox();
- if (bbox.GetCrossesDateLine())
- {
- throw new InvalidOperationException("Crossing dateline not yet supported");
- }
-
- ValueSource valueSource = null;
-
- Query spatial = null;
- SpatialOperation op = args.Operation;
-
- if (SpatialOperation.Is(op,
- SpatialOperation.BBoxWithin,
- SpatialOperation.BBoxIntersects))
- {
- spatial = MakeWithin(bbox);
- }
- else if (SpatialOperation.Is(op,
- SpatialOperation.Intersects,
- SpatialOperation.IsWithin))
- {
- spatial = MakeWithin(bbox);
- var circle = args.GetShape() as Circle;
- if (circle != null)
- {
- // Make the ValueSource
- valueSource = MakeValueSource(args);
-
- var vsf = new ValueSourceFilter(
- new QueryWrapperFilter(spatial), valueSource, 0, circle.GetRadius());
-
- spatial = new FilteredQuery(new MatchAllDocsQuery(), vsf);
- }
- }
- else if (op == SpatialOperation.IsDisjointTo)
- {
- spatial = MakeDisjoint(bbox);
- }
-
- if (spatial == null)
- {
- throw new UnsupportedSpatialOperation(args.Operation);
- }
-
- if (valueSource != null)
- {
- valueSource = new CachingDoubleValueSource(valueSource);
- }
- else
- {
- valueSource = MakeValueSource(args);
- }
- Query spatialRankingQuery = new FunctionQuery(valueSource);
- var bq = new BooleanQuery();
- bq.Add(spatial, Occur.MUST);
- bq.Add(spatialRankingQuery, Occur.MUST);
- return bq;
-
- }
-
- public override Filter MakeFilter(SpatialArgs args)
- {
- var circle = args.GetShape() as Circle;
- if (circle != null)
- {
- if (SpatialOperation.Is(args.Operation,
- SpatialOperation.Intersects,
- SpatialOperation.IsWithin))
- {
- Query bbox = MakeWithin(circle.GetBoundingBox());
-
- // Make the ValueSource
- ValueSource valueSource = MakeValueSource(args);
-
- return new ValueSourceFilter(
- new QueryWrapperFilter(bbox), valueSource, 0, circle.GetRadius());
- }
- }
- return new QueryWrapperFilter(MakeQuery(args));
- }
-
- /// <summary>
- /// Constructs a query to retrieve documents that fully contain the input envelope.
- /// </summary>
- /// <param name="bbox"></param>
- /// <param name="fieldInfo"></param>
- /// <returns>The spatial query</returns>
- private Query MakeWithin(Rectangle bbox)
- {
- Query qX = NumericRangeQuery.NewDoubleRange(
- fieldNameX,
- precisionStep,
- bbox.GetMinX(),
- bbox.GetMaxX(),
- true,
- true);
- Query qY = NumericRangeQuery.NewDoubleRange(
- fieldNameY,
- precisionStep,
- bbox.GetMinY(),
- bbox.GetMaxY(),
- true,
- true);
-
- var bq = new BooleanQuery {{qX, Occur.MUST}, {qY, Occur.MUST}};
- return bq;
- }
-
- /// <summary>
- /// Constructs a query to retrieve documents that fully contain the input envelope.
- /// </summary>
- /// <param name="bbox"></param>
- /// <param name="fieldInfo"></param>
- /// <returns>The spatial query</returns>
- Query MakeDisjoint(Rectangle bbox)
- {
- Query qX = NumericRangeQuery.NewDoubleRange(
- fieldNameX,
- precisionStep,
- bbox.GetMinX(),
- bbox.GetMaxX(),
- true,
- true);
- Query qY = NumericRangeQuery.NewDoubleRange(
- fieldNameY,
- precisionStep,
- bbox.GetMinY(),
- bbox.GetMaxY(),
- true,
- true);
-
- var bq = new BooleanQuery {{qX, Occur.MUST_NOT}, {qY, Occur.MUST_NOT}};
- return bq;
- }
-
- }
-}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6bcb249d/test-files/spatial/cities-IsWithin-BBox.txt
----------------------------------------------------------------------
diff --git a/test-files/spatial/cities-IsWithin-BBox.txt b/test-files/spatial/cities-IsWithin-BBox.txt
deleted file mode 100644
index 1df64ea..0000000
--- a/test-files/spatial/cities-IsWithin-BBox.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-[San Francisco] G5391959 @ IsWithin(-122.524918 37.674973 -122.360123 37.817108)
-[Wellington] G2179537 @ IsWithin(174.711456 -41.360779 174.854279 -41.213837)
-[Barcelona] G6544100 G3128760 @ IsWithin(2.127228 41.333313 2.226105 41.408844)
-
-
-
-
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6bcb249d/test/contrib/Spatial/Contrib.Spatial.NTS.Tests.csproj
----------------------------------------------------------------------
diff --git a/test/contrib/Spatial/Contrib.Spatial.NTS.Tests.csproj b/test/contrib/Spatial/Contrib.Spatial.NTS.Tests.csproj
deleted file mode 100644
index 835a000..0000000
--- a/test/contrib/Spatial/Contrib.Spatial.NTS.Tests.csproj
+++ /dev/null
@@ -1,178 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-
- 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.
-
--->
-<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <PropertyGroup>
- <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProductVersion>9.0.21022</ProductVersion>
- <SchemaVersion>2.0</SchemaVersion>
- <ProjectGuid>{DEC65744-D581-4007-87B2-BB0726EE0395}</ProjectGuid>
- <AppDesignerFolder>Properties</AppDesignerFolder>
- <RootNamespace>Lucene.Net.Contrib.Spatial.Test</RootNamespace>
- <AssemblyName>Lucene.Net.Contrib.Spatial.NTS.Test</AssemblyName>
- <FileAlignment>512</FileAlignment>
- <FileUpgradeFlags>
- </FileUpgradeFlags>
- <OldToolsVersion>3.5</OldToolsVersion>
- <UpgradeBackupLocation />
- <PublishUrl>publish\</PublishUrl>
- <Install>true</Install>
- <InstallFrom>Disk</InstallFrom>
- <UpdateEnabled>false</UpdateEnabled>
- <UpdateMode>Foreground</UpdateMode>
- <UpdateInterval>7</UpdateInterval>
- <UpdateIntervalUnits>Days</UpdateIntervalUnits>
- <UpdatePeriodically>false</UpdatePeriodically>
- <UpdateRequired>false</UpdateRequired>
- <MapFileExtensions>true</MapFileExtensions>
- <ApplicationRevision>0</ApplicationRevision>
- <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
- <IsWebBootstrapper>false</IsWebBootstrapper>
- <UseApplicationTrust>false</UseApplicationTrust>
- <BootstrapperEnabled>true</BootstrapperEnabled>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
- <Framework>$(TargetFrameworkVersion.Replace("v", "NET").Replace(".", ""))</Framework>
- <DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>..\..\..\build\bin\contrib\Spatial.NTS\$(Configuration.Replace("35", ""))\$(Framework)\</OutputPath>
- <DefineConstants>DEBUG;TRACE;$(Framework)</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- <NoWarn>618</NoWarn>
- <OutputType>Library</OutputType>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug35|AnyCPU' ">
- <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
- <Framework>$(TargetFrameworkVersion.Replace("v", "NET").Replace(".", ""))</Framework>
- <DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>..\..\..\build\bin\contrib\Spatial.NTS\$(Configuration.Replace("35", ""))\$(Framework)\</OutputPath>
- <DefineConstants>DEBUG;TRACE;$(Framework)</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- <NoWarn>618</NoWarn>
- <OutputType>Library</OutputType>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
- <Framework>$(TargetFrameworkVersion.Replace("v", "NET").Replace(".", ""))</Framework>
- <DebugType>pdbonly</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>..\..\..\build\bin\contrib\Spatial.NTS\$(Configuration.Replace("35", ""))\$(Framework)\</OutputPath>
- <DefineConstants>TRACE;$(Framework)</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- <DebugSymbols>true</DebugSymbols>
- <OutputType>Library</OutputType>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release35|AnyCPU' ">
- <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
- <Framework>$(TargetFrameworkVersion.Replace("v", "NET").Replace(".", ""))</Framework>
- <DebugType>pdbonly</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>..\..\..\build\bin\contrib\Spatial.NTS\$(Configuration.Replace("35", ""))\$(Framework)\</OutputPath>
- <DefineConstants>TRACE;$(Framework)</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- <DebugSymbols>true</DebugSymbols>
- <OutputType>Library</OutputType>
- </PropertyGroup>
- <ItemGroup>
- <Reference Include="nunit.framework">
- <HintPath>..\..\..\lib\NUnit.org\NUnit\2.5.9\bin\net-2.0\framework\nunit.framework.dll</HintPath>
- </Reference>
- <Reference Include="Spatial4n.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f9456e1ca16d45e, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\..\lib\Spatial4n\$(Framework)\Spatial4n.Core.NTS.dll</HintPath>
- </Reference>
- <Reference Include="System" />
- <Reference Condition="'$(Framework)' == 'NET35'" Include="System.Core" />
- </ItemGroup>
- <ItemGroup>
- <Compile Include="..\..\core\Util\LuceneTestCase.cs">
- <Link>LuceneTestCase.cs</Link>
- </Compile>
- <Compile Include="..\..\core\Util\Paths.cs">
- <Link>Paths.cs</Link>
- </Compile>
- <Compile Include="BBox\TestBBoxStrategy.cs" />
- <Compile Include="Compatibility\TermsFilterTest.cs" />
- <Compile Include="PortedSolr3Test.cs" />
- <Compile Include="Prefix\TestRecursivePrefixTreeStrategy.cs" />
- <Compile Include="Prefix\TestTermQueryPrefixGridStrategy.cs" />
- <Compile Include="Prefix\Tree\SpatialPrefixTreeTest.cs" />
- <Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="Queries\SpatialArgsParserTest.cs" />
- <Compile Include="SpatialMatchConcern.cs" />
- <Compile Include="SpatialTestCase.cs" />
- <Compile Include="SpatialTestQuery.cs" />
- <Compile Include="StrategyTestCase.cs" />
- <Compile Include="TestTestFramework.cs" />
- <Compile Include="Various.cs" />
- <Compile Include="Vector\TestTwoDoublesStrategy.cs" />
- </ItemGroup>
- <ItemGroup>
- <BootstrapperPackage Include=".NETFramework,Version=v4.0">
- <Visible>False</Visible>
- <ProductName>Microsoft .NET Framework 4 %28x86 and x64%29</ProductName>
- <Install>true</Install>
- </BootstrapperPackage>
- <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
- <Visible>False</Visible>
- <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
- <Install>false</Install>
- </BootstrapperPackage>
- <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
- <Visible>False</Visible>
- <ProductName>.NET Framework 3.5 SP1</ProductName>
- <Install>false</Install>
- </BootstrapperPackage>
- <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
- <Visible>False</Visible>
- <ProductName>Windows Installer 3.1</ProductName>
- <Install>true</Install>
- </BootstrapperPackage>
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="..\..\..\src\contrib\Spatial\Contrib.Spatial.NTS.csproj">
- <Project>{02d030d0-c7b5-4561-8bdd-41408b2e2f41}</Project>
- <Name>Contrib.Spatial.NTS</Name>
- </ProjectReference>
- <ProjectReference Include="..\..\..\src\core\Lucene.Net.csproj">
- <Project>{5D4AD9BE-1FFB-41AB-9943-25737971BF57}</Project>
- <Name>Lucene.Net</Name>
- </ProjectReference>
- </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.
- <Target Name="BeforeBuild">
- </Target>
- <Target Name="AfterBuild">
- </Target>
- -->
-</Project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6bcb249d/test/contrib/Spatial/Contrib.Spatial.Tests.csproj
----------------------------------------------------------------------
diff --git a/test/contrib/Spatial/Contrib.Spatial.Tests.csproj b/test/contrib/Spatial/Contrib.Spatial.Tests.csproj
index 51a470e..762014b 100644
--- a/test/contrib/Spatial/Contrib.Spatial.Tests.csproj
+++ b/test/contrib/Spatial/Contrib.Spatial.Tests.csproj
@@ -104,9 +104,9 @@
<Reference Include="nunit.framework">
<HintPath>..\..\..\lib\NUnit.org\NUnit\2.5.9\bin\net-2.0\framework\nunit.framework.dll</HintPath>
</Reference>
- <Reference Include="Spatial4n.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f9456e1ca16d45e, processorArchitecture=MSIL">
+ <Reference Include="Spatial4n.Core.NTS, Version=0.3.0.0, Culture=neutral, PublicKeyToken=9f9456e1ca16d45e, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\..\lib\Spatial4n\$(Framework)\Spatial4n.Core.dll</HintPath>
+ <HintPath>..\..\..\build\bin\contrib\Spatial\Debug\NET40\Spatial4n.Core.NTS.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Condition="'$(Framework)' == 'NET35'" Include="System.Core" />
@@ -119,7 +119,9 @@
<Link>Paths.cs</Link>
</Compile>
<Compile Include="BBox\TestBBoxStrategy.cs" />
+ <Compile Include="CheckHits.cs" />
<Compile Include="Compatibility\TermsFilterTest.cs" />
+ <Compile Include="DistanceStrategyTest.cs" />
<Compile Include="PortedSolr3Test.cs" />
<Compile Include="Prefix\TestRecursivePrefixTreeStrategy.cs" />
<Compile Include="Prefix\TestTermQueryPrefixGridStrategy.cs" />
@@ -131,7 +133,6 @@
<Compile Include="SpatialTestQuery.cs" />
<Compile Include="StrategyTestCase.cs" />
<Compile Include="TestTestFramework.cs" />
- <Compile Include="Various.cs" />
<Compile Include="Vector\TestTwoDoublesStrategy.cs" />
</ItemGroup>
<ItemGroup>
@@ -157,9 +158,9 @@
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
- <ProjectReference Include="..\..\..\src\contrib\Spatial\Contrib.Spatial.csproj">
- <Project>{35C347F4-24B2-4BE5-8117-A0E3001551CE}</Project>
- <Name>Contrib.Spatial</Name>
+ <ProjectReference Include="..\..\..\src\contrib\Spatial\Contrib.Spatial.NTS.csproj">
+ <Project>{02d030d0-c7b5-4561-8bdd-41408b2e2f41}</Project>
+ <Name>Contrib.Spatial.NTS</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\src\core\Lucene.Net.csproj">
<Project>{5D4AD9BE-1FFB-41AB-9943-25737971BF57}</Project>
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6bcb249d/test/contrib/Spatial/Various.cs
----------------------------------------------------------------------
diff --git a/test/contrib/Spatial/Various.cs b/test/contrib/Spatial/Various.cs
deleted file mode 100644
index 9d03360..0000000
--- a/test/contrib/Spatial/Various.cs
+++ /dev/null
@@ -1,248 +0,0 @@
-/*
- *
- * 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.
- *
-*/
-
-using System;
-using Lucene.Net.Analysis;
-using Lucene.Net.Documents;
-using Lucene.Net.Index;
-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.Shapes;
-using Directory = Lucene.Net.Store.Directory;
-
-namespace Lucene.Net.Contrib.Spatial.Test
-{
- [TestFixture]
- public class Various
- {
- private Directory _directory;
- private IndexSearcher _searcher;
- private IndexWriter _writer;
- protected SpatialStrategy strategy;
- protected readonly SpatialContext ctx = SpatialContext.GEO_KM;
- protected readonly bool storeShape = true;
- private int maxLength;
-
- [SetUp]
- protected void SetUp()
- {
- maxLength = GeohashPrefixTree.GetMaxLevelsPossible();
- strategy = new RecursivePrefixTreeStrategy(new GeohashPrefixTree(ctx, maxLength), GetType().Name);
-
- _directory = new RAMDirectory();
- _writer = new IndexWriter(_directory, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED);
- }
-
- private void AddPoint(IndexWriter writer, String name, double lat, double lng)
- {
- 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.CreateIndexableFields(shape))
- {
- doc.Add(f);
- }
- //if (storeShape) doc.Add(new Field(GetType().Name, ctx.ToString(shape), Field.Store.YES, Field.Index.NO));
- writer.AddDocument(doc);
- }
-
- [Test]
- public void RadiusOf15Something()
- {
- // Origin
- const double _lat = 45.829507799999988;
- const double _lng = -73.800524699999983;
-
- //Locations
- AddPoint(_writer, "The location doc we are after", _lat, _lng);
-
- _writer.Commit();
- _writer.Close();
-
- _searcher = new IndexSearcher(_directory, true);
-
- ExecuteSearch(45.831909, -73.810322, ctx.GetUnits().Convert(150000, DistanceUnits.MILES), 1);
- ExecuteSearch(45.831909, -73.810322, ctx.GetUnits().Convert(15000, DistanceUnits.MILES), 1);
- ExecuteSearch(45.831909, -73.810322, ctx.GetUnits().Convert(1500, DistanceUnits.MILES), 1);
-
- _searcher.Close();
- _directory.Close();
- }
-
- private void ExecuteSearch(double lat, double lng, double radius, int expectedResults)
- {
- var dq = strategy.MakeQuery(new SpatialArgs(SpatialOperation.IsWithin, ctx.MakeCircle(lng, lat, radius)));
- Console.WriteLine(dq);
-
- //var dsort = new DistanceFieldComparatorSource(dq.DistanceFilter);
- //Sort sort = new Sort(new SortField("foo", dsort, false));
-
- // Perform the search, using the term query, the distance filter, and the
- // distance sort
- TopDocs hits = _searcher.Search(dq, 10);
- int results = hits.TotalHits;
- ScoreDoc[] scoreDocs = hits.ScoreDocs;
-
- // Get a list of distances
- //Dictionary<int, Double> distances = dq.DistanceFilter.Distances;
-
- //Console.WriteLine("Distance Filter filtered: " + distances.Count);
- //Console.WriteLine("Results: " + results);
-
- //Assert.AreEqual(expectedResults, distances.Count); // fixed a store of only needed distances
- Assert.AreEqual(expectedResults, results);
- }
-
- [Test]
- public void CheckIfSortingCorrectly()
- {
- // Origin
- const double lat = 38.96939;
- const double lng = -77.386398;
- var radius = ctx.GetUnits().Convert(6.0, DistanceUnits.MILES);
-
-
- AddPoint(_writer, "c/1", 38.9579000, -77.3572000); // 1.76 Miles away
- AddPoint(_writer, "a/2", 38.9690000, -77.3862000); // 0.03 Miles away
- AddPoint(_writer, "b/3", 38.9510000, -77.4107000); // 1.82 Miles away
-
- _writer.Commit();
- _writer.Close();
-
- _searcher = new IndexSearcher(_directory, true);
-
- // create a distance query
- var args = new SpatialArgs(SpatialOperation.IsWithin, ctx.MakeCircle(lng, lat, radius));
-
- var vs = strategy.MakeValueSource(args);
- var vals = vs.GetValues(_searcher.IndexReader);
-
- args.SetDistPrecision(0.0);
- var dq = strategy.MakeQuery(args);
- Console.WriteLine(dq);
-
- TopDocs hits = _searcher.Search(dq, null, 1000, new Sort(new SortField("distance", SortField.SCORE, true)));
- var results = hits.TotalHits;
- Assert.AreEqual(3, results);
-
- var expectedOrder = new[] {"a/2", "c/1", "b/3"};
- for (int i = 0; i < hits.TotalHits; i++)
- {
- Assert.AreEqual(expectedOrder[i], _searcher.Doc(hits.ScoreDocs[i].Doc).GetField("name").StringValue);
- }
- }
-
- [Test]
- public void LUCENENET462()
- {
- Console.WriteLine("LUCENENET462");
-
- // Origin
- const double _lat = 51.508129;
- const double _lng = -0.128005;
-
- // Locations
- AddPoint(_writer, "Location 1", 51.5073802128877, -0.124669075012207);
- AddPoint(_writer, "Location 2", 51.5091, -0.1235);
- AddPoint(_writer, "Location 3", 51.5093, -0.1232);
- AddPoint(_writer, "Location 4", 51.5112531582845, -0.12509822845459);
- AddPoint(_writer, "Location 5", 51.5107, -0.123);
- AddPoint(_writer, "Location 6", 51.512, -0.1246);
- AddPoint(_writer, "Location 8", 51.5088760101322, -0.143165588378906);
- AddPoint(_writer, "Location 9", 51.5087958793819, -0.143508911132813);
-
- _writer.Commit();
- _writer.Close();
-
- _searcher = new IndexSearcher(_directory, true);
-
- // 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)));
- Console.WriteLine(dq);
-
- //var dsort = new DistanceFieldComparatorSource(dq.DistanceFilter);
- //Sort sort = new Sort(new SortField("foo", dsort, false));
-
- // Perform the search, using the term query, the distance filter, and the
- // distance sort
- TopDocs hits = _searcher.Search(dq, 1000);
- var results = hits.TotalHits;
- Assert.AreEqual(8, results);
-
- radius = ctx.GetUnits().Convert(1.0, DistanceUnits.MILES);
- var spatialArgs = new SpatialArgs(SpatialOperation.IsWithin, ctx.MakeCircle(_lng, _lat, radius));
- dq = strategy.MakeQuery(spatialArgs);
- Console.WriteLine(dq);
-
- //var dsort = new DistanceFieldComparatorSource(dq.DistanceFilter);
- //Sort sort = new Sort(new SortField("foo", dsort, false));
-
- // Perform the search, using the term query, the distance filter, and the
- // distance sort
- hits = _searcher.Search(dq, 1000);
- results = hits.TotalHits;
-
- Assert.AreEqual(8, results);
-
- _searcher.Close();
- _directory.Close();
- }
-
- [Test]
- public void LUCENENET483()
- {
- Console.WriteLine("LUCENENET483");
-
- // Origin
- const double _lat = 42.350153;
- const double _lng = -71.061667;
-
- //Locations
- AddPoint(_writer, "Location 1", 42.0, -71.0); //24 miles away from origin
- AddPoint(_writer, "Location 2", 42.35, -71.06); //less than a mile
-
- _writer.Commit();
- _writer.Close();
-
- _searcher = new IndexSearcher(_directory, true);
-
- // 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)));
- Console.WriteLine(dq);
-
- TopDocs hits = _searcher.Search(dq, 1000);
- var results = hits.TotalHits;
- Assert.AreEqual(2, results);
-
- _searcher.Close();
- _directory.Close();
- }
- }
-}