LUCENE-6988: IndexableField.tokenStream() no longer throws IOException

This commit is contained in:
Alan Woodward 2016-01-25 10:04:41 +00:00
parent b62c6715df
commit 75dd5e9f9e
10 changed files with 17 additions and 18 deletions

View File

@ -164,6 +164,9 @@ API Changes
* LUCENE-6932: IndexInput.seek implementations now throw EOFException
if you seek beyond the end of the file (Adrien Grand, Mike McCandless)
* LUCENE-6988: IndexableField.tokenStream() no longer throws IOException
(Alan Woodward)
Optimizations
* LUCENE-6951: Improve GeoPointInPolygonQuery using point orientation based

View File

@ -225,7 +225,7 @@ public abstract class StoredFieldsWriter implements Closeable {
}
@Override
public TokenStream tokenStream(Analyzer analyzer, TokenStream reuse) throws IOException {
public TokenStream tokenStream(Analyzer analyzer, TokenStream reuse) {
return null;
}

View File

@ -28,7 +28,6 @@ import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
import org.apache.lucene.index.IndexOptions;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.index.IndexableFieldType;
import org.apache.lucene.util.BytesRef;
@ -497,7 +496,7 @@ public class Field implements IndexableField {
}
@Override
public TokenStream tokenStream(Analyzer analyzer, TokenStream reuse) throws IOException {
public TokenStream tokenStream(Analyzer analyzer, TokenStream reuse) {
if (fieldType().indexOptions() == IndexOptions.NONE) {
// Not indexed
return null;

View File

@ -17,13 +17,12 @@ package org.apache.lucene.index;
* limitations under the License.
*/
import java.io.IOException;
import java.io.Reader;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.search.similarities.ClassicSimilarity; // javadocs
import org.apache.lucene.search.similarities.Similarity; // javadocs
import org.apache.lucene.search.similarities.ClassicSimilarity;
import org.apache.lucene.search.similarities.Similarity;
import org.apache.lucene.util.BytesRef;
// TODO: how to handle versioning here...?
@ -55,9 +54,8 @@ public interface IndexableField {
* check.
* @return TokenStream value for indexing the document. Should always return
* a non-null value if the field is to be indexed
* @throws IOException Can be thrown while creating the TokenStream
*/
public TokenStream tokenStream(Analyzer analyzer, TokenStream reuse) throws IOException;
public TokenStream tokenStream(Analyzer analyzer, TokenStream reuse);
/**
* Returns the field's index-time boost.

View File

@ -117,7 +117,7 @@ public class TestFieldReuse extends BaseTokenStreamTestCase {
}
@Override
public TokenStream tokenStream(Analyzer analyzer, TokenStream reuse) throws IOException {
public TokenStream tokenStream(Analyzer analyzer, TokenStream reuse) {
lastSeen = reuse;
return lastReturned = new CannedTokenStream(new Token("unimportant", 0, 10));
}

View File

@ -1786,7 +1786,7 @@ public class TestIndexWriterExceptions extends LuceneTestCase {
}
@Override
public TokenStream tokenStream(Analyzer analyzer, TokenStream reuse) throws IOException {
public TokenStream tokenStream(Analyzer analyzer, TokenStream reuse) {
return null;
}
});

View File

@ -17,7 +17,6 @@ package org.apache.lucene.index;
* limitations under the License.
*/
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.util.Collections;
@ -159,7 +158,7 @@ public class TestIndexableField extends LuceneTestCase {
}
@Override
public TokenStream tokenStream(Analyzer analyzer, TokenStream previous) throws IOException {
public TokenStream tokenStream(Analyzer analyzer, TokenStream previous) {
return readerValue() != null ? analyzer.tokenStream(name(), readerValue()) :
analyzer.tokenStream(name(), new StringReader(stringValue()));
}

View File

@ -191,7 +191,7 @@ public class LazyDocument {
}
@Override
public TokenStream tokenStream(Analyzer analyzer, TokenStream reuse) throws IOException {
public TokenStream tokenStream(Analyzer analyzer, TokenStream reuse) {
return getRealValue().tokenStream(analyzer, reuse);
}
}

View File

@ -17,8 +17,6 @@ package org.apache.lucene.codecs.idversion;
* limitations under the License.
*/
import java.io.IOException;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
@ -50,7 +48,7 @@ class StringAndPayloadField extends Field {
}
@Override
public TokenStream tokenStream(Analyzer analyzer, TokenStream reuse) throws IOException {
public TokenStream tokenStream(Analyzer analyzer, TokenStream reuse) {
SingleTokenWithPayloadTokenStream ts;
if (reuse instanceof SingleTokenWithPayloadTokenStream) {
ts = (SingleTokenWithPayloadTokenStream) reuse;

View File

@ -100,7 +100,7 @@ public class SuggestField extends Field {
}
@Override
public TokenStream tokenStream(Analyzer analyzer, TokenStream reuse) throws IOException {
public TokenStream tokenStream(Analyzer analyzer, TokenStream reuse) {
CompletionTokenStream completionStream = wrapTokenStream(super.tokenStream(analyzer, reuse));
completionStream.setPayload(buildSuggestPayload());
return completionStream;
@ -126,13 +126,15 @@ public class SuggestField extends Field {
return TYPE;
}
private BytesRef buildSuggestPayload() throws IOException {
private BytesRef buildSuggestPayload() {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try (OutputStreamDataOutput output = new OutputStreamDataOutput(byteArrayOutputStream)) {
output.writeVInt(surfaceForm.length);
output.writeBytes(surfaceForm.bytes, surfaceForm.offset, surfaceForm.length);
output.writeVInt(weight + 1);
output.writeByte(type());
} catch (IOException e) {
throw new RuntimeException(e); // not possible, it's a ByteArrayOutputStream!
}
return new BytesRef(byteArrayOutputStream.toByteArray());
}