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.morelikethis;
18:
19: import org.compass.core.CompassDetachedHits;
20: import org.compass.core.CompassHits;
21: import org.compass.core.CompassQuery;
22: import org.compass.core.CompassSession;
23: import org.compass.core.CompassTransaction;
24: import org.compass.core.test.AbstractTestCase;
25:
26: /**
27: * @author kimchy
28: */
29: public class MoreLikeThisQueryBuilderTests extends AbstractTestCase {
30:
31: protected String[] getMappings() {
32: return new String[] { "querybuilder/morelikethis/mapping.cpm.xml" };
33: }
34:
35: public void testSimpleMoreLikeThis() {
36: CompassSession session = openSession();
37: CompassTransaction tr = session.beginTransaction();
38:
39: A a = new A();
40: a.id = 1;
41: a.value = "test with some specific keyword keyword";
42: session.save("a", a);
43:
44: a = new A();
45: a.id = 2;
46: a.value = "another one with keyword keyword";
47: session.save("a", a);
48:
49: a = new A();
50: a.id = 3;
51: a.value = "nothing related";
52: session.save("a", a);
53:
54: // verify explicit value
55: CompassQuery query = session.queryBuilder().moreLikeThis("a",
56: "1").setMinResourceFreq(1).setMinTermFreq(1)
57: .addProperty("value").toQuery();
58: CompassHits hits = query.hits();
59: assertEquals(1, hits.length());
60:
61: // verify on all (note we store term vector on it)
62: query = session.queryBuilder().moreLikeThis("a", "1")
63: .setMinResourceFreq(1).setMinTermFreq(2).toQuery();
64: // (we will find two on this ones since the alias is added).
65: CompassDetachedHits detachedHits = query.hits().detach();
66: assertEquals(1, detachedHits.length());
67:
68: // just test adding several properties
69: session.queryBuilder().moreLikeThis("a", "1").addProperty(
70: "value").addProperty("alias");
71:
72: tr.commit();
73: session.close();
74: }
75: }
|