001: /*
002: * Copyright 2004-2006 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.compass.annotations.test.spellcheck;
018:
019: import org.compass.annotations.test.AbstractAnnotationsTestCase;
020: import org.compass.core.CompassSession;
021: import org.compass.core.CompassTransaction;
022: import org.compass.core.config.CompassConfiguration;
023: import org.compass.core.config.CompassSettings;
024: import org.compass.core.engine.spellcheck.SearchEngineSpellCheckManager;
025: import org.compass.core.lucene.LuceneEnvironment;
026:
027: /**
028: * @author kimchy
029: */
030: public class SpellCheckAnnotationTests extends
031: AbstractAnnotationsTestCase {
032:
033: protected void addExtraConf(CompassConfiguration conf) {
034: conf.addClass(A.class).addClass(B.class);
035: }
036:
037: protected void addSettings(CompassSettings settings) {
038: settings.setBooleanSetting(LuceneEnvironment.SpellCheck.ENABLE,
039: true);
040: settings.setBooleanSetting(
041: LuceneEnvironment.SpellCheck.SCHEDULE, false);
042: }
043:
044: public void testSearchInclude() {
045: setUpData();
046:
047: SearchEngineSpellCheckManager spellCheckManager = getCompass()
048: .getSpellCheckManager();
049: assertTrue(spellCheckManager.rebuild());
050:
051: String[] suggestions = spellCheckManager.suggestBuilder("whit")
052: .suggest().getSuggestions();
053: assertEquals(1, suggestions.length);
054: assertEquals("white", suggestions[0]);
055:
056: suggestions = spellCheckManager.suggestBuilder("whit").aliases(
057: "A").suggest().getSuggestions();
058: assertEquals(1, suggestions.length);
059: assertEquals("white", suggestions[0]);
060:
061: suggestions = spellCheckManager.suggestBuilder("blac").aliases(
062: "A").suggest().getSuggestions();
063: assertEquals(0, suggestions.length);
064: }
065:
066: public void testSearchExlcude() {
067: setUpData();
068:
069: SearchEngineSpellCheckManager spellCheckManager = getCompass()
070: .getSpellCheckManager();
071: assertTrue(spellCheckManager.rebuild());
072:
073: String[] suggestions = spellCheckManager.suggestBuilder("fiv")
074: .suggest().getSuggestions();
075: assertEquals(1, suggestions.length);
076: assertEquals("five", suggestions[0]);
077:
078: suggestions = spellCheckManager.suggestBuilder("fiv").aliases(
079: "B").suggest().getSuggestions();
080: assertEquals(1, suggestions.length);
081: assertEquals("five", suggestions[0]);
082:
083: suggestions = spellCheckManager.suggestBuilder("sixtee")
084: .aliases("B").suggest().getSuggestions();
085: assertEquals(0, suggestions.length);
086: }
087:
088: private void setUpData() {
089: CompassSession session = openSession();
090: CompassTransaction tr = session.beginTransaction();
091:
092: A a = new A();
093: a.id = 1;
094: a.avalue1 = "white";
095: a.avalue2 = "black";
096: session.save(a);
097:
098: B b = new B();
099: b.id = 1;
100: b.bvalue1 = "five";
101: b.bvalue2 = "sixteen";
102: session.save(b);
103:
104: tr.commit();
105: session.close();
106: }
107: }
|