diff --git a/CHANGES.txt b/CHANGES.txt index 1b5e66eec37..179b81c3357 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -61,6 +61,8 @@ Bug Fixes (Rob Staveley, yonik) 6. Worked around a Jetty bug that caused invalid XML responses for fields containing non ASCII chars. (Bertrand Delacretaz via yonik, SOLR-32) + 7. WordDelimiterFilter can throw exceptions if configured with both + generate and catenate off. (Mike Klaas via yonik, SOLR-34) Other Changes 1. Upgrade to Lucene 2.0 nightly build 2006-06-22, lucene SVN revision 416224, diff --git a/src/java/org/apache/solr/analysis/WordDelimiterFilter.java b/src/java/org/apache/solr/analysis/WordDelimiterFilter.java index 47e0788a063..fc713a26c69 100644 --- a/src/java/org/apache/solr/analysis/WordDelimiterFilter.java +++ b/src/java/org/apache/solr/analysis/WordDelimiterFilter.java @@ -329,16 +329,16 @@ final class WordDelimiterFilter extends TokenFilter { if (numWords==0) { // all numbers addCombos(tlist,0,numtok,generateNumberParts!=0,catenateNumbers!=0 || catenateAll!=0, 1); - break; + if (queue.size() > 0) break; else continue; } else if (numNumbers==0) { // all words addCombos(tlist,0,numtok,generateWordParts!=0,catenateWords!=0 || catenateAll!=0, 1); - break; + if (queue.size() > 0) break; else continue; } else if (generateNumberParts==0 && generateWordParts==0 && catenateNumbers==0 && catenateWords==0) { // catenate all *only* // OPT:could be optimized to add to current queue... addCombos(tlist,0,numtok,false,catenateAll!=0, 1); - break; + if (queue.size() > 0) break; else continue; } // @@ -369,7 +369,10 @@ final class WordDelimiterFilter extends TokenFilter { addCombos(tlist,0,numtok,false,true,0); } - break; + // NOTE: in certain cases, queue may be empty (for instance, if catenate + // and generate are both set to false). In this case, we should proceed + // to next token rather than throwing ArrayOutOfBounds + if (queue.size() > 0) break; else continue; } // System.out.println("##########AFTER COMBINATIONS:"+ str(queue)); diff --git a/src/test/org/apache/solr/analysis/TestSynonymFilter.java b/src/test/org/apache/solr/analysis/TestSynonymFilter.java index 4bd445eeb48..de4752c70eb 100644 --- a/src/test/org/apache/solr/analysis/TestSynonymFilter.java +++ b/src/test/org/apache/solr/analysis/TestSynonymFilter.java @@ -1,284 +1,284 @@ -/** - * Copyright 2006 The Apache Software Foundation - * - * Licensed 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; - -import junit.framework.TestCase; -import org.apache.lucene.analysis.Token; -import org.apache.lucene.analysis.TokenStream; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -/** - * @author yonik - * @version $Id$ - */ -public class TestSynonymFilter extends TestCase { - - public List strings(String str) { - String[] arr = str.split(" "); - return Arrays.asList(arr); - } - - /*** - * Return a list of tokens according to a test string format: - * a b c => returns List [a,b,c] - * a/b => tokens a and b share the same spot (b.positionIncrement=0) - * a,3/b/c => a,b,c all share same position (a.positionIncrement=3, b.positionIncrement=0, c.positionIncrement=0) - */ - public List tokens(String str) { - String[] arr = str.split(" "); - List result = new ArrayList(); - for (int i=0; i 1) t.setPositionIncrement(Integer.parseInt(params[1])); - result.add(t); - for (int j=1; j returns List [a,b,c] + * a/b => tokens a and b share the same spot (b.positionIncrement=0) + * a,3/b/c => a,b,c all share same position (a.positionIncrement=3, b.positionIncrement=0, c.positionIncrement=0) + */ + public List tokens(String str) { + String[] arr = str.split(" "); + List result = new ArrayList(); + for (int i=0; i 1) t.setPositionIncrement(Integer.parseInt(params[1])); + result.add(t); + for (int j=1; j + + + + + + + + + @@ -311,6 +320,8 @@ + +