lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pnas...@apache.org
Subject [Lucene.Net] svn commit: r1102182 - in /incubator/lucene.net/trunk: build/vs2010/contrib/ src/contrib/Regex/ src/contrib/Regex/Properties/
Date Thu, 12 May 2011 07:05:13 GMT
Author: pnasser
Date: Thu May 12 07:05:13 2011
New Revision: 1102182

URL: http://svn.apache.org/viewvc?rev=1102182&view=rev
Log:
LUCENENET-330 Search.Regex minimal port (in Trunk)

Added:
    incubator/lucene.net/trunk/build/vs2010/contrib/Contrib.Regex.sln
    incubator/lucene.net/trunk/src/contrib/Regex/
    incubator/lucene.net/trunk/src/contrib/Regex/CSharpRegexCapabilities.cs
    incubator/lucene.net/trunk/src/contrib/Regex/Contrib.Regex.csproj
    incubator/lucene.net/trunk/src/contrib/Regex/IRegexCapabilities.cs
    incubator/lucene.net/trunk/src/contrib/Regex/IRegexQueryCapable.cs
    incubator/lucene.net/trunk/src/contrib/Regex/Properties/
    incubator/lucene.net/trunk/src/contrib/Regex/Properties/AssemblyInfo.cs
    incubator/lucene.net/trunk/src/contrib/Regex/RegexQuery.cs
    incubator/lucene.net/trunk/src/contrib/Regex/RegexTermEnum.cs
    incubator/lucene.net/trunk/src/contrib/Regex/SpanRegexQuery.cs
Modified:
    incubator/lucene.net/trunk/build/vs2010/contrib/Contrib.All.sln

Modified: incubator/lucene.net/trunk/build/vs2010/contrib/Contrib.All.sln
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/build/vs2010/contrib/Contrib.All.sln?rev=1102182&r1=1102181&r2=1102182&view=diff
==============================================================================
--- incubator/lucene.net/trunk/build/vs2010/contrib/Contrib.All.sln (original)
+++ incubator/lucene.net/trunk/build/vs2010/contrib/Contrib.All.sln Thu May 12 07:05:13 2011
@@ -1,6 +1,6 @@
 
 Microsoft Visual Studio Solution File, Format Version 11.00
