我正在尝试创建一个自定义solr过滤器,它只保留具有最大整数值的标记。在这样做的时候,到目前为止我编写了以下代码:
public final class MaxValueTokenFilter extends TokenFilter {
private final CharTermAttribute termAttribute = addAttribute(CharTermAttribute.class);
public MaxValueTokenFilter(TokenStream in) {
super(in);
}
@Override
public boolean incrementToken() throws IOException {
TokenStream clonedTokenStream = DeepCopy???(input);
int maxVal = 0;
//increamenting the clonedTokenStream should not increment the actual tokenStream
while (clonedToken.incrementToken()) {
final String term = termAttribute.toString();
int currentNumber = Integer.parseInt(term);
if(currentNumber > maxVal)
{
maxVal = currentNumber;
}
}
//increment the actual token to match the maximum value
while (input.incrementToken()) {
final String term = termAttribute.toString();
int currentNumber = Integer.parseInt(term);
if(currentNumber == maxVal)
{
return true;
}
}
return false;
}
@Override
public void reset() throws IOException {
super.reset();
}
}
有人可以帮我制作TokenStream对象的DeepCopy,这样增加复制的TokenStream就不会增加实际的TokenStream。