Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id E18C9200C7D for ; Tue, 16 May 2017 16:28:23 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id E0724160BAC; Tue, 16 May 2017 14:28:23 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 13854160B9D for ; Tue, 16 May 2017 16:28:22 +0200 (CEST) Received: (qmail 33649 invoked by uid 500); 16 May 2017 14:28:21 -0000 Mailing-List: contact commits-help@lucenenet.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: lucene-net-dev@lucenenet.apache.org Delivered-To: mailing list commits@lucenenet.apache.org Received: (qmail 33632 invoked by uid 99); 16 May 2017 14:28:21 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 May 2017 14:28:21 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id AA913E1789; Tue, 16 May 2017 14:28:21 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: nightowl888@apache.org To: commits@lucenenet.apache.org Date: Tue, 16 May 2017 14:28:21 -0000 Message-Id: <28aee8a14e0c49a495f474df6e71079e@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [01/10] lucenenet git commit: API: Added overloads of Analyzer.NewAnonymous() to accept a delegate method parameter for InitReader archived-at: Tue, 16 May 2017 14:28:24 -0000 Repository: lucenenet Updated Branches: refs/heads/master 14c3e7b12 -> aa609e3b2 API: Added overloads of Analyzer.NewAnonymous() to accept a delegate method parameter for InitReader Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/8eeb071e Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/8eeb071e Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/8eeb071e Branch: refs/heads/master Commit: 8eeb071e1583c1ebcfe5f6f65c575739f595c96d Parents: 14c3e7b Author: Shad Storhaug Authored: Sat May 13 07:12:28 2017 +0700 Committer: Shad Storhaug Committed: Tue May 16 18:57:48 2017 +0700 ---------------------------------------------------------------------- src/Lucene.Net/Analysis/Analyzer.cs | 96 +++++++++++++++++++++++++++++--- 1 file changed, 88 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8eeb071e/src/Lucene.Net/Analysis/Analyzer.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net/Analysis/Analyzer.cs b/src/Lucene.Net/Analysis/Analyzer.cs index f9f280b..ba27c90 100644 --- a/src/Lucene.Net/Analysis/Analyzer.cs +++ b/src/Lucene.Net/Analysis/Analyzer.cs @@ -94,7 +94,7 @@ namespace Lucene.Net.Analysis /// /// Creates a new instance with the ability to specify the body of the - /// method through the argument. + /// method through the parameter. /// Simple example: /// /// var analyzer = Analyzer.NewAnonymous(createComponents: (fieldName, reader) => @@ -111,7 +111,7 @@ namespace Lucene.Net.Analysis /// /// An delegate method that represents (is called by) the /// method. It accepts a fieldName and a reader and - /// returns the for this analyzer. + /// returns the for this analyzer. /// /// A new instance. public static Analyzer NewAnonymous(Func createComponents) @@ -121,7 +121,7 @@ namespace Lucene.Net.Analysis /// /// Creates a new instance with the ability to specify the body of the - /// method through the argument and allows the use of a . + /// method through the parameter and allows the use of a . /// Simple example: /// /// var analyzer = Analyzer.NewAnonymous(createComponents: (fieldName, reader) => @@ -138,13 +138,82 @@ namespace Lucene.Net.Analysis /// /// An delegate method that represents (is called by) the /// method. It accepts a fieldName and a reader and - /// returns the for this analyzer. + /// returns the for this analyzer. /// /// A custom instance. /// A new instance. public static Analyzer NewAnonymous(Func createComponents, ReuseStrategy reuseStrategy) { - return new AnonymousAnalyzer(createComponents, reuseStrategy); + return NewAnonymous(createComponents, null, reuseStrategy); + } + + /// + /// Creates a new instance with the ability to specify the body of the + /// method through the parameter, the body of the + /// method through the parameter. + /// Simple example: + /// + /// var analyzer = Analyzer.NewAnonymous(createComponents: (fieldName, reader) => + /// { + /// Tokenizer source = new FooTokenizer(reader); + /// TokenStream filter = new FooFilter(source); + /// filter = new BarFilter(filter); + /// return new TokenStreamComponents(source, filter); + /// }, initReader: (fieldName, reader) => + /// { + /// return new HTMLStripCharFilter(reader); + /// }); + /// + /// + /// LUCENENET specific + /// + /// + /// A delegate method that represents (is called by) the + /// method. It accepts a fieldName and a reader and + /// returns the for this analyzer. + /// + /// A delegate method that represents (is called by) the + /// method. It accepts a fieldName and a reader and + /// returns the that can be modified or wrapped by the method. + /// A new instance. + public static Analyzer NewAnonymous(Func createComponents, Func initReader) + { + return NewAnonymous(createComponents, initReader, GLOBAL_REUSE_STRATEGY); + } + + /// + /// Creates a new instance with the ability to specify the body of the + /// method through the parameter, the body of the + /// method through the parameter, and allows the use of a . + /// Simple example: + /// + /// var analyzer = Analyzer.NewAnonymous(createComponents: (fieldName, reader) => + /// { + /// Tokenizer source = new FooTokenizer(reader); + /// TokenStream filter = new FooFilter(source); + /// filter = new BarFilter(filter); + /// return new TokenStreamComponents(source, filter); + /// }, initReader: (fieldName, reader) => + /// { + /// return new HTMLStripCharFilter(reader); + /// }, reuseStrategy); + /// + /// + /// LUCENENET specific + /// + /// + /// A delegate method that represents (is called by) the + /// method. It accepts a fieldName and a reader and + /// returns the for this analyzer. + /// + /// A delegate method that represents (is called by) the + /// method. It accepts a fieldName and a reader and + /// returns the that can be modified or wrapped by the method. + /// A custom instance. + /// A new instance. + public static Analyzer NewAnonymous(Func createComponents, Func initReader, ReuseStrategy reuseStrategy) + { + return new AnonymousAnalyzer(createComponents, initReader, reuseStrategy); } /// @@ -399,18 +468,29 @@ namespace Lucene.Net.Analysis private class AnonymousAnalyzer : Analyzer { private readonly Func createComponents; + private readonly Func initReader; - public AnonymousAnalyzer(Func createComponents, ReuseStrategy reuseStrategy) + public AnonymousAnalyzer(Func createComponents, Func initReader, ReuseStrategy reuseStrategy) : base(reuseStrategy) { if (createComponents == null) throw new ArgumentNullException("createComponents"); this.createComponents = createComponents; + this.initReader = initReader; } protected internal override TokenStreamComponents CreateComponents(string fieldName, TextReader reader) { - return createComponents(fieldName, reader); + return this.createComponents(fieldName, reader); + } + + protected internal override TextReader InitReader(string fieldName, TextReader reader) + { + if (this.initReader != null) + { + return this.initReader(fieldName, reader); + } + return base.InitReader(fieldName, reader); } } } @@ -420,7 +500,7 @@ namespace Lucene.Net.Analysis /// access to the source () and the outer end (sink), an /// instance of which also serves as the /// returned by - /// . + /// . /// public class TokenStreamComponents {