LUCENE-4842: Unbreak SynonymMap.Builder.join(String[],CharsRef)

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1457380 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Steven Rowe 2013-03-17 06:02:33 +00:00
parent 9316cb96f2
commit 9fffda8c34
2 changed files with 14 additions and 15 deletions

View File

@ -91,25 +91,20 @@ public class SynonymMap {
int upto = 0;
char[] buffer = reuse.chars;
for (String word : words) {
if (upto > 0) {
if (upto >= buffer.length) {
reuse.grow(upto);
buffer = reuse.chars;
}
buffer[upto++] = SynonymMap.WORD_SEPARATOR;
}
final int wordLen = word.length();
final int needed = upto + wordLen;
final int needed = (0 == upto ? wordLen : 1 + upto + wordLen); // Add 1 for WORD_SEPARATOR
if (needed > buffer.length) {
reuse.grow(needed);
buffer = reuse.chars;
}
if (upto > 0) {
buffer[upto++] = SynonymMap.WORD_SEPARATOR;
}
word.getChars(0, wordLen, buffer, upto);
upto += wordLen;
}
reuse.length = upto;
return reuse;
}

View File

@ -55,9 +55,13 @@ public class TestSynonymMapFilter extends BaseTokenStreamTestCase {
if (VERBOSE) {
System.out.println(" add input=" + input + " output=" + output + " keepOrig=" + keepOrig);
}
b.add(new CharsRef(input.replaceAll(" +", "\u0000")),
new CharsRef(output.replaceAll(" +", "\u0000")),
keepOrig);
CharsRef inputCharsRef = new CharsRef();
SynonymMap.Builder.join(input.split(" +"), inputCharsRef);
CharsRef outputCharsRef = new CharsRef();
SynonymMap.Builder.join(output.split(" +"), outputCharsRef);
b.add(inputCharsRef, outputCharsRef, keepOrig);
}
private void assertEquals(CharTermAttribute term, String expected) {