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.analyzerfilter;
18:
19: import org.compass.core.CompassException;
20: import org.compass.core.CompassHits;
21: import org.compass.core.CompassSession;
22: import org.compass.core.CompassTransaction;
23: import org.compass.core.config.CompassSettings;
24: import org.compass.core.lucene.LuceneEnvironment;
25: import org.compass.core.lucene.engine.analyzer.synonym.SynonymLookupProvider;
26: import org.compass.core.test.AbstractTestCase;
27:
28: /**
29: * @author kimchy
30: */
31: public class AnalyzerFilterTests extends AbstractTestCase {
32:
33: private static final String TEXT = "the quick brown fox jumped over the lazy dogs";
34:
35: public static class TestLookupSynonymProvider implements
36: SynonymLookupProvider {
37:
38: public void configure(CompassSettings settings)
39: throws CompassException {
40: }
41:
42: public String[] lookupSynonyms(String value) {
43: if (value.equals("quick")) {
44: return new String[] { "fast" };
45: }
46: return null;
47: }
48: }
49:
50: protected String[] getMappings() {
51: return new String[] { "analyzerfilter/osem.cpm.xml" };
52: }
53:
54: protected void addSettings(CompassSettings settings) {
55: settings
56: .setGroupSettings(
57: LuceneEnvironment.AnalyzerFilter.PREFIX,
58: "synm",
59: new String[] {
60: LuceneEnvironment.AnalyzerFilter.TYPE,
61: LuceneEnvironment.AnalyzerFilter.Synonym.LOOKUP },
62: new String[] {
63: LuceneEnvironment.AnalyzerFilter.SYNONYM_TYPE,
64: TestLookupSynonymProvider.class
65: .getName() });
66:
67: settings.setGroupSettings(LuceneEnvironment.Analyzer.PREFIX,
68: LuceneEnvironment.Analyzer.DEFAULT_GROUP,
69: new String[] { LuceneEnvironment.Analyzer.FILTERS },
70: new String[] { "synm" });
71: }
72:
73: public void testSimpleLookupSynonym() throws Exception {
74: CompassSession session = openSession();
75: CompassTransaction tr = session.beginTransaction();
76:
77: Long id = new Long(1);
78: A a = new A();
79: a.setId(id);
80: a.setValue(TEXT);
81: session.save(a);
82:
83: CompassHits hits = session.find("value:quick");
84: assertEquals(1, hits.getLength());
85: // test for the all property as well
86: hits = session.find("quick");
87: assertEquals(1, hits.getLength());
88:
89: hits = session.find("value:fast");
90: assertEquals(1, hits.getLength());
91: // test for the all property as well
92: hits = session.find("fast");
93: assertEquals(1, hits.getLength());
94:
95: tr.commit();
96: session.close();
97: }
98: }
|