Lucene.Net.Search.MultiPhraseQuery: 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/86873c5a Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/86873c5a Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/86873c5a Branch: refs/heads/master Commit: 86873c5aa279831d336a7487819e3284682f8083 Parents: 56d6d6d Author: Shad Storhaug <[email protected]> Authored: Wed Jun 21 23:53:22 2017 +0700 Committer: Shad Storhaug <[email protected]> Committed: Thu Jun 22 00:13:02 2017 +0700 ---------------------------------------------------------------------- src/Lucene.Net/Search/MultiPhraseQuery.cs | 37 +++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucenenet/blob/86873c5a/src/Lucene.Net/Search/MultiPhraseQuery.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net/Search/MultiPhraseQuery.cs b/src/Lucene.Net/Search/MultiPhraseQuery.cs index 5e2491d..ea93931 100644 --- a/src/Lucene.Net/Search/MultiPhraseQuery.cs +++ b/src/Lucene.Net/Search/MultiPhraseQuery.cs @@ -42,6 +42,7 @@ namespace Lucene.Net.Search using TermsEnum = Lucene.Net.Index.TermsEnum; using TermState = Lucene.Net.Index.TermState; using ToStringUtils = Lucene.Net.Util.ToStringUtils; + using System.Collections; /// <summary> /// <see cref="MultiPhraseQuery"/> is a generalized version of <see cref="PhraseQuery"/>, with an added @@ -51,11 +52,25 @@ namespace Lucene.Net.Search /// <see cref="Add(Term)"/> on the term "Microsoft", then find all terms that have "app" as /// prefix using <c>MultiFields.GetFields(IndexReader).GetTerms(string)</c>, and use <see cref="MultiPhraseQuery.Add(Term[])"/> /// to add them to the query. + /// <para/> + /// Collection initializer note: To create and populate a <see cref="MultiPhraseQuery"/> + /// in a single statement, you can use the following example as a guide: + /// + /// <code> + /// var multiPhraseQuery = new MultiPhraseQuery() { + /// new Term("field", "microsoft"), + /// new Term("field", "office") + /// }; + /// </code> + /// Note that as long as you specify all of the parameters, you can use either + /// <see cref="Add(Term)"/>, <see cref="Add(Term[])"/>, or <see cref="Add(Term[], int)"/> + /// as the method to use to initialize. If there are multiple parameters, each parameter set + /// must be surrounded by curly braces. /// </summary> #if FEATURE_SERIALIZABLE [Serializable] #endif - public class MultiPhraseQuery : Query + public class MultiPhraseQuery : Query, IEnumerable<Term[]> // LUCENENET specific - implemented IEnumerable<Term[]>, which allows for use of collection initializer. See: https://stackoverflow.com/a/9195144 { private string field; private List<Term[]> termArrays = new List<Term[]>(); @@ -503,6 +518,26 @@ namespace Lucene.Net.Search } return true; } + + /// <summary> + /// Returns an enumerator that iterates through the <see cref="termArrays"/> collection. + /// </summary> + /// <returns>An enumerator that can be used to iterate through the <see cref="termArrays"/> collection.</returns> + // LUCENENET specific + public IEnumerator<Term[]> GetEnumerator() + { + return termArrays.GetEnumerator(); + } + + /// <summary> + /// Returns an enumerator that iterates through the <see cref="termArrays"/>. + /// </summary> + /// <returns>An enumerator that can be used to iterate through the <see cref="termArrays"/> collection.</returns> + // LUCENENET specific + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } } /// <summary>
