SOLR-3688: fix spellcheck test relying on map order

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1367125 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2012-07-30 15:40:11 +00:00
parent f600aa6094
commit eb80f5e897
2 changed files with 13 additions and 4 deletions

View File

@ -8,8 +8,10 @@ import org.apache.solr.spelling.SpellingOptions;
import org.apache.solr.spelling.SpellingResult;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@ -49,12 +51,20 @@ public class DummyCustomParamSpellChecker extends SolrSpellChecker {
SpellingResult result = new SpellingResult();
//just spit back out the results
// sort the keys to make ordering predictable
Iterator<String> iterator = options.customParams.getParameterNamesIterator();
List<String> lst = new ArrayList<String>();
while (iterator.hasNext()) {
lst.add(iterator.next());
}
Collections.sort(lst);
int i = 0;
while (iterator.hasNext()){
String name = iterator.next();
for (String name : lst) {
String value = options.customParams.get(name);
result.add(new Token(name, i++, i++), Collections.singletonList(value));
result.add(new Token(name, i, i+1), Collections.singletonList(value));
i += 2;
}
return result;
}

View File

@ -100,7 +100,6 @@ public class SpellCheckComponentTest extends SolrTestCaseJ4 {
@Test
public void testPerDictionary() throws Exception {
assumeFalse("This test fails in most cases with Java 8+, looks like it depends on order of some HashSet/HashMap whatever", Constants.JRE_IS_MINIMUM_JAVA8);
assertJQ(req("json.nl","map", "qt",rh, SpellCheckComponent.COMPONENT_NAME, "true", SpellingParams.SPELLCHECK_BUILD, "true", "q","documemt"
, SpellingParams.SPELLCHECK_DICT, "perDict", SpellingParams.SPELLCHECK_PREFIX + ".perDict.foo", "bar", SpellingParams.SPELLCHECK_PREFIX + ".perDict.bar", "foo")
,"/spellcheck/suggestions/bar=={'numFound':1, 'startOffset':0, 'endOffset':1, 'suggestion':['foo']}"