LUCENE-4209: suggester fixes to not leave behind files in /tmp

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1359873 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2012-07-10 20:04:33 +00:00
parent e48f99c36c
commit 524fa2d4f6
5 changed files with 13 additions and 5 deletions

View File

@ -43,6 +43,10 @@ Bug Fixes
so that it works correctly with Analyzers that produce binary non-UTF-8 terms
such as CollationAnalyzer. (Nattapong Sirilappanich via Robert Muir)
* LUCENE-4209: Fix FSTCompletionLookup to close its sorter, so that it won't
leave temp files behind in /tmp. Fix SortedTermFreqIteratorWrapper to not
leave temp files behind in /tmp on Windows. (Uwe Schindler, Robert Muir)
Build
* LUCENE-4094: Support overriding file.encoding on forked test JVMs

View File

@ -128,13 +128,13 @@ public class SortedTermFreqIteratorWrapper implements TermFreqIterator {
}
private void close() throws IOException {
IOUtils.close(reader);
if (tempInput != null) {
tempInput.delete();
}
if (tempSorted != null) {
tempSorted.delete();
}
IOUtils.close(reader);
}
private final static class BytesOnlyComparator implements Comparator<BytesRef> {

View File

@ -150,6 +150,7 @@ public class FSTCompletionLookup extends Lookup {
Sort.ByteSequencesWriter writer = new Sort.ByteSequencesWriter(tempInput);
Sort.ByteSequencesReader reader = null;
ExternalRefSorter sorter = null;
// Push floats up front before sequences to sort them. For now, assume they are non-negative.
// If negative floats are allowed some trickery needs to be done to find their byte order.
@ -175,7 +176,7 @@ public class FSTCompletionLookup extends Lookup {
SortInfo info = new Sort().sort(tempInput, tempSorted);
tempInput.delete();
FSTCompletionBuilder builder = new FSTCompletionBuilder(
buckets, new ExternalRefSorter(new Sort()), sharedTailLength);
buckets, sorter = new ExternalRefSorter(new Sort()), sharedTailLength);
final int inputLines = info.lines;
reader = new Sort.ByteSequencesReader(tempSorted);
@ -215,9 +216,9 @@ public class FSTCompletionLookup extends Lookup {
success = true;
} finally {
if (success)
IOUtils.close(reader, writer);
IOUtils.close(reader, writer, sorter);
else
IOUtils.closeWhileHandlingException(reader, writer);
IOUtils.closeWhileHandlingException(reader, writer, sorter);
tempInput.delete();
tempSorted.delete();

View File

@ -25,7 +25,9 @@ import org.junit.Test;
public class BytesRefSortersTest extends LuceneTestCase {
@Test
public void testExternalRefSorter() throws Exception {
check(new ExternalRefSorter(new Sort()));
ExternalRefSorter s = new ExternalRefSorter(new Sort());
check(s);
s.close();
}
@Test

View File

@ -56,5 +56,6 @@ public class LargeInputFST {
File fstFile = new File("completion.fst");
System.out.println("Done. Writing automaton: " + fstFile.getAbsolutePath());
completion.getFST().save(fstFile);
sorter.close();
}
}