You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2018/11/30 09:04:00 UTC
[5/6] lucene-solr:branch_7x: LUCENE-8575: Improve toString() in
SegmentInfo
LUCENE-8575: Improve toString() in SegmentInfo
Signed-off-by: Namgyu Kim <kn...@gmail.com>
Signed-off-by: Adrien Grand <jp...@gmail.com>
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/8c4c3cff
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/8c4c3cff
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/8c4c3cff
Branch: refs/heads/branch_7x
Commit: 8c4c3cffa388a3289037b67b8aeafa5d727e98f4
Parents: e021e57
Author: Namgyu Kim <kn...@gmail.com>
Authored: Wed Nov 28 23:56:30 2018 +0900
Committer: Adrien Grand <jp...@gmail.com>
Committed: Fri Nov 30 09:43:05 2018 +0100
----------------------------------------------------------------------
lucene/CHANGES.txt | 3 ++
.../org/apache/lucene/index/SegmentInfo.java | 12 ++++-
.../apache/lucene/index/TestSegmentInfos.java | 53 ++++++++++++++++++++
3 files changed, 67 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/8c4c3cff/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 4331f02..08ee759 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -30,6 +30,9 @@ Improvements
* LUCENE-8529: TopSuggestDocsCollector will now use the completion key to tiebreak completion
suggestion with identical scores. (Jim Ferenczi)
+* LUCENE-8575: SegmentInfos#toString now includes attributes and diagnostics.
+ (Namgyu Kim via Adrien Grand)
+
Optimizations
* LUCENE-8552: FieldInfos.getMergedFieldInfos no longer does any merging if there is <= 1 segment.
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/8c4c3cff/lucene/core/src/java/org/apache/lucene/index/SegmentInfo.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/index/SegmentInfo.java b/lucene/core/src/java/org/apache/lucene/index/SegmentInfo.java
index 5e6d773..7c91eeb 100644
--- a/lucene/core/src/java/org/apache/lucene/index/SegmentInfo.java
+++ b/lucene/core/src/java/org/apache/lucene/index/SegmentInfo.java
@@ -211,7 +211,17 @@ public final class SegmentInfo {
s.append(']');
}
- // TODO: we could append toString of attributes() here?
+ if (!diagnostics.isEmpty()) {
+ s.append(":[diagnostics=");
+ s.append(diagnostics.toString());
+ s.append(']');
+ }
+
+ if (!attributes.isEmpty()) {
+ s.append(":[attributes=");
+ s.append(attributes.toString());
+ s.append(']');
+ }
return s.toString();
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/8c4c3cff/lucene/core/src/test/org/apache/lucene/index/TestSegmentInfos.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestSegmentInfos.java b/lucene/core/src/test/org/apache/lucene/index/TestSegmentInfos.java
index efe13f6..effd5e0 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestSegmentInfos.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestSegmentInfos.java
@@ -18,7 +18,9 @@ package org.apache.lucene.index;
import org.apache.lucene.codecs.Codec;
+import org.apache.lucene.search.Sort;
import org.apache.lucene.store.BaseDirectoryWrapper;
+import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IOContext;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.StringHelper;
@@ -26,6 +28,9 @@ import org.apache.lucene.util.Version;
import java.io.IOException;
import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
public class TestSegmentInfos extends LuceneTestCase {
@@ -98,5 +103,53 @@ public class TestSegmentInfos extends LuceneTestCase {
assertEquals(Version.LATEST, sis.getCommitLuceneVersion());
dir.close();
}
+
+ /** Test toString method */
+ public void testToString() throws Throwable{
+ SegmentInfo si;
+ final Directory dir = newDirectory();
+ Codec codec = Codec.getDefault();
+
+ // diagnostics map
+ Map<String, String> diagnostics = new LinkedHashMap<>();
+ diagnostics.put("key1", "value1");
+ diagnostics.put("key2", "value2");
+
+ // attributes map
+ Map<String,String> attributes = new LinkedHashMap<>();
+ attributes.put("key1", "value1");
+ attributes.put("key2", "value2");
+
+ // diagnostics X, attributes X
+ si = new SegmentInfo(dir, Version.LATEST, Version.LATEST, "TEST", 10000, false, codec, Collections.emptyMap(), StringHelper.randomId(), new HashMap<>(), Sort.INDEXORDER);
+ assertEquals("TEST(" + Version.LATEST.toString() + ")" +
+ ":C10000" +
+ ":[indexSort=<doc>]", si.toString());
+
+ // diagnostics O, attributes X
+ si = new SegmentInfo(dir, Version.LATEST, Version.LATEST, "TEST", 10000, false, codec, diagnostics, StringHelper.randomId(), new HashMap<>(), Sort.INDEXORDER);
+ assertEquals("TEST(" + Version.LATEST.toString() + ")" +
+ ":C10000" +
+ ":[indexSort=<doc>]" +
+ ":[diagnostics={key1=value1, key2=value2}]", si.toString());
+
+ // diagnostics X, attributes O
+ si = new SegmentInfo(dir, Version.LATEST, Version.LATEST, "TEST", 10000, false, codec, Collections.emptyMap(), StringHelper.randomId(), attributes, Sort.INDEXORDER);
+ assertEquals("TEST(" + Version.LATEST.toString() + ")" +
+ ":C10000" +
+ ":[indexSort=<doc>]" +
+ ":[attributes={key1=value1, key2=value2}]", si.toString());
+
+ // diagnostics O, attributes O
+ si = new SegmentInfo(dir, Version.LATEST, Version.LATEST, "TEST", 10000, false, codec, diagnostics, StringHelper.randomId(), attributes, Sort.INDEXORDER);
+ System.out.println(si.toString());
+ assertEquals("TEST(" + Version.LATEST.toString() + ")" +
+ ":C10000" +
+ ":[indexSort=<doc>]" +
+ ":[diagnostics={key1=value1, key2=value2}]" +
+ ":[attributes={key1=value1, key2=value2}]", si.toString());
+
+ dir.close();
+ }
}