You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by da...@apache.org on 2018/12/01 17:10:07 UTC
[19/32] lucene-solr:jira/http2: 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/c2ab0477
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/c2ab0477
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/c2ab0477
Branch: refs/heads/jira/http2
Commit: c2ab04775dd2b683f96e65c78a7a3696396d2263
Parents: c074b97
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:42:49 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/c2ab0477/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 88b09e9..f5b056e 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -231,6 +231,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/c2ab0477/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/c2ab0477/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 de78ffc..7611d15 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();
+ }
}