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.querybuilder.analyzerquery;
18:
19: import org.compass.core.CompassHits;
20: import org.compass.core.CompassSession;
21: import org.compass.core.CompassTransaction;
22: import org.compass.core.config.CompassSettings;
23: import org.compass.core.lucene.LuceneEnvironment;
24: import org.compass.core.test.AbstractTestCase;
25:
26: /**
27: * @author kimchy
28: */
29: public class AnalyzerSpecificQueryStringTests extends AbstractTestCase {
30:
31: protected String[] getMappings() {
32: return new String[] { "querybuilder/analyzerquery/mapping.cpm.xml" };
33: }
34:
35: protected void addSettings(CompassSettings settings) {
36: settings
37: .setGroupSettings(
38: LuceneEnvironment.Analyzer.PREFIX,
39: "ws",
40: new String[] { LuceneEnvironment.Analyzer.TYPE },
41: new String[] { LuceneEnvironment.Analyzer.CoreTypes.WHITESPACE });
42: }
43:
44: public void testAnalyzerSpecificQueryString() {
45: CompassSession session = openSession();
46: CompassTransaction tr = session.beginTransaction();
47:
48: A a = new A();
49: a.id = 1;
50: a.value = "that test";
51: a.value1 = "the more";
52: session.save("a", a);
53:
54: // first find based on prefix
55:
56: // this one will find a hit since we use just whitespace analyzer
57: CompassHits hits = session.find("value:that");
58: assertEquals(1, hits.length());
59: // this one will find none since it uses the standard analyzer
60: hits = session.find("value1:the");
61: assertEquals(0, hits.length());
62:
63: // we just test with the all property
64: // since we can't know which analyzer to use, we simply default to the search
65: // one
66: hits = session.find("that");
67: assertEquals(0, hits.length());
68: hits = session.find("the");
69: assertEquals(0, hits.length());
70:
71: tr.commit();
72: session.close();
73: }
74: }
|