You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by cp...@apache.org on 2017/02/20 17:58:25 UTC
[1/2] lucene-solr:branch_6x: LUCENE-7688: Add
OneMergeWrappingMergePolicy class. (Keith Laban, Christine Poerschke)
Repository: lucene-solr
Updated Branches:
refs/heads/branch_6x ea5181073 -> db83e582f
LUCENE-7688: Add OneMergeWrappingMergePolicy class. (Keith Laban, Christine Poerschke)
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/180614c1
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/180614c1
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/180614c1
Branch: refs/heads/branch_6x
Commit: 180614c1491a7e8ffa7b5aba5bab0ad646e2d5f4
Parents: ea51810
Author: Christine Poerschke <cp...@apache.org>
Authored: Mon Feb 20 17:19:54 2017 +0000
Committer: Christine Poerschke <cp...@apache.org>
Committed: Mon Feb 20 17:55:05 2017 +0000
----------------------------------------------------------------------
lucene/CHANGES.txt | 3 +
.../index/OneMergeWrappingMergePolicy.java | 72 +++++++++
.../index/TestOneMergeWrappingMergePolicy.java | 146 +++++++++++++++++++
3 files changed, 221 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/180614c1/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 8c1e3cd..c875587 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -56,6 +56,9 @@ New Features
implementation for analysis/tokenization (Clinton Gormley, Mike
McCandless)
+* LUCENE-7688: Add OneMergeWrappingMergePolicy class.
+ (Keith Laban, Christine Poerschke)
+
Bug Fixes
* LUCENE-7630: Fix (Edge)NGramTokenFilter to no longer drop payloads
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/180614c1/lucene/core/src/java/org/apache/lucene/index/OneMergeWrappingMergePolicy.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/index/OneMergeWrappingMergePolicy.java b/lucene/core/src/java/org/apache/lucene/index/OneMergeWrappingMergePolicy.java
new file mode 100644
index 0000000..982e8c2
--- /dev/null
+++ b/lucene/core/src/java/org/apache/lucene/index/OneMergeWrappingMergePolicy.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.index;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.function.UnaryOperator;
+
+/**
+ * A wrapping merge policy that wraps the {@link org.apache.lucene.index.MergePolicy.OneMerge}
+ * objects returned by the wrapped merge policy.
+ *
+ * @lucene.experimental
+ */
+public class OneMergeWrappingMergePolicy extends MergePolicyWrapper {
+
+ private final UnaryOperator<OneMerge> wrapOneMerge;
+
+ /**
+ * Constructor
+ *
+ * @param in - the wrapped merge policy
+ * @param wrapOneMerge - operator for wrapping OneMerge objects
+ */
+ public OneMergeWrappingMergePolicy(MergePolicy in, UnaryOperator<OneMerge> wrapOneMerge) {
+ super(in);
+ this.wrapOneMerge = wrapOneMerge;
+ }
+
+ @Override
+ public MergeSpecification findMerges(MergeTrigger mergeTrigger, SegmentInfos segmentInfos, IndexWriter writer)
+ throws IOException {
+ return wrapSpec(in.findMerges(mergeTrigger, segmentInfos, writer));
+ }
+
+ @Override
+ public MergeSpecification findForcedMerges(SegmentInfos segmentInfos, int maxSegmentCount,
+ Map<SegmentCommitInfo,Boolean> segmentsToMerge, IndexWriter writer) throws IOException {
+ return wrapSpec(in.findForcedMerges(segmentInfos, maxSegmentCount, segmentsToMerge, writer));
+ }
+
+ @Override
+ public MergeSpecification findForcedDeletesMerges(SegmentInfos segmentInfos, IndexWriter writer)
+ throws IOException {
+ return wrapSpec(in.findForcedDeletesMerges(segmentInfos, writer));
+ }
+
+ private MergeSpecification wrapSpec(MergeSpecification spec) {
+ MergeSpecification wrapped = spec == null ? null : new MergeSpecification();
+ if (wrapped != null) {
+ for (OneMerge merge : spec.merges) {
+ wrapped.add(wrapOneMerge.apply(merge));
+ }
+ }
+ return wrapped;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/180614c1/lucene/core/src/test/org/apache/lucene/index/TestOneMergeWrappingMergePolicy.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestOneMergeWrappingMergePolicy.java b/lucene/core/src/test/org/apache/lucene/index/TestOneMergeWrappingMergePolicy.java
new file mode 100644
index 0000000..f27437f
--- /dev/null
+++ b/lucene/core/src/test/org/apache/lucene/index/TestOneMergeWrappingMergePolicy.java
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.index;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.StringHelper;
+import org.apache.lucene.util.TestUtil;
+import org.apache.lucene.util.Version;
+import org.junit.Test;
+
+public class TestOneMergeWrappingMergePolicy extends LuceneTestCase {
+
+ private static class PredeterminedMergePolicy extends MergePolicy {
+
+ final private MergePolicy.MergeSpecification merges;
+ final private MergePolicy.MergeSpecification forcedMerges;
+ final private MergePolicy.MergeSpecification forcedDeletesMerges;
+
+ public PredeterminedMergePolicy(
+ MergePolicy.MergeSpecification merges,
+ MergePolicy.MergeSpecification forcedMerges,
+ MergePolicy.MergeSpecification forcedDeletesMerges) {
+ this.merges = merges;
+ this.forcedMerges = forcedMerges;
+ this.forcedDeletesMerges = forcedDeletesMerges;
+ }
+
+ @Override
+ public MergePolicy.MergeSpecification findMerges(MergeTrigger mergeTrigger, SegmentInfos segmentInfos, IndexWriter writer)
+ throws IOException {
+ return merges;
+ }
+
+ @Override
+ public MergePolicy.MergeSpecification findForcedMerges(SegmentInfos segmentInfos, int maxSegmentCount,
+ Map<SegmentCommitInfo,Boolean> segmentsToMerge, IndexWriter writer) throws IOException {
+ return forcedMerges;
+ }
+
+ @Override
+ public MergePolicy.MergeSpecification findForcedDeletesMerges(SegmentInfos segmentInfos, IndexWriter writer)
+ throws IOException {
+ return forcedDeletesMerges;
+ }
+
+ }
+
+ private static class WrappedOneMerge extends MergePolicy.OneMerge {
+
+ final MergePolicy.OneMerge original;
+
+ public WrappedOneMerge(MergePolicy.OneMerge original) {
+ super(original.segments);
+ this.original = original;
+ }
+
+ }
+
+ @Test
+ public void testSegmentsAreWrapped() throws IOException {
+ try (final Directory dir = newDirectory()) {
+ // first create random merge specs
+ final MergePolicy.MergeSpecification msM = createRandomMergeSpecification(dir);
+ final MergePolicy.MergeSpecification msF = createRandomMergeSpecification(dir);
+ final MergePolicy.MergeSpecification msD = createRandomMergeSpecification(dir);
+ // secondly, pass them to the predetermined merge policy constructor
+ final MergePolicy originalMP = new PredeterminedMergePolicy(msM, msF, msD);
+ // thirdly wrap the predetermined merge policy
+ final MergePolicy oneMergeWrappingMP = new OneMergeWrappingMergePolicy(
+ originalMP,
+ merge -> new WrappedOneMerge(merge));
+ // finally, ask for merges and check what we got
+ implTestSegmentsAreWrapped(msM, oneMergeWrappingMP.findMerges(null, null, null));
+ implTestSegmentsAreWrapped(msF, oneMergeWrappingMP.findForcedMerges(null, 0, null, null));
+ implTestSegmentsAreWrapped(msD, oneMergeWrappingMP.findForcedDeletesMerges(null, null));
+ }
+ }
+
+ private static void implTestSegmentsAreWrapped(MergePolicy.MergeSpecification originalMS, MergePolicy.MergeSpecification testMS) {
+ // wrapping does not add or remove merge specs
+ assertEquals((originalMS == null), (testMS == null));
+ if (originalMS == null) return;
+ assertEquals(originalMS.merges.size(), testMS.merges.size());
+ // wrapping does not re-order merge specs
+ for (int ii = 0; ii < originalMS.merges.size(); ++ii) {
+ final MergePolicy.OneMerge originalOM = originalMS.merges.get(ii);
+ final MergePolicy.OneMerge testOM = testMS.merges.get(ii);
+ // wrapping wraps
+ assertTrue(testOM instanceof WrappedOneMerge);
+ final WrappedOneMerge wrappedOM = (WrappedOneMerge)testOM;
+ // and what is wrapped is what was originally passed in
+ assertEquals(originalOM, wrappedOM.original);
+ }
+ }
+
+ private static MergePolicy.MergeSpecification createRandomMergeSpecification(Directory dir) {
+ MergePolicy.MergeSpecification ms;
+ if (0 < random().nextInt(10)) { // ~ 1 in 10 times return null
+ ms = new MergePolicy.MergeSpecification();
+ // append up to 10 (random non-sensical) one merge objects
+ for (int ii = 0; ii < random().nextInt(10); ++ii) {
+ final SegmentInfo si = new SegmentInfo(
+ dir, // dir
+ Version.LATEST, // version
+ TestUtil.randomSimpleString(random()), // name
+ random().nextInt(), // maxDoc
+ random().nextBoolean(), // isCompoundFile
+ null, // codec
+ Collections.emptyMap(), // diagnostics
+ TestUtil.randomSimpleString(// id
+ random(),
+ StringHelper.ID_LENGTH,
+ StringHelper.ID_LENGTH).getBytes(StandardCharsets.US_ASCII),
+ Collections.emptyMap(), // attributes
+ null /* indexSort */);
+ final List<SegmentCommitInfo> segments = new LinkedList<SegmentCommitInfo>();
+ segments.add(new SegmentCommitInfo(si, 0, 0, 0, 0));
+ ms.add(new MergePolicy.OneMerge(segments));
+ }
+ }
+ return null;
+ }
+
+}
[2/2] lucene-solr:branch_6x: SOLR-10175: turn
TestAnalyticsQParserPlugin's @Ignore into @AwaitsFix
Posted by cp...@apache.org.
SOLR-10175: turn TestAnalyticsQParserPlugin's @Ignore into @AwaitsFix
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/db83e582
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/db83e582
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/db83e582
Branch: refs/heads/branch_6x
Commit: db83e582f7976563eab76eafdacb5dae716f8aae
Parents: 180614c
Author: Christine Poerschke <cp...@apache.org>
Authored: Mon Feb 20 17:38:25 2017 +0000
Committer: Christine Poerschke <cp...@apache.org>
Committed: Mon Feb 20 17:55:21 2017 +0000
----------------------------------------------------------------------
.../test/org/apache/solr/search/TestAnalyticsQParserPlugin.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/db83e582/solr/core/src/test/org/apache/solr/search/TestAnalyticsQParserPlugin.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/search/TestAnalyticsQParserPlugin.java b/solr/core/src/test/org/apache/solr/search/TestAnalyticsQParserPlugin.java
index cfd6b75..937fe9c 100644
--- a/solr/core/src/test/org/apache/solr/search/TestAnalyticsQParserPlugin.java
+++ b/solr/core/src/test/org/apache/solr/search/TestAnalyticsQParserPlugin.java
@@ -18,6 +18,7 @@ package org.apache.solr.search;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.util.LuceneTestCase.AwaitsFix;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.response.QueryResponse;
@@ -31,12 +32,11 @@ import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.handler.component.MergeStrategy;
import org.apache.solr.handler.component.ShardResponse;
-import org.junit.Ignore;
import java.util.List;
import java.util.concurrent.Future;
import java.io.IOException;
-@Ignore
+@AwaitsFix(bugUrl = "https://issues.apache.org/jira/browse/SOLR-10175")
public class TestAnalyticsQParserPlugin extends QParserPlugin {