Skip to content

Apache Lucene open-source search software

LUCENE-5339: nocommits

Michael McCandless5edc798fda3c
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/FacetsConfig.java b/lucene/facet/src/java/org/apache/lucene/facet/FacetsConfig.java
index 79f1e0bf65d..f1d02fab192 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/FacetsConfig.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/FacetsConfig.java
@@ -490,6 +490,9 @@ public class FacetsConfig {
StringBuilder sb = new StringBuilder();
for(int i=0;i<length;i++) {
String s = path[i];
+ if (s.length() == 0) {
+ throw new IllegalArgumentException("each path component must have length > 0 (got: \"\")");
+ }
int numChars = s.length();
for(int j=0;j<numChars;j++) {
char ch = s.charAt(j);
@@ -512,6 +515,9 @@ public class FacetsConfig {
public static String[] stringToPath(String s) {
List<String> parts = new ArrayList<String>();
int length = s.length();
+ if (length == 0) {
+ return new String[0];
+ }
char[] buffer = new char[length];
int upto = 0;
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/FacetLabel.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/FacetLabel.java
index 3af439356cc..e793d41bcf2 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/FacetLabel.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/FacetLabel.java
@@ -18,9 +18,7 @@ package org.apache.lucene.facet.taxonomy;
*/
import java.util.Arrays;
-import java.util.regex.Pattern;
-import org.apache.lucene.facet.FacetsConfig;
import static org.apache.lucene.util.ByteBlockPool.BYTE_BLOCK_SIZE;
@@ -30,7 +28,6 @@ import static org.apache.lucene.util.ByteBlockPool.BYTE_BLOCK_SIZE;
*
* @lucene.experimental
*/
-// nocommit rename to just Label under .facet?
public class FacetLabel implements Comparable<FacetLabel> {
/*
@@ -79,7 +76,8 @@ public class FacetLabel implements Comparable<FacetLabel> {
/** Construct from the given path components. */
public FacetLabel(final String... components) {
- assert components.length > 0 : "use CategoryPath.EMPTY to create an empty path";
+ // nocommit why so anal?
+ // assert components.length > 0 : "use CategoryPath.EMPTY to create an empty path";
long len = 0;
for (String comp : components) {
if (comp == null || comp.isEmpty()) {
@@ -105,51 +103,6 @@ public class FacetLabel implements Comparable<FacetLabel> {
return new FacetLabel(components);
}
- /** Construct from a given path, separating path components with {@code delimiter}. */
- public FacetLabel(final String pathString, final char delimiter) {
- if (pathString.length() > MAX_CATEGORY_PATH_LENGTH) {
- throw new IllegalArgumentException("category path exceeds maximum allowed path length: max="
- + MAX_CATEGORY_PATH_LENGTH + " len=" + pathString.length()
- + " path=" + pathString.substring(0, 30) + "...");
- }
-
- // nocommit
- String[] comps;
- if (delimiter == '\u001F') {
- comps = FacetsConfig.stringToPath(pathString);
- } else {
- comps = pathString.split(Pattern.quote(Character.toString(delimiter)));
- }
- if (comps.length == 1 && comps[0].isEmpty()) {
- components = null;
- length = 0;
- } else {
- for (String comp : comps) {
- if (comp == null || comp.isEmpty()) {
- throw new IllegalArgumentException("empty or null components not allowed: " + Arrays.toString(comps));
- }
- }
- components = comps;
- length = components.length;
- }
- }
-
- /**
- * Returns the number of characters needed to represent the path, including
- * delimiter characters, for using with
- * {@link #copyFullPath(char[], int, char)}.
- */
- public int fullPathLength() {
- if (length == 0) return 0;
-
- int charsNeeded = 0;
- for (int i = 0; i < length; i++) {
- charsNeeded += components[i].length();
- }
- charsNeeded += length - 1; // num delimter chars
- return charsNeeded;
- }
-
/**
* Compares this path with another {@link FacetLabel} for lexicographic
* order.
@@ -167,48 +120,6 @@ public class FacetLabel implements Comparable<FacetLabel> {
return length - other.length;
}
- private void hasDelimiter(String offender, char delimiter) {
- throw new IllegalArgumentException("delimiter character '" + delimiter + "' (U+" + Integer.toHexString(delimiter) + ") appears in path component \"" + offender + "\"");
- }
-
- private void noDelimiter(char[] buf, int offset, int len, char delimiter) {
- for(int idx=0;idx<len;idx++) {
- if (buf[offset+idx] == delimiter) {
- hasDelimiter(new String(buf, offset, len), delimiter);
- }
- }
- }
-
- /**
- * Copies the path components to the given {@code char[]}, starting at index
- * {@code start}. {@code delimiter} is copied between the path components.
- * Returns the number of chars copied.
- *
- * <p>
- * <b>NOTE:</b> this method relies on the array being large enough to hold the
- * components and separators - the amount of needed space can be calculated
- * with {@link #fullPathLength()}.
- */
- public int copyFullPath(char[] buf, int start, char delimiter) {
- if (length == 0) {
- return 0;
- }
-
- int idx = start;
- int upto = length - 1;
- for (int i = 0; i < upto; i++) {
- int len = components[i].length();
- components[i].getChars(0, len, buf, idx);
- noDelimiter(buf, idx, len, delimiter);
- idx += len;
- buf[idx++] = delimiter;
- }
- components[upto].getChars(0, components[upto].length(), buf, idx);
- noDelimiter(buf, idx, components[upto].length(), delimiter);
-
- return idx + components[upto].length() - start;
- }
-
@Override
public boolean equals(Object obj) {
if (!(obj instanceof FacetLabel)) {
@@ -275,29 +186,11 @@ public class FacetLabel implements Comparable<FacetLabel> {
*/
@Override
public String toString() {
- return toString('/');
- }
-
- /**
- * Returns a string representation of the path, separating components with the
- * given delimiter.
- */
-
- public String toString(char delimiter) {
- // nocommit
- if (delimiter == '\u001F') {
- return FacetsConfig.pathToString(components, length);
- } else {
- if (length == 0) return "";
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < length; i++) {
- if (components[i].indexOf(delimiter) != -1) {
- hasDelimiter(components[i], delimiter);
- }
- sb.append(components[i]).append(delimiter);
- }
- sb.setLength(sb.length() - 1); // remove last delimiter
- return sb.toString();
+ if (length == 0) {
+ return "FacetLabel: []";
}
+ String[] parts = new String[length];
+ System.arraycopy(components, 0, parts, 0, length);
+ return "FacetLabel: " + Arrays.toString(parts);
}
}
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/PrintTaxonomyStats.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/PrintTaxonomyStats.java
index c04d67b9116..b063ce2ac6b 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/PrintTaxonomyStats.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/PrintTaxonomyStats.java
@@ -64,7 +64,7 @@ public class PrintTaxonomyStats {
numImmediateChildren++;
}
FacetLabel cp = r.getPath(child);
- out.println("/" + cp + ": " + numImmediateChildren + " immediate children; " + (1+countAllChildren(r, child)) + " total categories");
+ out.println("/" + cp.components[0] + ": " + numImmediateChildren + " immediate children; " + (1+countAllChildren(r, child)) + " total categories");
if (printTree) {
printAllChildren(out, r, child, " ", 1);
}
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/Consts.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/Consts.java
index b3d8850cb4f..2f103e86dc6 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/Consts.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/Consts.java
@@ -23,23 +23,8 @@ import org.apache.lucene.util.BytesRef;
* @lucene.experimental
*/
abstract class Consts {
-
static final String FULL = "$full_path$";
static final String FIELD_PAYLOADS = "$payloads$";
static final String PAYLOAD_PARENT = "p";
static final BytesRef PAYLOAD_PARENT_BYTES_REF = new BytesRef(PAYLOAD_PARENT);
-
- /**
- * Delimiter used for creating the full path of a category from the list of
- * its labels from root. It is forbidden for labels to contain this
- * character.
- * <P>
- * Originally, we used \uFFFE, officially a "unicode noncharacter" (invalid
- * unicode character) for this purpose. Recently, we switched to the
- * "private-use" character \uF749. Even more recently, we
- * switched to \U001F (INFORMATION_SEPARATOR).
- */
- //static final char DEFAULT_DELIMITER = '\uFFFE';
- //static final char DEFAULT_DELIMITER = '\uF749';
- static final char DEFAULT_DELIMITER = '\u001F';
}
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyReader.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyReader.java
index ea4b897c2e3..931e3b8fe11 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyReader.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyReader.java
@@ -5,6 +5,7 @@ import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
+import org.apache.lucene.facet.FacetsConfig;
import org.apache.lucene.facet.taxonomy.FacetLabel;
import org.apache.lucene.facet.taxonomy.LRUHashMap;
import org.apache.lucene.facet.taxonomy.ParallelTaxonomyArrays;
@@ -65,8 +66,6 @@ public class DirectoryTaxonomyReader extends TaxonomyReader {
private volatile TaxonomyIndexArrays taxoArrays;
- private char delimiter = Consts.DEFAULT_DELIMITER;
-
/**
* Called only from {@link #doOpenIfChanged()}. If the taxonomy has been
* recreated, you should pass {@code null} as the caches and parent/children
@@ -270,7 +269,7 @@ public class DirectoryTaxonomyReader extends TaxonomyReader {
// If we're still here, we have a cache miss. We need to fetch the
// value from disk, and then also put it in the cache:
int ret = TaxonomyReader.INVALID_ORDINAL;
- DocsEnum docs = MultiFields.getTermDocsEnum(indexReader, null, Consts.FULL, new BytesRef(cp.toString(delimiter)), 0);
+ DocsEnum docs = MultiFields.getTermDocsEnum(indexReader, null, Consts.FULL, new BytesRef(FacetsConfig.pathToString(cp.components, cp.length)), 0);
if (docs != null && docs.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
ret = docs.docID();
@@ -310,7 +309,7 @@ public class DirectoryTaxonomyReader extends TaxonomyReader {
}
StoredDocument doc = indexReader.document(ordinal);
- FacetLabel ret = new FacetLabel(doc.get(Consts.FULL), delimiter);
+ FacetLabel ret = new FacetLabel(FacetsConfig.stringToPath(doc.get(Consts.FULL)));
synchronized (categoryCache) {
categoryCache.put(catIDInteger, ret);
}
@@ -343,21 +342,6 @@ public class DirectoryTaxonomyReader extends TaxonomyReader {
}
}
- /**
- * setDelimiter changes the character that the taxonomy uses in its
- * internal storage as a delimiter between category components. Do not
- * use this method unless you really know what you are doing.
- * <P>
- * If you do use this method, make sure you call it before any other
- * methods that actually queries the taxonomy. Moreover, make sure you
- * always pass the same delimiter for all LuceneTaxonomyWriter and
- * LuceneTaxonomyReader objects you create.
- */
- public void setDelimiter(char delimiter) {
- ensureOpen();
- this.delimiter = delimiter;
- }
-
public String toString(int max) {
ensureOpen();
StringBuilder sb = new StringBuilder();
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java
index 00907742291..5b97eb27b2f 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java
@@ -104,8 +104,7 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {
// Records the taxonomy index epoch, updated on replaceTaxonomy as well.
private long indexEpoch;
-
- private char delimiter = Consts.DEFAULT_DELIMITER;
+
private SinglePositionTokenStream parentStream = new SinglePositionTokenStream(Consts.PAYLOAD_PARENT);
private Field parentStreamField;
private Field fullPathField;
@@ -140,23 +139,6 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {
return infos.getUserData();
}
- /**
- * Changes the character that the taxonomy uses in its internal storage as a
- * delimiter between category components. Do not use this method unless you
- * really know what you are doing. It has nothing to do with whatever
- * character the application may be using to represent categories for its own
- * use.
- * <p>
- * If you do use this method, make sure you call it before any other methods
- * that actually queries the taxonomy. Moreover, make sure you always pass the
- * same delimiter for all taxonomy writer and reader instances you create for
- * the same directory.
- */
- public void setDelimiter(char delimiter) {
- ensureOpen();
- this.delimiter = delimiter;
- }
-
/**
* Forcibly unlocks the taxonomy in the named directory.
* <P>
@@ -422,7 +404,7 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {
int doc = -1;
DirectoryReader reader = readerManager.acquire();
try {
- final BytesRef catTerm = new BytesRef(categoryPath.toString(delimiter));
+ final BytesRef catTerm = new BytesRef(FacetsConfig.pathToString(categoryPath.components, categoryPath.length));
TermsEnum termsEnum = null; // reuse
DocsEnum docs = null; // reuse
for (AtomicReaderContext ctx : reader.leaves()) {
@@ -730,7 +712,7 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {
// hence documents), there are no deletions in the index. Therefore, it
// is sufficient to call next(), and then doc(), exactly once with no
// 'validation' checks.
- FacetLabel cp = new FacetLabel(t.utf8ToString(), delimiter);
+ FacetLabel cp = new FacetLabel(FacetsConfig.stringToPath(t.utf8ToString()));
docsEnum = termsEnum.docs(null, docsEnum, DocsEnum.FLAG_NONE);
boolean res = cache.put(cp, docsEnum.nextDoc() + ctx.docBase);
assert !res : "entries should not have been evicted from the cache";
@@ -819,8 +801,7 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {
final Terms terms = ar.terms(Consts.FULL);
te = terms.iterator(te);
while (te.next() != null) {
- String value = te.term().utf8ToString();
- FacetLabel cp = new FacetLabel(value, delimiter);
+ FacetLabel cp = new FacetLabel(FacetsConfig.stringToPath(te.term().utf8ToString()));
final int ordinal = addCategory(cp);
docs = te.docs(null, docs, DocsEnum.FLAG_NONE);
ordinalMap.addMapping(docs.nextDoc() + base, ordinal);
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/writercache/CompactLabelToOrdinal.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/writercache/CompactLabelToOrdinal.java
index fed23edf86c..53acee1358e 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/writercache/CompactLabelToOrdinal.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/writercache/CompactLabelToOrdinal.java
@@ -125,7 +125,7 @@ public class CompactLabelToOrdinal extends LabelToOrdinal {
int prevVal = collisionMap.addLabel(label, hash, ordinal);
if (prevVal != ordinal) {
- throw new IllegalArgumentException("Label already exists: " + label.toString('/') + " prev ordinal " + prevVal);
+ throw new IllegalArgumentException("Label already exists: " + label + " prev ordinal " + prevVal);
}
}
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/TestFacetsConfig.java b/lucene/facet/src/test/org/apache/lucene/facet/TestFacetsConfig.java
index a0822768fbf..5a745cbdc80 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/TestFacetsConfig.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/TestFacetsConfig.java
@@ -19,7 +19,6 @@ package org.apache.lucene.facet;
import java.util.Arrays;
-import org.apache.lucene.facet.FacetTestCase;
import org.apache.lucene.util._TestUtil;
public class TestFacetsConfig extends FacetTestCase {
@@ -29,7 +28,14 @@ public class TestFacetsConfig extends FacetTestCase {
int numParts = _TestUtil.nextInt(random(), 1, 6);
String[] parts = new String[numParts];
for(int j=0;j<numParts;j++) {
- parts[j] = _TestUtil.randomUnicodeString(random());
+ String s;
+ while (true) {
+ s = _TestUtil.randomUnicodeString(random());
+ if (s.length() > 0) {
+ break;
+ }
+ }
+ parts[j] = s;
}
String s = FacetsConfig.pathToString(parts);
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestFacetLabel.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestFacetLabel.java
index 85abea0087b..f1ba467dd39 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestFacetLabel.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestFacetLabel.java
@@ -35,11 +35,11 @@ public class TestFacetLabel extends FacetTestCase {
@Test
public void testToString() {
// When the category is empty, we expect an empty string
- assertEquals("", FacetLabel.EMPTY.toString('/'));
- // one category (so no delimiter needed)
- assertEquals("hello", new FacetLabel("hello").toString('/'));
- // more than one category (so no delimiter needed)
- assertEquals("hello/world", new FacetLabel("hello", "world").toString('/'));
+ assertEquals("FacetLabel: []", FacetLabel.EMPTY.toString());
+ // one category
+ assertEquals("FacetLabel: [hello]", new FacetLabel("hello").toString());
+ // more than one category
+ assertEquals("FacetLabel: [hello, world]", new FacetLabel("hello", "world").toString());
}
@Test
@@ -54,21 +54,6 @@ public class TestFacetLabel extends FacetTestCase {
}
}
- @Test
- public void testDelimiterConstructor() {
- FacetLabel p = new FacetLabel("", '/');
- assertEquals(0, p.length);
- p = new FacetLabel("hello", '/');
- assertEquals(p.length, 1);
- assertEquals(p.toString('@'), "hello");
- p = new FacetLabel("hi/there", '/');
- assertEquals(p.length, 2);
- assertEquals(p.toString('@'), "hi@there");
- p = new FacetLabel("how/are/you/doing?", '/');
- assertEquals(p.length, 4);
- assertEquals(p.toString('@'), "how@are@you@doing?");
- }
-
@Test
public void testDefaultConstructor() {
// test that the default constructor (no parameters) currently
@@ -77,7 +62,7 @@ public class TestFacetLabel extends FacetTestCase {
// test.
FacetLabel p = FacetLabel.EMPTY;
assertEquals(0, p.length);
- assertEquals("", p.toString('/'));
+ assertEquals("FacetLabel: []", p.toString());
}
@Test
@@ -87,22 +72,22 @@ public class TestFacetLabel extends FacetTestCase {
FacetLabel p1 = p.subpath(2);
assertEquals(2, p1.length);
- assertEquals("hi/there", p1.toString('/'));
+ assertEquals("FacetLabel: [hi, there]", p1.toString());
p1 = p.subpath(1);
assertEquals(1, p1.length);
- assertEquals("hi", p1.toString('/'));
+ assertEquals("FacetLabel: [hi]", p1.toString());
p1 = p.subpath(0);
assertEquals(0, p1.length);
- assertEquals("", p1.toString('/'));
+ assertEquals("FacetLabel: []", p1.toString());
// with all the following lengths, the prefix should be the whole path
int[] lengths = { 3, -1, 4 };
for (int i = 0; i < lengths.length; i++) {
p1 = p.subpath(lengths[i]);
assertEquals(3, p1.length);
- assertEquals("hi/there/man", p1.toString('/'));
+ assertEquals("FacetLabel: [hi, there, man]", p1.toString());
assertEquals(p, p1);
}
}
@@ -133,47 +118,25 @@ public class TestFacetLabel extends FacetTestCase {
public void testArrayConstructor() {
FacetLabel p = new FacetLabel("hello", "world", "yo");
assertEquals(3, p.length);
- assertEquals("hello/world/yo", p.toString('/'));
- }
-
- @Test
- public void testCharsNeededForFullPath() {
- assertEquals(0, FacetLabel.EMPTY.fullPathLength());
- String[] components = { "hello", "world", "yo" };
- FacetLabel cp = new FacetLabel(components);
- int expectedCharsNeeded = 0;
- for (String comp : components) {
- expectedCharsNeeded += comp.length();
- }
- expectedCharsNeeded += cp.length - 1; // delimiter chars
- assertEquals(expectedCharsNeeded, cp.fullPathLength());
- }
-
- @Test
- public void testCopyToCharArray() {
- FacetLabel p = new FacetLabel("hello", "world", "yo");
- char[] charArray = new char[p.fullPathLength()];
- int numCharsCopied = p.copyFullPath(charArray, 0, '.');
- assertEquals(p.fullPathLength(), numCharsCopied);
- assertEquals("hello.world.yo", new String(charArray, 0, numCharsCopied));
+ assertEquals("FacetLabel: [hello, world, yo]", p.toString());
}
@Test
public void testCompareTo() {
- FacetLabel p = new FacetLabel("a/b/c/d", '/');
- FacetLabel pother = new FacetLabel("a/b/c/d", '/');
+ FacetLabel p = new FacetLabel("a", "b", "c", "d");
+ FacetLabel pother = new FacetLabel("a", "b", "c", "d");
assertEquals(0, pother.compareTo(p));
assertEquals(0, p.compareTo(pother));
- pother = new FacetLabel("", '/');
+ pother = new FacetLabel();
assertTrue(pother.compareTo(p) < 0);
assertTrue(p.compareTo(pother) > 0);
- pother = new FacetLabel("a/b_/c/d", '/');
+ pother = new FacetLabel("a", "b_", "c", "d");
assertTrue(pother.compareTo(p) > 0);
assertTrue(p.compareTo(pother) < 0);
- pother = new FacetLabel("a/b/c", '/');
+ pother = new FacetLabel("a", "b", "c");
assertTrue(pother.compareTo(p) < 0);
assertTrue(p.compareTo(pother) > 0);
- pother = new FacetLabel("a/b/c/e", '/');
+ pother = new FacetLabel("a", "b", "c", "e");
assertTrue(pother.compareTo(p) > 0);
assertTrue(p.compareTo(pother) < 0);
}
@@ -198,82 +161,6 @@ public class TestFacetLabel extends FacetTestCase {
// ok
}
}
-
- String[] path_tests = new String[] {
- "/test", // empty in the beginning
- "test//foo", // empty in the middle
- };
-
- for (String path : path_tests) {
- try {
- assertNotNull(new FacetLabel(path, '/'));
- fail("empty or null components should not be allowed: " + path);
- } catch (IllegalArgumentException e) {
- // ok
- }
- }
-
- // a trailing path separator is produces only one component
- assertNotNull(new FacetLabel("test/", '/'));
-
- }
-
- @Test
- public void testInvalidDelimChar() throws Exception {
- // Make sure CategoryPath doesn't silently corrupt:
- char[] buf = new char[100];
- FacetLabel cp = new FacetLabel("foo/bar");
- try {
- cp.toString();
- fail("expected exception");
- } catch (IllegalArgumentException iae) {
- // expected
- }
- try {
- cp.copyFullPath(buf, 0, '/');
- fail("expected exception");
- } catch (IllegalArgumentException iae) {
- // expected
- }
- cp = new FacetLabel("abc", "foo/bar");
- try {
- cp.toString();
- fail("expected exception");
- } catch (IllegalArgumentException iae) {
- // expected
- }
- try {
- cp.copyFullPath(buf, 0, '/');
- fail("expected exception");
- } catch (IllegalArgumentException iae) {
- // expected
- }
- cp = new FacetLabel("foo:bar");
- try {
- cp.toString(':');
- fail("expected exception");
- } catch (IllegalArgumentException iae) {
- // expected
- }
- try {
- cp.copyFullPath(buf, 0, ':');
- fail("expected exception");
- } catch (IllegalArgumentException iae) {
- // expected
- }
- cp = new FacetLabel("abc", "foo:bar");
- try {
- cp.toString(':');
- fail("expected exception");
- } catch (IllegalArgumentException iae) {
- // expected
- }
- try {
- cp.copyFullPath(buf, 0, ':');
- fail("expected exception");
- } catch (IllegalArgumentException iae) {
- // expected
- }
}
@Test
@@ -294,13 +181,5 @@ public class TestFacetLabel extends FacetTestCase {
} catch (IllegalArgumentException e) {
// expected
}
-
- try {
- assertNotNull(new FacetLabel("dim\u001f" + bigComp, '\u001f'));
- fail("long paths should not be allowed; len=" + bigComp.length());
- } catch (IllegalArgumentException e) {
- // expected
- }
}
-
}
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyCombined.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyCombined.java
index 205c1944422..727b67c3862 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyCombined.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyCombined.java
@@ -147,7 +147,7 @@ public class TestTaxonomyCombined extends FacetTestCase {
if (path.length==0) {
return "<empty>";
}
- return "<"+path.toString('/')+">";
+ return "<"+path.toString()+">";
}
/** Basic tests for TaxonomyWriter. Basically, we test that
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestConcurrentFacetedIndexing.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestConcurrentFacetedIndexing.java
index f0bc44c7c6f..635d504ecde 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestConcurrentFacetedIndexing.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestConcurrentFacetedIndexing.java
@@ -1,8 +1,6 @@
package org.apache.lucene.facet.taxonomy.directory;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
@@ -112,7 +110,7 @@ public class TestConcurrentFacetedIndexing extends FacetTestCase {
// add all prefixes to values
int level = label.length;
while (level > 0) {
- String s = label.subpath(level).toString('/');
+ String s = FacetsConfig.pathToString(label.components, level);
values.put(s, s);
--level;
}
@@ -133,7 +131,7 @@ public class TestConcurrentFacetedIndexing extends FacetTestCase {
assertEquals("mismatch number of categories", values.size() + 1, tr.getSize()); // +1 for root category
int[] parents = tr.getParallelTaxonomyArrays().parents();
for (String cat : values.keySet()) {
- FacetLabel cp = new FacetLabel(cat, '/');
+ FacetLabel cp = new FacetLabel(FacetsConfig.stringToPath(cat));
assertTrue("category not found " + cp, tr.getOrdinal(cp) > 0);
int level = cp.length;
int parentOrd = 0; // for root, parent is always virtual ROOT (ord=0)
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java
index 01800ebdad1..a02ac0c1cc3 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/directory/TestDirectoryTaxonomyWriter.java
@@ -1,7 +1,6 @@
package org.apache.lucene.facet.taxonomy.directory;
import java.io.IOException;
-import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
@@ -271,10 +270,10 @@ public class TestDirectoryTaxonomyWriter extends FacetTestCase {
Integer.toString(value / 100000), Integer.toString(value));
int ord = tw.addCategory(cp);
assertTrue("invalid parent for ordinal " + ord + ", category " + cp, tw.getParent(ord) != -1);
- String l1 = cp.subpath(1).toString('/');
- String l2 = cp.subpath(2).toString('/');
- String l3 = cp.subpath(3).toString('/');
- String l4 = cp.subpath(4).toString('/');
+ String l1 = FacetsConfig.pathToString(cp.components, 1);
+ String l2 = FacetsConfig.pathToString(cp.components, 2);
+ String l3 = FacetsConfig.pathToString(cp.components, 3);
+ String l4 = FacetsConfig.pathToString(cp.components, 4);
values.put(l1, l1);
values.put(l2, l2);
values.put(l3, l3);
@@ -295,7 +294,7 @@ public class TestDirectoryTaxonomyWriter extends FacetTestCase {
assertEquals("mismatch number of categories", values.size() + 1, dtr.getSize()); // +1 for root category
int[] parents = dtr.getParallelTaxonomyArrays().parents();
for (String cat : values.keySet()) {
- FacetLabel cp = new FacetLabel(cat, '/');
+ FacetLabel cp = new FacetLabel(FacetsConfig.stringToPath(cat));
assertTrue("category not found " + cp, dtr.getOrdinal(cp) > 0);
int level = cp.length;
int parentOrd = 0; // for root, parent is always virtual ROOT (ord=0)
@@ -472,11 +471,11 @@ public class TestDirectoryTaxonomyWriter extends FacetTestCase {
// build source, large, taxonomy
DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(srcTaxoDir);
- int ord = taxoWriter.addCategory(new FacetLabel("A/1/1/1/1/1/1", '/'));
+ int ord = taxoWriter.addCategory(new FacetLabel("A", "1", "1", "1", "1", "1", "1"));
taxoWriter.close();
taxoWriter = new DirectoryTaxonomyWriter(targetTaxoDir);
- int ordinal = taxoWriter.addCategory(new FacetLabel("B/1", '/'));
+ int ordinal = taxoWriter.addCategory(new FacetLabel("B", "1"));
assertEquals(1, taxoWriter.getParent(ordinal)); // call getParent to initialize taxoArrays
taxoWriter.commit();
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/writercache/TestCompactLabelToOrdinal.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/writercache/TestCompactLabelToOrdinal.java
index 5b2f700099e..711b443b662 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/writercache/TestCompactLabelToOrdinal.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/writercache/TestCompactLabelToOrdinal.java
@@ -57,7 +57,8 @@ public class TestCompactLabelToOrdinal extends FacetTestCase {
.onMalformedInput(CodingErrorAction.REPLACE);
uniqueValues[i] = decoder.decode(ByteBuffer.wrap(buffer, 0, size)).toString();
// we cannot have empty path components, so eliminate all prefix as well
- // as middle consecuive delimiter chars.
+ // as middle consecutive delimiter chars.
+ // nocommit remove
uniqueValues[i] = uniqueValues[i].replaceAll("/+", "/");
if (uniqueValues[i].startsWith("/")) {
uniqueValues[i] = uniqueValues[i].substring(1);
@@ -82,7 +83,13 @@ public class TestCompactLabelToOrdinal extends FacetTestCase {
}
int index = random.nextInt(numUniqueValues);
- FacetLabel label = new FacetLabel(uniqueValues[index], '/');
+ FacetLabel label;
+ String s = uniqueValues[index];
+ if (s.length() == 0) {
+ label = FacetLabel.EMPTY;
+ } else {
+ label = new FacetLabel(s.split("/"));
+ }
int ord1 = map.getOrdinal(label);
int ord2 = compact.getOrdinal(label);
@@ -97,7 +104,13 @@ public class TestCompactLabelToOrdinal extends FacetTestCase {
}
for (int i = 0; i < numUniqueValues; i++) {
- FacetLabel label = new FacetLabel(uniqueValues[i], '/');
+ FacetLabel label;
+ String s = uniqueValues[i];
+ if (s.length() == 0) {
+ label = FacetLabel.EMPTY;
+ } else {
+ label = new FacetLabel(s.split("/"));
+ }
int ord1 = map.getOrdinal(label);
int ord2 = compact.getOrdinal(label);
assertEquals(ord1, ord2);