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 53044200CBD for ; Thu, 22 Jun 2017 07:25:07 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 517AF160BF6; Thu, 22 Jun 2017 05:25:07 +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 E13DF160C04 for ; Thu, 22 Jun 2017 07:25:05 +0200 (CEST) Received: (qmail 81704 invoked by uid 500); 22 Jun 2017 05:25:05 -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 81177 invoked by uid 99); 22 Jun 2017 05:25:04 -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; Thu, 22 Jun 2017 05:25:04 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 0AD44E967F; Thu, 22 Jun 2017 05:25:03 +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: Thu, 22 Jun 2017 05:25:27 -0000 Message-Id: <57736974187c4d06a54580ed4424687a@git.apache.org> In-Reply-To: <231e7073b9444cdc955d02db32d1edee@git.apache.org> References: <231e7073b9444cdc955d02db32d1edee@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [26/38] lucenenet git commit: API: Lucene.Net.Search.Filter: Added NewAnonymous() method for easy creation of anonymous classes via delegate methods. archived-at: Thu, 22 Jun 2017 05:25:07 -0000 API: Lucene.Net.Search.Filter: Added NewAnonymous() method for easy creation of anonymous classes via delegate methods. Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/cbb4d3fb Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/cbb4d3fb Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/cbb4d3fb Branch: refs/heads/master Commit: cbb4d3fb8e5e226fdbcba859c34d348142fc482a Parents: de55c63 Author: Shad Storhaug Authored: Wed Jun 21 20:21:06 2017 +0700 Committer: Shad Storhaug Committed: Thu Jun 22 00:13:00 2017 +0700 ---------------------------------------------------------------------- src/Lucene.Net/Search/Filter.cs | 47 +++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cbb4d3fb/src/Lucene.Net/Search/Filter.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net/Search/Filter.cs b/src/Lucene.Net/Search/Filter.cs index ad0d726..3910edd 100644 --- a/src/Lucene.Net/Search/Filter.cs +++ b/src/Lucene.Net/Search/Filter.cs @@ -30,7 +30,7 @@ namespace Lucene.Net.Search #if FEATURE_SERIALIZABLE [Serializable] #endif - public abstract class Filter // LUCENENET TODO: API - Make static NewAnonymous() factory method with delegate method for GetDocIdSet() + public abstract class Filter { /// /// Creates a enumerating the documents that should be @@ -59,5 +59,50 @@ namespace Lucene.Net.Search /// the filter doesn't accept any documents otherwise internal optimization might not apply /// in the case an empty is returned. public abstract DocIdSet GetDocIdSet(AtomicReaderContext context, IBits acceptDocs); + + + /// + /// Creates a new instance with the ability to specify the body of the + /// method through the parameter. + /// Simple example: + /// + /// var filter = Filter.NewAnonymous(getDocIdSet: (context, acceptDocs) => + /// { + /// if (acceptDocs == null) acceptDocs = new Bits.MatchAllBits(5); + /// OpenBitSet bitset = new OpenBitSet(5); + /// if (acceptDocs.Get(1)) bitset.Set(1); + /// if (acceptDocs.Get(3)) bitset.Set(3); + /// return new DocIdBitSet(bitset); + /// }); + /// + /// + /// LUCENENET specific + /// + /// + /// A delegate method that represents (is called by) the + /// method. It accepts a context and a acceptDocs and + /// returns the for this filter. + /// + /// + public static Filter NewAnonymous(Func getDocIdSet) + { + return new AnonymousFilter(getDocIdSet); + } + + // LUCENENET specific + private class AnonymousFilter : Filter + { + private readonly Func getDocIdSet; + + public AnonymousFilter(Func getDocIdSet) + { + this.getDocIdSet = getDocIdSet; + } + + public override DocIdSet GetDocIdSet(AtomicReaderContext context, IBits acceptDocs) + { + return this.getDocIdSet(context, acceptDocs); + } + } } } \ No newline at end of file