LUCENE-6606: SegmentInfo.toString now includes the sorter if SortingMergePolicy was used

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1687976 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2015-06-27 23:17:18 +00:00
parent 8e4b427926
commit e85c95c75c
3 changed files with 31 additions and 8 deletions

View File

@ -101,6 +101,10 @@ New Features
in GeoPoint, (4) add thread-safety where missing -- Geo3dShape. (Karl Wright,
David Smiley)
* LUCENE-6606: SegmentInfo.toString now confesses how the documents
were sorted, when SortingMergePolicy was used (Christine Poerschke
via Mike McCandless)
API Changes
* LUCENE-6508: Simplify Lock api, there is now just

View File

@ -173,12 +173,13 @@ public final class SegmentInfo {
/** Used for debugging. Format may suddenly change.
*
* <p>Current format looks like
* <code>_a(3.1):c45/4</code>, which means the segment's
* name is <code>_a</code>; it was created with Lucene 3.1 (or
* <code>_a(3.1):c45/4:[sorter=&lt;long: "timestamp"&gt;!]</code>, which means
* the segment's name is <code>_a</code>; it was created with Lucene 3.1 (or
* '?' if it's unknown); it's using compound file
* format (would be <code>C</code> if not compound); it
* has 45 documents; it has 4 deletions (this part is
* left off when there are no deletions).</p>
* left off when there are no deletions); it is sorted by the timestamp field
* in descending order (this part is omitted for unsorted segments).</p>
*/
public String toString(int delCount) {
StringBuilder s = new StringBuilder();
@ -192,6 +193,16 @@ public final class SegmentInfo {
s.append('/').append(delCount);
}
final String sorter_key = "sorter"; // SortingMergePolicy.SORTER_ID_PROP; // TODO: use this once we can import SortingMergePolicy (currently located in 'misc' instead of 'core')
final String sorter_val = diagnostics.get(sorter_key);
if (sorter_val != null) {
s.append(":[");
s.append(sorter_key);
s.append('=');
s.append(sorter_val);
s.append(']');
}
// TODO: we could append toString of attributes() here?
return s.toString();

View File

@ -53,13 +53,19 @@ public class TestSortingMergePolicy extends LuceneTestCase {
private List<String> terms;
private Directory dir1, dir2;
private Sort sort;
private boolean reversedSort;
private IndexReader reader;
private IndexReader sortedReader;
@Override
public void setUp() throws Exception {
super.setUp();
sort = new Sort(new SortField("ndv", SortField.Type.LONG));
final Boolean reverse = (random().nextBoolean() ? null : new Boolean(random().nextBoolean()));
final SortField sort_field = (reverse == null
? new SortField("ndv", SortField.Type.LONG)
: new SortField("ndv", SortField.Type.LONG, reverse.booleanValue()));
sort = new Sort(sort_field);
reversedSort = (null != reverse && reverse.booleanValue());
createRandomIndexes();
}
@ -158,10 +164,12 @@ public class TestSortingMergePolicy extends LuceneTestCase {
super.tearDown();
}
private static void assertSorted(LeafReader reader) throws IOException {
private static void assertSorted(LeafReader reader, boolean reverse) throws IOException {
final NumericDocValues ndv = reader.getNumericDocValues("ndv");
for (int i = 1; i < reader.maxDoc(); ++i) {
assertTrue("ndv(" + (i-1) + ")=" + ndv.get(i-1) + ",ndv(" + i + ")=" + ndv.get(i), ndv.get(i-1) <= ndv.get(i));
final int lhs = (!reverse ? i-1 : i);
final int rhs = (!reverse ? i : i-1);
assertTrue("ndv(" + (i-1) + ")=" + ndv.get(i-1) + ",ndv(" + i + ")=" + ndv.get(i)+",reverse="+reverse, ndv.get(lhs) <= ndv.get(rhs));
}
}
@ -169,8 +177,8 @@ public class TestSortingMergePolicy extends LuceneTestCase {
final LeafReader sortedReader1 = SortingLeafReader.wrap(SlowCompositeReaderWrapper.wrap(reader), sort);
final LeafReader sortedReader2 = SlowCompositeReaderWrapper.wrap(sortedReader);
assertSorted(sortedReader1);
assertSorted(sortedReader2);
assertSorted(sortedReader1, reversedSort);
assertSorted(sortedReader2, reversedSort);
assertReaderEquals("", sortedReader1, sortedReader2);
}