lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [33/38] lucenenet git commit: Lucene.Net.Queries.CommonTermsQuery: Implemented IEnumerable<T> so collection initializer can be used and added documentation to show usage of collection initializer
Date Thu, 22 Jun 2017 05:25:34 GMT
Lucene.Net.Queries.CommonTermsQuery: Implemented IEnumerable<T> so collection initializer
can be used and added documentation to show usage of collection initializer


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

Branch: refs/heads/master
Commit: a632950c14a7608e2f98e3f38a740e21d5787c72
Parents: 121684b
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Wed Jun 21 23:56:32 2017 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Thu Jun 22 00:13:04 2017 +0700

----------------------------------------------------------------------
 src/Lucene.Net.Queries/CommonTermsQuery.cs | 35 +++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a632950c/src/Lucene.Net.Queries/CommonTermsQuery.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/CommonTermsQuery.cs b/src/Lucene.Net.Queries/CommonTermsQuery.cs
index dfc4b4a..701dbd6 100644
--- a/src/Lucene.Net.Queries/CommonTermsQuery.cs
+++ b/src/Lucene.Net.Queries/CommonTermsQuery.cs
@@ -3,6 +3,7 @@ using Lucene.Net.Search;
 using Lucene.Net.Support;
 using Lucene.Net.Util;
 using System;
+using System.Collections;
 using System.Collections.Generic;
 using System.Diagnostics;
 using System.Globalization;
@@ -27,7 +28,7 @@ namespace Lucene.Net.Queries
      * See the License for the specific language governing permissions and
      * limitations under the License.
      */
-    
+
     /// <summary>
     /// A query that executes high-frequency terms in a optional sub-query to prevent
     /// slow queries due to "common" terms like stopwords. This query
@@ -52,8 +53,18 @@ namespace Lucene.Net.Queries
     /// rewritten into a plain conjunction query ie. all high-frequency terms need to
     /// match in order to match a document.
     /// </para>
+    /// <para/>
+    /// Collection initializer note: To create and populate a <see cref="CommonTermsQuery"/>
+    /// in a single statement, you can use the following example as a guide:
+    /// 
+    /// <code>
+    /// var query = new CommonTermsQuery() {
+    ///     new Term("field", "microsoft"), 
+    ///     new Term("field", "office")
+    /// };
+    /// </code>
     /// </summary>
-    public class CommonTermsQuery : Query
+    public class CommonTermsQuery : Query, IEnumerable<Term> // LUCENENET specific
- implemented IEnumerable<Term>, which allows for use of collection initializer. See:
https://stackoverflow.com/a/9195144
     {
         /*
          * TODO maybe it would make sense to abstract this even further and allow to
@@ -476,5 +487,25 @@ namespace Lucene.Net.Queries
         {
             return context == null ? new TermQuery(term) : new TermQuery(term, context);
         }
+
+        /// <summary>
+        /// Returns an enumerator that iterates through the <see cref="m_terms"/> collection.
+        /// </summary>
+        /// <returns>An enumerator that can be used to iterate through the <see
cref="m_terms"/> collection.</returns>
+        // LUCENENET specific
+        public IEnumerator<Term> GetEnumerator()
+        {
+            return this.m_terms.GetEnumerator();
+        }
+
+        /// <summary>
+        /// Returns an enumerator that iterates through the <see cref="m_terms"/> collection.
+        /// </summary>
+        /// <returns>An enumerator that can be used to iterate through the <see
cref="m_terms"/> collection.</returns>
+        // LUCENENET specific
+        IEnumerator IEnumerable.GetEnumerator()
+        {
+            return GetEnumerator();
+        }
     }
 }
\ No newline at end of file


Mime
View raw message