-# Visual C# Express 2010
+# 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.Core", "..\..\..\src\contrib\Core\Contrib.Core.csproj",
"{FEF899EB-610C-4D3C-A556-A01F56F4AFE0}"
@@ -27,6 +27,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contrib.WordNet.Syns2Index", "..\..\..\src\contrib\WordNet\Syns2Index\Contrib.WordNet.Syns2Index.csproj",
"{7563D4D9-AE91-42BA-A270-1D264660F6DF}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contrib.Regex", "..\..\..\src\contrib\Regex\Contrib.Regex.csproj",
"{A26BD3B7-DF90-43B4-99E2-6A617CDE1579}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -85,6 +87,10 @@ Global
 		{7563D4D9-AE91-42BA-A270-1D264660F6DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{7563D4D9-AE91-42BA-A270-1D264660F6DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{7563D4D9-AE91-42BA-A270-1D264660F6DF}.Release|Any CPU.Build.0 = Release|Any CPU
+		{A26BD3B7-DF90-43B4-99E2-6A617CDE1579}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{A26BD3B7-DF90-43B4-99E2-6A617CDE1579}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{A26BD3B7-DF90-43B4-99E2-6A617CDE1579}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{A26BD3B7-DF90-43B4-99E2-6A617CDE1579}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

Added: incubator/lucene.net/trunk/build/vs2010/contrib/Contrib.Regex.sln
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/build/vs2010/contrib/Contrib.Regex.sln?rev=1102182&view=auto
==============================================================================
--- incubator/lucene.net/trunk/build/vs2010/contrib/Contrib.Regex.sln (added)
+++ incubator/lucene.net/trunk/build/vs2010/contrib/Contrib.Regex.sln Thu May 12 07:05:13
2011
@@ -0,0 +1,22 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.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.Core", "..\..\..\src\contrib\Regex\Contrib.Regex.csproj",
"{A26BD3B7-DF90-43B4-99E2-6A617CDE1579}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{A26BD3B7-DF90-43B4-99E2-6A617CDE1579}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{A26BD3B7-DF90-43B4-99E2-6A617CDE1579}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{A26BD3B7-DF90-43B4-99E2-6A617CDE1579}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{A26BD3B7-DF90-43B4-99E2-6A617CDE1579}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal

Added: incubator/lucene.net/trunk/src/contrib/Regex/CSharpRegexCapabilities.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Regex/CSharpRegexCapabilities.cs?rev=1102182&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Regex/CSharpRegexCapabilities.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/Regex/CSharpRegexCapabilities.cs Thu May 12 07:05:13
2011
@@ -0,0 +1,91 @@
+/* 
+ * 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;
+
+namespace Lucene.Net.Search.Regex
+{
+	/// <summary>
+	/// C# Regex based implementation of <see cref="IRegexCapabilities"/>.
+	/// </summary>
+	/// <remarks>http://www.java2s.com/Open-Source/Java-Document/Net/lucene-connector/org/apache/lucene/search/regex/JavaUtilRegexCapabilities.java.htm</remarks>
+	public class CSharpRegexCapabilities : IRegexCapabilities, IEquatable<CSharpRegexCapabilities>
+	{
+		private System.Text.RegularExpressions.Regex _rPattern;
+
+		/// <summary>
+		/// Called by the constructor of <see cref="RegexTermEnum"/> allowing implementations
to cache 
+		/// a compiled version of the regular expression pattern.
+		/// </summary>
+		/// <param name="pattern">regular expression pattern</param>
+		public void Compile(string pattern)
+		{
+			_rPattern = new System.Text.RegularExpressions.Regex(pattern, 
+				System.Text.RegularExpressions.RegexOptions.Compiled);
+		}
+
+		/// <summary>
+		/// True on match.
+		/// </summary>
+		/// <param name="s">text to match</param>
+		/// <returns>true on match</returns>
+		public bool Match(string s)
+		{
+			return _rPattern.IsMatch(s);
+		}
+
+		/// <summary>
+		/// A wise prefix implementation can reduce the term enumeration (and thus performance)
+		/// of RegexQuery dramatically.
+		/// </summary>
+		/// <returns>static non-regex prefix of the pattern last passed to <see cref="IRegexCapabilities.Compile"/>.
+		///   May return null</returns>
+		public string Prefix()
+		{
+			return null;
+		}
+
+		/// <summary>
+		/// Indicates whether the current object is equal to another object of the same type.
+		/// </summary>
+		/// <returns>
+		/// true if the current object is equal to the <paramref name="other"/> parameter;
otherwise, false.
+		/// </returns>
+		/// <param name="other">An object to compare with this object</param>
+		public bool Equals(CSharpRegexCapabilities other)
+		{
+			if (other == null) return false;
+			if (this == other) return true;
+
+			if (_rPattern != null ? !_rPattern.Equals(other._rPattern) : other._rPattern != null)
+				return false;
+
+			return true;
+		}
+
+		public override bool Equals(object obj)
+		{
+			if (obj as CSharpRegexCapabilities == null) return false;
+			return Equals((CSharpRegexCapabilities) obj);
+		}
+
+		public override int GetHashCode()
+		{
+			return (_rPattern != null ? _rPattern.GetHashCode() : 0);
+		}
+	}
+}

Added: incubator/lucene.net/trunk/src/contrib/Regex/Contrib.Regex.csproj
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Regex/Contrib.Regex.csproj?rev=1102182&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Regex/Contrib.Regex.csproj (added)
+++ incubator/lucene.net/trunk/src/contrib/Regex/Contrib.Regex.csproj Thu May 12 07:05:13
2011
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="utf-8"?>
+<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>8.0.30703</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{A26BD3B7-DF90-43B4-99E2-6A617CDE1579}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>Contrib.Regex</RootNamespace>
+    <AssemblyName>Contrib.Regex</AssemblyName>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>..\..\..\bin\contrib\Regex\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="CSharpRegexCapabilities.cs" />
+    <Compile Include="IRegexCapabilities.cs" />
+    <Compile Include="IRegexQueryCapable.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="RegexQuery.cs" />
+    <Compile Include="RegexTermEnum.cs" />
+    <Compile Include="SpanRegexQuery.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\..\core\Lucene.Net.csproj">
+      <Project>{5D4AD9BE-1FFB-41AB-9943-25737971BF57}</Project>
+      <Name>Lucene.Net</Name>
+    </ProjectReference>
+  </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

Added: incubator/lucene.net/trunk/src/contrib/Regex/IRegexCapabilities.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Regex/IRegexCapabilities.cs?rev=1102182&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Regex/IRegexCapabilities.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/Regex/IRegexCapabilities.cs Thu May 12 07:05:13
2011
@@ -0,0 +1,48 @@
+/* 
+ * 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.
+ */
+
+namespace Lucene.Net.Search.Regex
+{
+	/// <summary>
+	/// Defines basic operations needed by {@link RegexQuery} for a regular expression implementation.
+	/// </summary>
+	/// <remarks>http://www.java2s.com/Open-Source/Java-Document/Net/lucene-connector/org/apache/lucene/search/regex/RegexCapabilities.java.htm</remarks>
+	public interface IRegexCapabilities
+	{
+		/// <summary>
+		/// Called by the constructor of <see cref="RegexTermEnum"/> allowing implementations
to cache 
+		/// a compiled version of the regular expression pattern.
+		/// </summary>
+		/// <param name="pattern">regular expression pattern</param>
+		void Compile(string pattern);
+
+		/// <summary>
+		/// True on match.
+		/// </summary>
+		/// <param name="s">text to match</param>
+		/// <returns>true on match</returns>
+		bool Match(string s);
+
+		/// <summary>
+		/// A wise prefix implementation can reduce the term enumeration (and thus performance)
+		/// of RegexQuery dramatically.
+		/// </summary>
+		/// <returns>static non-regex prefix of the pattern last passed to <see cref="Compile"/>.
+		///   May return null</returns>
+		string Prefix();
+	}
+}

Added: incubator/lucene.net/trunk/src/contrib/Regex/IRegexQueryCapable.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Regex/IRegexQueryCapable.cs?rev=1102182&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Regex/IRegexQueryCapable.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/Regex/IRegexQueryCapable.cs Thu May 12 07:05:13
2011
@@ -0,0 +1,29 @@
+/* 
+ * 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.
+ */
+
+namespace Lucene.Net.Search.Regex
+{
+	/// <summary>
+	/// Defines methods for regular expression supporting queries to use.
+	/// </summary>
+	/// <remarks>http://www.java2s.com/Open-Source/Java-Document/Net/lucene-connector/org/apache/lucene/search/regex/RegexQueryCapable.java.htm</remarks>
+	public interface IRegexQueryCapable
+	{
+		void SetRegexImplementation(IRegexCapabilities impl);
+		IRegexCapabilities GetRegexImplementation();
+	}
+}

Added: incubator/lucene.net/trunk/src/contrib/Regex/Properties/AssemblyInfo.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Regex/Properties/AssemblyInfo.cs?rev=1102182&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Regex/Properties/AssemblyInfo.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/Regex/Properties/AssemblyInfo.cs Thu May 12 07:05:13
2011
@@ -0,0 +1,53 @@
+/**
+ * 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.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following 
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Lucene.Net.Contrib.Regex")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("The Apache Software Foundation")]
+[assembly: AssemblyProduct("Lucene.Net.Contrib.Regex")]
+[assembly: AssemblyCopyright("Copyright 2006 - 2011 The Apache Software Foundation")]
+[assembly: AssemblyTrademark("Copyright 2006 - 2011 The Apache Software Foundation")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible 
+// to COM components.  If you need to access a type in this assembly from 
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("7c479233-95a2-4d53-b0fd-0ad2389556b1")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers 
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("2.9.4")]
+[assembly: AssemblyFileVersion("2.9.4")]

Added: incubator/lucene.net/trunk/src/contrib/Regex/RegexQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Regex/RegexQuery.cs?rev=1102182&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Regex/RegexQuery.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/Regex/RegexQuery.cs Thu May 12 07:05:13 2011
@@ -0,0 +1,81 @@
+/* 
+ * 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.Index;
+
+namespace Lucene.Net.Search.Regex
+{
+	/// <summary>
+	/// Regular expression based query.
+	/// </summary>
+	/// <remarks>http://www.java2s.com/Open-Source/Java-Document/Net/lucene-connector/org/apache/lucene/search/regex/RegexQuery.java.htm</remarks>
+	public class RegexQuery : MultiTermQuery, IRegexQueryCapable, IEquatable<RegexQuery>
+	{
+		private IRegexCapabilities _regexImpl = new CSharpRegexCapabilities();
+
+		public RegexQuery(Term term) : base(term)
+		{
+		}
+
+		/// <summary>Construct the enumeration to be used, expanding the pattern term. </summary>
+		public override FilteredTermEnum GetEnum(IndexReader reader)
+		{
+			Term term = new Term(GetTerm().Field(), GetTerm().Text());
+			return new RegexTermEnum(reader, term, _regexImpl);
+		}
+
+		public void SetRegexImplementation(IRegexCapabilities impl)
+		{
+			_regexImpl = impl;
+		}
+
+		public IRegexCapabilities GetRegexImplementation()
+		{
+			return _regexImpl;
+		}
+
+		/// <summary>
+		/// Indicates whether the current object is equal to another object of the same type.
+		/// </summary>
+		/// <returns>
+		/// true if the current object is equal to the <paramref name="other"/> parameter;
otherwise, false.
+		/// </returns>
+		/// <param name="other">An object to compare with this object</param>
+		public bool Equals(RegexQuery other)
+		{
+			if (other == null) return false;
+			if (this == other) return true;
+
+			if (!base.Equals(other)) return false;
+			return _regexImpl.Equals(other._regexImpl);
+		}
+
+		public override bool Equals(object obj)
+		{
+			if ((obj == null) || (obj as RegexQuery == null)) return false;
+			if (this == obj) return true;
+
+			return Equals((RegexQuery) obj);
+		}
+
+		public override int GetHashCode()
+		{
+			return 29 * base.GetHashCode() + _regexImpl.GetHashCode();
+		}
+	}
+}

Added: incubator/lucene.net/trunk/src/contrib/Regex/RegexTermEnum.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Regex/RegexTermEnum.cs?rev=1102182&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Regex/RegexTermEnum.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/Regex/RegexTermEnum.cs Thu May 12 07:05:13 2011
@@ -0,0 +1,83 @@
+/* 
+ * 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.Index;
+
+namespace Lucene.Net.Search.Regex
+{
+	/// <summary>
+	/// Subclass of FilteredTermEnum for enumerating all terms that match the
+	/// specified regular expression term using the specified regular expression
+	/// implementation.
+	/// <para>Term enumerations are always ordered by Term.compareTo().  Each term in
+	/// the enumeration is greater than all that precede it.</para>
+	/// </summary>
+	/// <remarks>http://www.java2s.com/Open-Source/Java-Document/Net/lucene-connector/org/apache/lucene/search/regex/RegexTermEnum.java.htm</remarks>
+	public class RegexTermEnum : FilteredTermEnum
+	{
+		private string _sField = "";
+		private string _sPre = "";
+		private bool _bEndEnum;
+		private readonly IRegexCapabilities _regexImpl;
+
+		public RegexTermEnum(IndexReader reader, Term term, IRegexCapabilities regexImpl)
+		{
+			_sField = term.Field();
+			string sText = term.Text();
+			
+			_regexImpl = regexImpl;
+
+			_regexImpl.Compile(sText);
+
+			_sPre = _regexImpl.Prefix() ?? "";
+
+			SetEnum(reader.Terms(new Term(term.Field(), _sPre)));
+		}
+
+		/// <summary>Equality compare on the term </summary>
+		public override bool TermCompare(Term term)
+		{
+			if (_sField == term.Field())
+			{
+				string sSearchText = term.Text();
+				if (sSearchText.StartsWith(_sPre)) return _regexImpl.Match(sSearchText);
+			} //eif
+
+			_bEndEnum = true;
+			return false;
+		}
+
+		/// <summary>Equality measure on the term </summary>
+		public override float Difference()
+		{
+			// TODO: adjust difference based on distance of searchTerm.text() and term().text()
+			return 1.0F;
+		}
+
+		/// <summary>Indicates the end of the enumeration has been reached </summary>
+		public override bool EndEnum()
+		{
+			return _bEndEnum;
+		}
+
+		//public override void Close()
+		//{
+		//    base.Close();
+		//    _sField = null;
+		//}
+	}
+}

Added: incubator/lucene.net/trunk/src/contrib/Regex/SpanRegexQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Regex/SpanRegexQuery.cs?rev=1102182&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Regex/SpanRegexQuery.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/Regex/SpanRegexQuery.cs Thu May 12 07:05:13 2011
@@ -0,0 +1,162 @@
+/* 
+ * 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 System.Collections;
+using System.Collections.Generic;
+using System.Text;
+using Lucene.Net.Index;
+using Lucene.Net.Search.Spans;
+using Lucene.Net.Util;
+
+namespace Lucene.Net.Search.Regex
+{
+	/// <summary>
+	/// A SpanQuery version of <see cref="RegexQuery"/> allowing regular expression queries
to be nested
+	/// within other SpanQuery subclasses.
+	/// </summary>
+	/// <remarks>http://www.java2s.com/Open-Source/Java-Document/Net/lucene-connector/org/apache/lucene/search/regex/SpanRegexQuery.java.htm</remarks>
+	public class SpanRegexQuery : SpanQuery, IRegexQueryCapable, IEquatable<SpanRegexQuery>
+	{
+		private IRegexCapabilities _regexImpl = new CSharpRegexCapabilities();
+		private readonly Term _term;
+
+		public SpanRegexQuery(Term term)
+		{
+			_term = term;
+		}
+
+		public Term GetTerm()
+		{
+			return _term;
+		}
+
+		public override string ToString(string field)
+		{
+			StringBuilder sb = new StringBuilder();
+			sb.Append("SpanRegexQuery(");
+			sb.Append(_term);
+			sb.Append(')');
+			sb.Append(ToStringUtils.Boost(GetBoost()));
+			return sb.ToString();
+		}
+
+		public override Query Rewrite(IndexReader reader)
+		{
+			RegexQuery orig = new RegexQuery(_term);
+			orig.SetRegexImplementation(_regexImpl);
+
+			// RegexQuery (via MultiTermQuery).Rewrite always returns a BooleanQuery
+			orig.SetRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);	//@@
+			BooleanQuery bq = (BooleanQuery) orig.Rewrite(reader);
+
+			BooleanClause[] clauses = bq.GetClauses();
+			SpanQuery[] sqs = new SpanQuery[clauses.Length];
+			for (int i = 0; i < clauses.Length; i++)
+			{
+				BooleanClause clause = clauses[i];
+
+				// Clauses from RegexQuery.Rewrite are always TermQuery's
+				TermQuery tq = (TermQuery) clause.GetQuery();
+
+				sqs[i] = new SpanTermQuery(tq.GetTerm());
+				sqs[i].SetBoost(tq.GetBoost());
+			} //efor
+
+			SpanOrQuery query = new SpanOrQuery(sqs);
+			query.SetBoost(orig.GetBoost());
+
+			return query;
+		}
+
+		/// <summary>Expert: Returns the matches for this query in an index.  Used internally
+		/// to search for spans. 
+		/// </summary>
+		public override Spans.Spans GetSpans(IndexReader reader)
+		{
+			throw new InvalidOperationException("Query should have been rewritten");
+		}
+
+		/// <summary>Returns the name of the field matched by this query.</summary>
+		public override string GetField()
+		{
+			return _term.Field();
+		}
+
+		/// <summary>Returns a collection of all terms matched by this query.</summary>
+		/// <deprecated> use extractTerms instead
+		/// </deprecated>
+		/// <seealso cref="Query.ExtractTerms">
+		/// </seealso>
+		[Obsolete("use ExtractTerms instead")]
+        public override ICollection GetTerms()
+        {
+            ArrayList terms = new ArrayList {_term};
+		    return terms;
+        }
+    
+		public void SetRegexImplementation(IRegexCapabilities impl)
+		{
+			_regexImpl = impl;
+		}
+
+		public IRegexCapabilities GetRegexImplementation()
+		{
+			return _regexImpl;
+		}
+
+		/// <summary>
+		/// Indicates whether the current object is equal to another object of the same type.
+		/// </summary>
+		/// <returns>
+		/// true if the current object is equal to the <paramref name="other"/> parameter;
otherwise, false.
+		/// </returns>
+		/// <param name="other">An object to compare with this object.
+		///                 </param>
+		public bool Equals(SpanRegexQuery other)
+		{
+			if (other == null) return false;
+			if (this == other) return true;
+
+			if (!_regexImpl.Equals(other._regexImpl)) return false;
+			if (!_term.Equals(other._term)) return false;
+
+			return true;
+		}
+
+		/// <summary>
+		/// True if this object equals the specified object.
+		/// </summary>
+		/// <param name="obj">object</param>
+		/// <returns>true on equality</returns>
+		public override bool Equals(object obj)
+		{
+			if (obj as SpanRegexQuery == null) return false;
+
+			return Equals((SpanRegexQuery) obj);
+		}
+
+		/// <summary>
+		/// Get hash code for this object.
+		/// </summary>
+		/// <returns>hash code</returns>
+		public override int GetHashCode()
+		{
+			return 29 * _regexImpl.GetHashCode() + _term.GetHashCode();
+		}
+	}
+}



Mime
View raw message