mirror of https://github.com/apache/lucene.git
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:
parent
9316cb96f2
commit
9fffda8c34
|
@ -90,26 +90,21 @@ public class SynonymMap {
|
||||||
public static CharsRef join(String[] words, CharsRef reuse) {
|
public static CharsRef join(String[] words, CharsRef reuse) {
|
||||||
int upto = 0;
|
int upto = 0;
|
||||||
char[] buffer = reuse.chars;
|
char[] buffer = reuse.chars;
|
||||||
for(String word : words) {
|
for (String word : words) {
|
||||||
if (upto > 0) {
|
final int wordLen = word.length();
|
||||||
if (upto >= buffer.length) {
|
final int needed = (0 == upto ? wordLen : 1 + upto + wordLen); // Add 1 for WORD_SEPARATOR
|
||||||
reuse.grow(upto);
|
|
||||||
buffer = reuse.chars;
|
|
||||||
}
|
|
||||||
buffer[upto++] = SynonymMap.WORD_SEPARATOR;
|
|
||||||
}
|
|
||||||
|
|
||||||
final int wordLen = word.length();
|
|
||||||
final int needed = upto + wordLen;
|
|
||||||
if (needed > buffer.length) {
|
if (needed > buffer.length) {
|
||||||
reuse.grow(needed);
|
reuse.grow(needed);
|
||||||
buffer = reuse.chars;
|
buffer = reuse.chars;
|
||||||
}
|
}
|
||||||
|
if (upto > 0) {
|
||||||
|
buffer[upto++] = SynonymMap.WORD_SEPARATOR;
|
||||||
|
}
|
||||||
|
|
||||||
word.getChars(0, wordLen, buffer, upto);
|
word.getChars(0, wordLen, buffer, upto);
|
||||||
upto += wordLen;
|
upto += wordLen;
|
||||||
}
|
}
|
||||||
|
reuse.length = upto;
|
||||||
return reuse;
|
return reuse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,9 +55,13 @@ public class TestSynonymMapFilter extends BaseTokenStreamTestCase {
|
||||||
if (VERBOSE) {
|
if (VERBOSE) {
|
||||||
System.out.println(" add input=" + input + " output=" + output + " keepOrig=" + keepOrig);
|
System.out.println(" add input=" + input + " output=" + output + " keepOrig=" + keepOrig);
|
||||||
}
|
}
|
||||||
b.add(new CharsRef(input.replaceAll(" +", "\u0000")),
|
CharsRef inputCharsRef = new CharsRef();
|
||||||
new CharsRef(output.replaceAll(" +", "\u0000")),
|
SynonymMap.Builder.join(input.split(" +"), inputCharsRef);
|
||||||
keepOrig);
|
|
||||||
|
CharsRef outputCharsRef = new CharsRef();
|
||||||
|
SynonymMap.Builder.join(output.split(" +"), outputCharsRef);
|
||||||
|
|
||||||
|
b.add(inputCharsRef, outputCharsRef, keepOrig);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertEquals(CharTermAttribute term, String expected) {
|
private void assertEquals(CharTermAttribute term, String expected) {
|
||||||
|
|
Loading…
Reference in New Issue