From 888a897063a350c1d119d6d605d994806f700f51 Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Tue, 28 Apr 2009 21:17:38 +0000 Subject: [PATCH] LUCENE-1616: switch to single setOffset API git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@769543 13f79535-47bb-0310-9956-ffa450edef68 --- common-build.xml | 2 +- .../apache/lucene/analysis/CharTokenizer.java | 3 +-- .../lucene/analysis/KeywordTokenizer.java | 3 +-- .../analysis/standard/StandardTokenizer.java | 3 +-- .../tokenattributes/OffsetAttribute.java | 19 ++++++++----------- .../lucene/index/DocInverterPerThread.java | 3 +-- .../analysis/TestCachingTokenFilter.java | 3 +-- .../lucene/index/TestTermVectorsReader.java | 3 +-- .../lucene/queryParser/TestMultiAnalyzer.java | 3 +-- .../lucene/queryParser/TestQueryParser.java | 6 ++---- .../lucene/search/TestPositionIncrement.java | 3 +-- 11 files changed, 19 insertions(+), 32 deletions(-) diff --git a/common-build.xml b/common-build.xml index f3d88305c5a..9730308d996 100644 --- a/common-build.xml +++ b/common-build.xml @@ -41,7 +41,7 @@ - + diff --git a/src/java/org/apache/lucene/analysis/CharTokenizer.java b/src/java/org/apache/lucene/analysis/CharTokenizer.java index 5d090e71640..dc80aac30f8 100644 --- a/src/java/org/apache/lucene/analysis/CharTokenizer.java +++ b/src/java/org/apache/lucene/analysis/CharTokenizer.java @@ -90,8 +90,7 @@ public abstract class CharTokenizer extends Tokenizer { } termAtt.setTermLength(length); - offsetAtt.setStartOffset(start); - offsetAtt.setEndOffset(start+length); + offsetAtt.setOffset(start, start+length); return true; } diff --git a/src/java/org/apache/lucene/analysis/KeywordTokenizer.java b/src/java/org/apache/lucene/analysis/KeywordTokenizer.java index 3576ac15472..b367a304045 100644 --- a/src/java/org/apache/lucene/analysis/KeywordTokenizer.java +++ b/src/java/org/apache/lucene/analysis/KeywordTokenizer.java @@ -59,8 +59,7 @@ public class KeywordTokenizer extends Tokenizer { buffer = termAtt.resizeTermBuffer(1+buffer.length); } termAtt.setTermLength(upto); - offsetAtt.setStartOffset(0); - offsetAtt.setEndOffset(upto); + offsetAtt.setOffset(0, upto); return true; } return false; diff --git a/src/java/org/apache/lucene/analysis/standard/StandardTokenizer.java b/src/java/org/apache/lucene/analysis/standard/StandardTokenizer.java index 035697bc6ec..e1885abc473 100644 --- a/src/java/org/apache/lucene/analysis/standard/StandardTokenizer.java +++ b/src/java/org/apache/lucene/analysis/standard/StandardTokenizer.java @@ -161,8 +161,7 @@ public class StandardTokenizer extends Tokenizer { posIncrAtt.setPositionIncrement(posIncr); scanner.getText(termAtt); final int start = scanner.yychar(); - offsetAtt.setStartOffset(start); - offsetAtt.setEndOffset(start+termAtt.termLength()); + offsetAtt.setOffset(start, start+termAtt.termLength()); // This 'if' should be removed in the next release. For now, it converts // invalid acronyms to HOST. When removed, only the 'else' part should // remain. diff --git a/src/java/org/apache/lucene/analysis/tokenattributes/OffsetAttribute.java b/src/java/org/apache/lucene/analysis/tokenattributes/OffsetAttribute.java index d562257787d..93585e1353c 100644 --- a/src/java/org/apache/lucene/analysis/tokenattributes/OffsetAttribute.java +++ b/src/java/org/apache/lucene/analysis/tokenattributes/OffsetAttribute.java @@ -43,11 +43,14 @@ public class OffsetAttribute extends Attribute implements Cloneable, Serializabl return startOffset; } - /** Set the starting offset. - @see #startOffset() */ - public void setStartOffset(int offset) { - this.startOffset = offset; + + /** Set the starting and ending offset. + @see #startOffset() and #endOffset()*/ + public void setOffset(int startOffset, int endOffset) { + this.startOffset = startOffset; + this.endOffset = endOffset; } + /** Returns this Token's ending offset, one greater than the position of the last character corresponding to this token in the source text. The length @@ -56,11 +59,6 @@ public class OffsetAttribute extends Attribute implements Cloneable, Serializabl return endOffset; } - /** Set the ending offset. - @see #endOffset() */ - public void setEndOffset(int offset) { - this.endOffset = offset; - } public void clear() { startOffset = 0; @@ -92,7 +90,6 @@ public class OffsetAttribute extends Attribute implements Cloneable, Serializabl public void copyTo(Attribute target) { OffsetAttribute t = (OffsetAttribute) target; - t.setStartOffset(startOffset); - t.setEndOffset(endOffset); + t.setOffset(startOffset, endOffset); } } diff --git a/src/java/org/apache/lucene/index/DocInverterPerThread.java b/src/java/org/apache/lucene/index/DocInverterPerThread.java index 19cf39311cc..b2a8737e1ec 100644 --- a/src/java/org/apache/lucene/index/DocInverterPerThread.java +++ b/src/java/org/apache/lucene/index/DocInverterPerThread.java @@ -53,8 +53,7 @@ final class DocInverterPerThread extends DocFieldConsumerPerThread { public void reinit(String stringValue, int startOffset, int endOffset) { termAttribute.setTermBuffer(stringValue); - offsetAttribute.setStartOffset(startOffset); - offsetAttribute.setEndOffset(endOffset); + offsetAttribute.setOffset(startOffset, endOffset); } } diff --git a/src/test/org/apache/lucene/analysis/TestCachingTokenFilter.java b/src/test/org/apache/lucene/analysis/TestCachingTokenFilter.java index 188343921fe..bd8589ba430 100644 --- a/src/test/org/apache/lucene/analysis/TestCachingTokenFilter.java +++ b/src/test/org/apache/lucene/analysis/TestCachingTokenFilter.java @@ -51,8 +51,7 @@ public class TestCachingTokenFilter extends LuceneTestCase { return false; } else { termAtt.setTermBuffer(tokens[index++]); - offsetAtt.setStartOffset(0); - offsetAtt.setEndOffset(0); + offsetAtt.setOffset(0,0); return true; } } diff --git a/src/test/org/apache/lucene/index/TestTermVectorsReader.java b/src/test/org/apache/lucene/index/TestTermVectorsReader.java index a7b07838fd1..8d2b9140276 100644 --- a/src/test/org/apache/lucene/index/TestTermVectorsReader.java +++ b/src/test/org/apache/lucene/index/TestTermVectorsReader.java @@ -137,8 +137,7 @@ public class TestTermVectorsReader extends LuceneTestCase { else { final TestToken testToken = tokens[tokenUpto++]; termAtt.setTermBuffer(testToken.text); - offsetAtt.setStartOffset(testToken.startOffset); - offsetAtt.setEndOffset(testToken.endOffset); + offsetAtt.setOffset(testToken.startOffset, testToken.endOffset); if (tokenUpto > 1) { posIncrAtt.setPositionIncrement(testToken.pos - tokens[tokenUpto-2].pos); } else { diff --git a/src/test/org/apache/lucene/queryParser/TestMultiAnalyzer.java b/src/test/org/apache/lucene/queryParser/TestMultiAnalyzer.java index 2f0253eaba8..528a2c65d2f 100644 --- a/src/test/org/apache/lucene/queryParser/TestMultiAnalyzer.java +++ b/src/test/org/apache/lucene/queryParser/TestMultiAnalyzer.java @@ -163,8 +163,7 @@ public class TestMultiAnalyzer extends LuceneTestCase { public final boolean incrementToken() throws java.io.IOException { if (multiToken > 0) { termAtt.setTermBuffer("multi"+(multiToken+1)); - offsetAtt.setStartOffset(prevStartOffset); - offsetAtt.setEndOffset(prevEndOffset); + offsetAtt.setOffset(prevStartOffset, prevEndOffset); typeAtt.setType(prevType); posIncrAtt.setPositionIncrement(0); multiToken--; diff --git a/src/test/org/apache/lucene/queryParser/TestQueryParser.java b/src/test/org/apache/lucene/queryParser/TestQueryParser.java index f6c297758e3..f88e38f9df6 100644 --- a/src/test/org/apache/lucene/queryParser/TestQueryParser.java +++ b/src/test/org/apache/lucene/queryParser/TestQueryParser.java @@ -85,8 +85,7 @@ public class TestQueryParser extends LuceneTestCase { if (inPhrase) { inPhrase = false; termAtt.setTermBuffer("phrase2"); - offsetAtt.setStartOffset(savedStart); - offsetAtt.setEndOffset(savedEnd); + offsetAtt.setOffset(savedStart, savedEnd); return true; } else while (input.incrementToken()) { @@ -95,8 +94,7 @@ public class TestQueryParser extends LuceneTestCase { savedStart = offsetAtt.startOffset(); savedEnd = offsetAtt.endOffset(); termAtt.setTermBuffer("phrase1"); - offsetAtt.setStartOffset(savedStart); - offsetAtt.setEndOffset(savedEnd); + offsetAtt.setOffset(savedStart, savedEnd); return true; } else if (!termAtt.term().equals("stop")) return true; diff --git a/src/test/org/apache/lucene/search/TestPositionIncrement.java b/src/test/org/apache/lucene/search/TestPositionIncrement.java index 9c303cf1a3b..fe5f93b0dd2 100644 --- a/src/test/org/apache/lucene/search/TestPositionIncrement.java +++ b/src/test/org/apache/lucene/search/TestPositionIncrement.java @@ -59,8 +59,7 @@ public class TestPositionIncrement extends LuceneTestCase { if (i == TOKENS.length) return false; termAtt.setTermBuffer(TOKENS[i]); - offsetAtt.setStartOffset(i); - offsetAtt.setEndOffset(i); + offsetAtt.setOffset(i,i); posIncrAtt.setPositionIncrement(INCREMENTS[i]); i++; return true;