r112196 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112195‎ | r112196 | r112197 >
Date:10:33, 23 February 2012
Author:oren
Status:deferred
Tags:
Comment:
API upgrade necessitated by the deprecated next() methods
Modified paths:
  • /trunk/lucene-search-3/src/main/java/org/wikimedia/lsearch/analyzers/Aggregate.java (modified) (history)

Diff [purge]

Index: trunk/lucene-search-3/src/main/java/org/wikimedia/lsearch/analyzers/Aggregate.java
@@ -8,6 +8,8 @@
99 import org.apache.lucene.analysis.Analyzer;
1010 import org.apache.lucene.analysis.Token;
1111 import org.apache.lucene.analysis.TokenStream;
 12+import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
 13+import org.apache.lucene.analysis.tokenattributes.TermAttribute;
1214 import org.wikimedia.lsearch.config.IndexId;
1315
1416 /**
@@ -67,14 +69,40 @@
6870 this.flags = flags;
6971 }
7072
71 - private ArrayList<Token> toTokenArray(TokenStream stream) throws IOException {
 73+ private ArrayList<Token> toTokenArray(TokenStream tokenStream) throws IOException {
7274 ArrayList<Token> tt = new ArrayList<Token>();
73 - Token t = null;
74 - while( (t = stream.next()) != null && tt.size() < 0xff-1){
75 - tt.add(t);
76 - }
 75+
 76+ // TODO: remove 2.9.x api
 77+
 78+ /**
 79+ Token reusableToken = new Token();
 80+ while ((reusableToken = tokenStream.next(reusableToken)) != null
 81+ && tt.size() < 0xff - 1) {
 82+ tt.add(reusableToken);
 83+ }
 84+
 85+ */
 86+ OffsetAttribute offsetAttribute = (OffsetAttribute) tokenStream.getAttribute(OffsetAttribute.class);
 87+
 88+ TermAttribute termAttribute = (TermAttribute) tokenStream.getAttribute(TermAttribute.class);
 89+ //TODO: update above to 3.5 api by replacing with
 90+ //CharTermAttribute charTermAttribute = (CharTermAttribute) tokenStream.getAttribute(CharTermAttribute.class);
 91+
 92+
 93+ while (tokenStream.incrementToken() && tt.size() < 0xff - 1) {
 94+
 95+ tt.add(new Token(termAttribute.term(),offsetAttribute.startOffset(),offsetAttribute.endOffset()));
 96+ //TODO: update above to 3.5 api replacing with
 97+ //tt.add(new Token(charTermAttribute.toString(),offsetAttribute.startOffset(),offsetAttribute.endOffset()));
 98+
 99+
 100+ }
 101+ //}
77102 return tt;
78103 }
 104+
 105+
 106+
79107
80108 /** Number of tokens */
81109 public int length(){

Status & tagging log