Index: lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyCombined.java =================================================================== --- lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyCombined.java (revision 1438974) +++ lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyCombined.java (working copy) @@ -1132,6 +1132,23 @@ dir.close(); } + @Test + public void testEmptyString() throws Exception { + Directory dir = newDirectory(); + DirectoryTaxonomyWriter writer = new DirectoryTaxonomyWriter(dir); + CategoryPath cp1 = new CategoryPath("test"); + int ord1 = writer.addCategory(cp1); + CategoryPath cp2 = new CategoryPath("test", ""); + int ord2 = writer.addCategory(cp2); + assertTrue(ord1 != ord2); + TaxonomyReader reader = new DirectoryTaxonomyReader(writer); + writer.close(); + assertEquals(cp1, reader.getPath(ord1)); + assertEquals(cp2, reader.getPath(ord2)); + reader.close(); + dir.close(); + } + // TODO (Facet): test multiple readers, one writer. Have the multiple readers // using the same object (simulating threads) or different objects // (simulating processes). Index: lucene/facet/src/java/org/apache/lucene/facet/taxonomy/CategoryPath.java =================================================================== --- lucene/facet/src/java/org/apache/lucene/facet/taxonomy/CategoryPath.java (revision 1438974) +++ lucene/facet/src/java/org/apache/lucene/facet/taxonomy/CategoryPath.java (working copy) @@ -1,24 +1,26 @@ package org.apache.lucene.facet.taxonomy; -import org.apache.lucene.util.Constants; +/* +* 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. +*/ +import java.util.ArrayList; +import java.util.List; -/* - * 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. - */ +import org.apache.lucene.util.Constants; /** * Holds a sequence of string components, specifying the hierarchical name of a @@ -82,7 +84,19 @@ /** Construct from a given path, separating path components with {@code delimiter}. */ public CategoryPath(final String pathString, final char delimiter) { - String[] comps = pathString.split(Character.toString(delimiter)); + int upto = 0; + List compsList = new ArrayList(); + while (true) { + int next = pathString.indexOf(delimiter, upto); + if (next == -1) { + compsList.add(pathString.substring(upto)); + break; + } else { + compsList.add(pathString.substring(upto, next)); + upto = next+1; + } + } + String[] comps = compsList.toArray(new String[compsList.size()]); if (comps.length == 1 && comps[0].isEmpty()) { components = EMPTY.components; length = 0;