Index: src/main/java/org/apache/solr/analysis/CombiningFilterFactory.java =================================================================== --- src/main/java/org/apache/solr/analysis/CombiningFilterFactory.java (revision 0) +++ src/main/java/org/apache/solr/analysis/CombiningFilterFactory.java (revision 0) @@ -0,0 +1,37 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.solr.analysis; + +//Apache imports +import org.apache.lucene.analysis.TokenStream; +import org.apache.solr.analysis.BaseTokenFilterFactory; + +/** + * Constructs new {@link CombiningFilter}s. + * + * @author mattmann + * + */ +public class CombiningFilterFactory extends BaseTokenFilterFactory { + + @Override + public TokenStream create(TokenStream in) { + return new CombiningFilter(in); + } + +} Index: src/main/java/org/apache/solr/analysis/CombiningFilter.java =================================================================== --- src/main/java/org/apache/solr/analysis/CombiningFilter.java (revision 0) +++ src/main/java/org/apache/solr/analysis/CombiningFilter.java (revision 0) @@ -0,0 +1,58 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.solr.analysis; + +//JDK imports +import java.io.IOException; + +//Apache imports +import org.apache.lucene.analysis.TokenFilter; +import org.apache.lucene.analysis.TokenStream; + +/** + * Builds a {@link TokenFilter} responsible for reconstituting a stream of + * tokens into a single token {@link TokenStream}. + * + * We need this to do stop word analysis on a set of keywords, but to sort + * correctly. + * + * @author mattmann + * + */ +public class CombiningFilter extends TokenFilter { + + public CombiningFilter(TokenStream in) { + super(new TokenStreamMerger(in).createMergedTokenStream()); + } + + /* + * (non-Javadoc) + * + * @see org.apache.lucene.analysis.TokenStream#incrementToken() + */ + @Override + public boolean incrementToken() throws IOException { + if(!input.incrementToken()){ + input.clearAttributes(); + return false; + } + else return true; + + } + +} Index: src/main/java/org/apache/solr/analysis/TokenStreamMerger.java =================================================================== --- src/main/java/org/apache/solr/analysis/TokenStreamMerger.java (revision 0) +++ src/main/java/org/apache/solr/analysis/TokenStreamMerger.java (revision 0) @@ -0,0 +1,58 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.solr.analysis; + +//JDK imports +import java.io.IOException; +import java.io.StringReader; + +//Apache imports +import org.apache.lucene.analysis.KeywordTokenizer; +import org.apache.lucene.analysis.TokenStream; +import org.apache.lucene.analysis.tokenattributes.TermAttribute; + +/** + * Takes an existing {@link TokenStream} with many {@link Token}s, and merges it + * into a single {@link TokenStream} with a single {@link Token}. + * + * @author mattmann + * + */ +public class TokenStreamMerger { + + private TokenStream ts; + + public TokenStreamMerger(TokenStream ts) { + this.ts = ts; + } + + public TokenStream createMergedTokenStream() { + StringBuffer buf = new StringBuffer(); + try { + while (ts.incrementToken()) { + TermAttribute ta = (TermAttribute) ts + .getAttribute(TermAttribute.class); + buf.append(ta.term()); + } + } catch (IOException e) { + e.printStackTrace(); + } + + return new KeywordTokenizer(new StringReader(buf.toString())); + } +}