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.simple;
18:
19: import org.compass.core.Compass;
20: import org.compass.core.CompassSession;
21: import org.compass.core.CompassTransaction;
22: import org.compass.core.config.CompassSettings;
23: import org.compass.core.engine.spellcheck.SearchEngineSpellCheckManager;
24: import org.compass.core.lucene.LuceneEnvironment;
25: import org.compass.core.test.AbstractTestCase;
26:
27: /**
28: * @author kimchy
29: */
30: public class ScheduledSpellCheckTests extends AbstractTestCase {
31:
32: protected String[] getMappings() {
33: return new String[] { "spellcheck/simple/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, true);
41: settings.setIntSetting(
42: LuceneEnvironment.SpellCheck.SCHEDULE_INITIAL_DELAY, 0);
43: }
44:
45: /**
46: * If we enable scheduling, a rebuild will be scheduled on startup
47: */
48: public void testScheduledSpellCheckBuild() throws Exception {
49: setUpData();
50: getCompass().close();
51:
52: Compass compass = buildCompass();
53: Thread.sleep(500);
54:
55: SearchEngineSpellCheckManager spellCheckManager = compass
56: .getSpellCheckManager();
57:
58: String[] suggestions = spellCheckManager.suggestBuilder("fiv")
59: .suggest().getSuggestions();
60: assertEquals(1, suggestions.length);
61: assertEquals("five", suggestions[0]);
62: assertTrue(spellCheckManager.suggestBuilder("five").suggest()
63: .isExists());
64:
65: compass.close();
66: }
67:
68: protected void setUpData() {
69: CompassSession session = openSession();
70: CompassTransaction tr = session.beginTransaction();
71:
72: A a = new A();
73: a.id = 1;
74: a.value1 = "five";
75: a.value2 = "sixteen";
76: session.save("a1", a);
77:
78: a.value1 = "black";
79: a.value2 = "white";
80: session.save("a2", a);
81:
82: tr.commit();
83: session.close();
84: }
85: }
|