01: /*
02: * Copyright 2004-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.compass.core.test.spellcheck.mapping;
18:
19: import org.compass.core.CompassSession;
20: import org.compass.core.CompassTransaction;
21: import org.compass.core.config.CompassSettings;
22: import org.compass.core.lucene.LuceneEnvironment;
23: import org.compass.core.mapping.SpellCheckType;
24: import org.compass.core.test.AbstractTestCase;
25:
26: /**
27: * @author kimchy
28: */
29: public class DefaultIncludeMappingSpellCheckTests extends
30: AbstractTestCase {
31:
32: protected String[] getMappings() {
33: return new String[] { "spellcheck/mapping/mapping.cpm.xml" };
34: }
35:
36: protected void addSettings(CompassSettings settings) {
37: settings.setBooleanSetting(LuceneEnvironment.SpellCheck.ENABLE,
38: true);
39: settings.setBooleanSetting(
40: LuceneEnvironment.SpellCheck.SCHEDULE, false);
41: settings.setSetting(LuceneEnvironment.SpellCheck.DEFAULT_MODE,
42: SpellCheckType.INCLUDE.toString());
43: }
44:
45: public void testSimplePropertiesSpellCheck() {
46: CompassSession session = openSession();
47: CompassTransaction tr = session.beginTransaction();
48:
49: A a = new A();
50: a.id = 1;
51: a.value1 = "orange";
52: a.value2 = "white";
53: a.value3 = "black";
54: session.save("a2", a);
55:
56: tr.commit();
57: session.close();
58:
59: getCompass().getSpellCheckManager().concurrentRebuild();
60:
61: String[] suggestions = getCompass().getSpellCheckManager()
62: .suggestBuilder("orang").suggest().getSuggestions();
63: assertEquals(1, suggestions.length);
64: assertEquals("orange", suggestions[0]);
65:
66: suggestions = getCompass().getSpellCheckManager()
67: .suggestBuilder("blac").suggest().getSuggestions();
68: assertEquals(1, suggestions.length);
69: assertEquals("black", suggestions[0]);
70:
71: suggestions = getCompass().getSpellCheckManager()
72: .suggestBuilder("whit").suggest().getSuggestions();
73: assertEquals(0, suggestions.length);
74: }
75: }
|