001: package org.apache.lucene.queryParser.surround.query;
002:
003: /**
004: * Licensed to the Apache Software Foundation (ASF) under one or more
005: * contributor license agreements. See the NOTICE file distributed with
006: * this work for additional information regarding copyright ownership.
007: * The ASF licenses this file to You under the Apache License, Version 2.0
008: * (the "License"); you may not use this file except in compliance with
009: * the License. You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: */
019:
020: import junit.framework.TestCase;
021: import junit.framework.TestSuite;
022: import junit.textui.TestRunner;
023:
024: public class Test03Distance extends TestCase {
025: public static void main(String args[]) {
026: TestRunner.run(new TestSuite(Test03Distance.class));
027: }
028:
029: boolean verbose = false;
030: int maxBasicQueries = 16;
031:
032: String[] exceptionQueries = { "(aa and bb) w cc",
033: "(aa or bb) w (cc and dd)", "(aa opt bb) w cc",
034: "(aa not bb) w cc", "(aa or bb) w (bi:cc)",
035: "(aa or bb) w bi:cc", "(aa or bi:bb) w cc",
036: "(aa or (bi:bb)) w cc", "(aa or (bb and dd)) w cc" };
037:
038: public void test00Exceptions() throws Exception {
039: String m = ExceptionQueryTst.getFailQueries(exceptionQueries,
040: verbose);
041: if (m.length() > 0) {
042: fail("No ParseException for:\n" + m);
043: }
044: }
045:
046: final String fieldName = "bi";
047:
048: String[] docs1 = { "word1 word2 word3", "word4 word5",
049: "ord1 ord2 ord3", "orda1 orda2 orda3 word2 worda3",
050: "a c e a b c" };
051:
052: SingleFieldTestDb db1 = new SingleFieldTestDb(docs1, fieldName);
053:
054: String[] docs2 = { "w1 w2 w3 w4 w5", "w1 w3 w2 w3", "" };
055:
056: SingleFieldTestDb db2 = new SingleFieldTestDb(docs2, fieldName);
057:
058: public void distanceTest1(String query, int[] expdnrs)
059: throws Exception {
060: BooleanQueryTst bqt = new BooleanQueryTst(query, expdnrs, db1,
061: fieldName, this , new BasicQueryFactory(maxBasicQueries));
062: bqt.setVerbose(verbose);
063: bqt.doTest();
064: }
065:
066: public void distanceTest2(String query, int[] expdnrs)
067: throws Exception {
068: BooleanQueryTst bqt = new BooleanQueryTst(query, expdnrs, db2,
069: fieldName, this , new BasicQueryFactory(maxBasicQueries));
070: bqt.setVerbose(verbose);
071: bqt.doTest();
072: }
073:
074: public void test0W01() throws Exception {
075: int[] expdnrs = { 0 };
076: distanceTest1("word1 w word2", expdnrs);
077: }
078:
079: public void test0N01() throws Exception {
080: int[] expdnrs = { 0 };
081: distanceTest1("word1 n word2", expdnrs);
082: }
083:
084: public void test0N01r() throws Exception { /* r reverse */
085: int[] expdnrs = { 0 };
086: distanceTest1("word2 n word1", expdnrs);
087: }
088:
089: public void test0W02() throws Exception {
090: int[] expdnrs = {};
091: distanceTest1("word2 w word1", expdnrs);
092: }
093:
094: public void test0W03() throws Exception {
095: int[] expdnrs = {};
096: distanceTest1("word2 2W word1", expdnrs);
097: }
098:
099: public void test0N03() throws Exception {
100: int[] expdnrs = { 0 };
101: distanceTest1("word2 2N word1", expdnrs);
102: }
103:
104: public void test0N03r() throws Exception {
105: int[] expdnrs = { 0 };
106: distanceTest1("word1 2N word2", expdnrs);
107: }
108:
109: public void test0W04() throws Exception {
110: int[] expdnrs = {};
111: distanceTest1("word2 3w word1", expdnrs);
112: }
113:
114: public void test0N04() throws Exception {
115: int[] expdnrs = { 0 };
116: distanceTest1("word2 3n word1", expdnrs);
117: }
118:
119: public void test0N04r() throws Exception {
120: int[] expdnrs = { 0 };
121: distanceTest1("word1 3n word2", expdnrs);
122: }
123:
124: public void test0W05() throws Exception {
125: int[] expdnrs = {};
126: distanceTest1("orda1 w orda3", expdnrs);
127: }
128:
129: public void test0W06() throws Exception {
130: int[] expdnrs = { 3 };
131: distanceTest1("orda1 2w orda3", expdnrs);
132: }
133:
134: public void test1Wtrunc01() throws Exception {
135: int[] expdnrs = { 0 };
136: distanceTest1("word1* w word2", expdnrs);
137: }
138:
139: public void test1Wtrunc02() throws Exception {
140: int[] expdnrs = { 0 };
141: distanceTest1("word* w word2", expdnrs);
142: }
143:
144: public void test1Wtrunc02r() throws Exception {
145: int[] expdnrs = { 0, 3 };
146: distanceTest1("word2 w word*", expdnrs);
147: }
148:
149: public void test1Ntrunc02() throws Exception {
150: int[] expdnrs = { 0, 3 };
151: distanceTest1("word* n word2", expdnrs);
152: }
153:
154: public void test1Ntrunc02r() throws Exception {
155: int[] expdnrs = { 0, 3 };
156: distanceTest1("word2 n word*", expdnrs);
157: }
158:
159: public void test1Wtrunc03() throws Exception {
160: int[] expdnrs = { 0 };
161: distanceTest1("word1* w word2*", expdnrs);
162: }
163:
164: public void test1Ntrunc03() throws Exception {
165: int[] expdnrs = { 0 };
166: distanceTest1("word1* N word2*", expdnrs);
167: }
168:
169: public void test1Wtrunc04() throws Exception {
170: int[] expdnrs = {};
171: distanceTest1("kxork* w kxor*", expdnrs);
172: }
173:
174: public void test1Ntrunc04() throws Exception {
175: int[] expdnrs = {};
176: distanceTest1("kxork* 99n kxor*", expdnrs);
177: }
178:
179: public void test1Wtrunc05() throws Exception {
180: int[] expdnrs = {};
181: distanceTest1("word2* 2W word1*", expdnrs);
182: }
183:
184: public void test1Ntrunc05() throws Exception {
185: int[] expdnrs = { 0 };
186: distanceTest1("word2* 2N word1*", expdnrs);
187: }
188:
189: public void test1Wtrunc06() throws Exception {
190: int[] expdnrs = { 3 };
191: distanceTest1("ord* W word*", expdnrs);
192: }
193:
194: public void test1Ntrunc06() throws Exception {
195: int[] expdnrs = { 3 };
196: distanceTest1("ord* N word*", expdnrs);
197: }
198:
199: public void test1Ntrunc06r() throws Exception {
200: int[] expdnrs = { 3 };
201: distanceTest1("word* N ord*", expdnrs);
202: }
203:
204: public void test1Wtrunc07() throws Exception {
205: int[] expdnrs = { 3 };
206: distanceTest1("(orda2 OR orda3) W word*", expdnrs);
207: }
208:
209: public void test1Wtrunc08() throws Exception {
210: int[] expdnrs = { 3 };
211: distanceTest1("(orda2 OR orda3) W (word2 OR worda3)", expdnrs);
212: }
213:
214: public void test1Wtrunc09() throws Exception {
215: int[] expdnrs = { 3 };
216: distanceTest1("(orda2 OR orda3) 2W (word2 OR worda3)", expdnrs);
217: }
218:
219: public void test1Ntrunc09() throws Exception {
220: int[] expdnrs = { 3 };
221: distanceTest1("(orda2 OR orda3) 2N (word2 OR worda3)", expdnrs);
222: }
223:
224: public void test2Wprefix01() throws Exception {
225: int[] expdnrs = { 0 };
226: distanceTest2("W (w1, w2, w3)", expdnrs);
227: }
228:
229: public void test2Nprefix01a() throws Exception {
230: int[] expdnrs = { 0, 1 };
231: distanceTest2("N(w1, w2, w3)", expdnrs);
232: }
233:
234: public void test2Nprefix01b() throws Exception {
235: int[] expdnrs = { 0, 1 };
236: distanceTest2("N(w3, w1, w2)", expdnrs);
237: }
238:
239: public void test2Wprefix02() throws Exception {
240: int[] expdnrs = { 0, 1 };
241: distanceTest2("2W(w1,w2,w3)", expdnrs);
242: }
243:
244: public void test2Nprefix02a() throws Exception {
245: int[] expdnrs = { 0, 1 };
246: distanceTest2("2N(w1,w2,w3)", expdnrs);
247: }
248:
249: public void test2Nprefix02b() throws Exception {
250: int[] expdnrs = { 0, 1 };
251: distanceTest2("2N(w2,w3,w1)", expdnrs);
252: }
253:
254: public void test2Wnested01() throws Exception {
255: int[] expdnrs = { 0 };
256: distanceTest2("w1 W w2 W w3", expdnrs);
257: }
258:
259: public void test2Nnested01() throws Exception {
260: int[] expdnrs = { 0 };
261: distanceTest2("w1 N w2 N w3", expdnrs);
262: }
263:
264: public void test2Wnested02() throws Exception {
265: int[] expdnrs = { 0, 1 };
266: distanceTest2("w1 2W w2 2W w3", expdnrs);
267: }
268:
269: public void test2Nnested02() throws Exception {
270: int[] expdnrs = { 0, 1 };
271: distanceTest2("w1 2N w2 2N w3", expdnrs);
272: }
273: }
|