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.core.test.all.boost;
018:
019: import org.compass.core.CompassHits;
020: import org.compass.core.CompassSession;
021: import org.compass.core.CompassTransaction;
022: import org.compass.core.test.AbstractTestCase;
023:
024: /**
025: * This test verifies support for specific boost fields taken into account when used
026: * within the all query.
027: *
028: * @author kimchy
029: */
030: public class AllBoostTests extends AbstractTestCase {
031:
032: protected String[] getMappings() {
033: return new String[] { "all/boost/mapping.cpm.xml" };
034: }
035:
036: public void testValue1BoostLevel2() {
037: CompassSession session = openSession();
038: CompassTransaction tr = session.beginTransaction();
039:
040: A a = new A();
041: a.id = 1;
042: a.value1 = "test2";
043: a.value2 = "test1";
044: session.save("anoboost", a);
045: session.save("a1", a);
046:
047: a = new A();
048: a.id = 2;
049: a.value1 = "test1";
050: a.value2 = "test2";
051: session.save("anoboost", a);
052: session.save("a1", a);
053:
054: CompassHits hits = session.queryBuilder().queryString("test1")
055: .toQuery().setAliases("anoboost").hits();
056: assertEquals(1, ((A) hits.data(0)).id);
057: assertEquals(2, ((A) hits.data(1)).id);
058: hits = session.queryBuilder().queryString("test1").toQuery()
059: .setAliases("a1").hits();
060: assertEquals(2, ((A) hits.data(0)).id);
061: assertEquals(1, ((A) hits.data(1)).id);
062:
063: tr.commit();
064: session.close();
065: }
066:
067: public void testValue1BoostLevel2WithSeveralTokens() {
068: CompassSession session = openSession();
069: CompassTransaction tr = session.beginTransaction();
070:
071: A a = new A();
072: a.id = 1;
073: a.value1 = "moo test2";
074: a.value2 = "moo test1";
075: session.save("anoboost", a);
076: session.save("a1", a);
077:
078: a = new A();
079: a.id = 2;
080: a.value1 = "moo test1";
081: a.value2 = "moo test2";
082: session.save("anoboost", a);
083: session.save("a1", a);
084:
085: CompassHits hits = session.queryBuilder().queryString("test1")
086: .toQuery().setAliases("anoboost").hits();
087: assertEquals(1, ((A) hits.data(0)).id);
088: assertEquals(2, ((A) hits.data(1)).id);
089: hits = session.queryBuilder().queryString("test1").toQuery()
090: .setAliases("a1").hits();
091: assertEquals(2, ((A) hits.data(0)).id);
092: assertEquals(1, ((A) hits.data(1)).id);
093:
094: tr.commit();
095: session.close();
096: }
097:
098: public void testBoostMapping() {
099: CompassSession session = openSession();
100: CompassTransaction tr = session.beginTransaction();
101:
102: B b = new B();
103: b.id = 1;
104: b.boost = 1;
105: b.value1 = "test2";
106: b.value2 = "test1";
107: session.save("bnoboost", b);
108: session.save("b1", b);
109:
110: b = new B();
111: b.id = 2;
112: b.boost = 2;
113: b.value1 = "test1";
114: b.value2 = "test2";
115: session.save("bnoboost", b);
116: session.save("b1", b);
117:
118: CompassHits hits = session.queryBuilder().queryString("test1")
119: .toQuery().setAliases("bnoboost").hits();
120: assertEquals(1, ((B) hits.data(0)).id);
121: assertEquals(2, ((B) hits.data(1)).id);
122: hits = session.queryBuilder().queryString("test1").toQuery()
123: .setAliases("b1").hits();
124: assertEquals(2, ((B) hits.data(0)).id);
125: assertEquals(1, ((B) hits.data(1)).id);
126:
127: tr.commit();
128: session.close();
129: }
130: }
|