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.find.aliases1;
18:
19: import org.compass.core.CompassHits;
20: import org.compass.core.CompassSession;
21: import org.compass.core.CompassTransaction;
22: import org.compass.core.test.AbstractTestCase;
23:
24: /**
25: * @author kimchy
26: */
27: public class AliasesFindTests extends AbstractTestCase {
28:
29: protected String[] getMappings() {
30: return new String[] { "find/aliases1/mapping.cpm.xml" };
31: }
32:
33: public void testSubIndexAliasNarrow() {
34: addDataA(0, 10);
35: addDataB(0, 10);
36:
37: CompassSession session = openSession();
38: CompassTransaction tr = session.beginTransaction();
39: CompassHits hits = session.find("alias:a1 OR alias:b1");
40: assertEquals(20, hits.getLength());
41:
42: hits = session.queryBuilder().queryString(
43: "alias:a1 OR alias:b1").toQuery().setAliases(
44: new String[] { "a1" }).hits();
45: assertEquals(10, hits.getLength());
46:
47: hits = session.queryBuilder().queryString(
48: "alias:a1 OR alias:b1").toQuery().setSubIndexes(
49: new String[] { "ab" }).hits();
50: assertEquals(20, hits.getLength());
51:
52: hits = session.queryBuilder().queryString(
53: "alias:a1 OR alias:b1").toQuery().setSubIndexes(
54: new String[] { "ab" })
55: .setAliases(new String[] { "a1" }).hits();
56: assertEquals(10, hits.getLength());
57:
58: tr.commit();
59: session.close();
60: }
61:
62: private void addDataA(int from, int to) {
63: CompassSession session = openSession();
64: CompassTransaction tr = session.beginTransaction();
65: for (int i = from; i < to; i++) {
66: A a = new A();
67: a.setId(new Long(i));
68: a.setValue("value");
69: session.save(a);
70: }
71: tr.commit();
72: session.close();
73: }
74:
75: private void addDataB(int from, int to) {
76: CompassSession session = openSession();
77: CompassTransaction tr = session.beginTransaction();
78: for (int i = from; i < to; i++) {
79: B b = new B();
80: b.setId(new Long(i));
81: b.setValue("value");
82: session.save(b);
83: }
84: tr.commit();
85: session.close();
86: }
87:
88: }
|