lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [2/2] lucenenet git commit: API: Lucene.Net.Support.Document: Added extension methods to make casting to the correct field type simpler.
Date Thu, 13 Jul 2017 18:38:26 GMT
API: Lucene.Net.Support.Document: Added extension methods to make casting to the correct field
type simpler.


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/e694ee94
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/e694ee94
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/e694ee94

Branch: refs/heads/master
Commit: e694ee94f57ab8ceff5747760f99cd9b8505aa4c
Parents: 559efc7
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Fri Jul 14 01:34:03 2017 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Fri Jul 14 01:38:03 2017 +0700

----------------------------------------------------------------------
 src/Lucene.Net/Document/Document.cs             |  2 +-
 src/Lucene.Net/Lucene.Net.csproj                |  1 +
 .../Support/Document/DocumentExtensions.cs      | 39 ++++++++++++++++++++
 3 files changed, 41 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e694ee94/src/Lucene.Net/Document/Document.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Document/Document.cs b/src/Lucene.Net/Document/Document.cs
index d19f874..e67946f 100644
--- a/src/Lucene.Net/Document/Document.cs
+++ b/src/Lucene.Net/Document/Document.cs
@@ -192,7 +192,7 @@ namespace Lucene.Net.Documents
 
         /// <summary>
         /// Returns an array of <see cref="IIndexableField"/>s with the given name.
-        /// this method returns an empty array when there are no
+        /// This method returns an empty array when there are no
         /// matching fields. It never returns <c>null</c>.
         /// </summary>
         /// <param name="name"> the name of the field </param>

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e694ee94/src/Lucene.Net/Lucene.Net.csproj
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Lucene.Net.csproj b/src/Lucene.Net/Lucene.Net.csproj
index ff96872..d2b8e6e 100644
--- a/src/Lucene.Net/Lucene.Net.csproj
+++ b/src/Lucene.Net/Lucene.Net.csproj
@@ -394,6 +394,7 @@
     <Compile Include="Index\TwoStoredFieldsConsumers.cs" />
     <Compile Include="Index\UpgradeIndexMergePolicy.cs" />
     <Compile Include="LucenePackage.cs" />
+    <Compile Include="Support\Document\DocumentExtensions.cs" />
     <Compile Include="Support\IO\Compression\LZOCompressor.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Search\AutomatonQuery.cs" />

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e694ee94/src/Lucene.Net/Support/Document/DocumentExtensions.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Support/Document/DocumentExtensions.cs b/src/Lucene.Net/Support/Document/DocumentExtensions.cs
new file mode 100644
index 0000000..c04dc21
--- /dev/null
+++ b/src/Lucene.Net/Support/Document/DocumentExtensions.cs
@@ -0,0 +1,39 @@
+´╗┐using Lucene.Net.Index;
+using System.Linq;
+
+namespace Lucene.Net.Documents
+{
+    /// <summary>
+    /// Extension methods to the <see cref="Document"/> class.
+    /// </summary>
+    public static class DocumentExtensions
+    {
+        /// <summary>
+        /// Returns a field with the given name if any exist in this document cast to type
<typeparam name="T"/>, or
+        /// <c>null</c>. If multiple fields exists with this name, this method
returns the
+        /// first value added.
+        /// <para/>
+        /// LUCENENET specific
+        /// </summary>
+        /// <exception cref="InvalidCastException">If the field type cannot be cast
to <typeparam name="T"/>.</exception>
+        public static T GetField<T>(this Document document, string name) where T :
IIndexableField
+        {
+            return (T)document.GetField(name);
+        }
+
+        /// <summary>
+        /// Returns an array of <see cref="IIndexableField"/>s with the given name,
cast to type <typeparam name="T"/>.
+        /// This method returns an empty array when there are no
+        /// matching fields. It never returns <c>null</c>.
+        /// <para/>
+        /// LUCENENET specific
+        /// </summary>
+        /// <param name="name"> the name of the field </param>
+        /// <returns> a <see cref="T:IndexableField[]"/> array </returns>
+        /// <exception cref="InvalidCastException">If the field type cannot be cast
to <typeparam name="T"/>.</exception>
+        public static T[] GetFields<T>(this Document document, string name) where T
: IIndexableField
+        {
+            return document.GetFields(name).Cast<T>().ToArray();
+        }
+    }
+}


Mime
View raw message