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 Test02Boolean extends TestCase {
025: public static void main(String args[]) {
026: TestRunner.run(new TestSuite(Test02Boolean.class));
027: }
028:
029: final String fieldName = "bi";
030: boolean verbose = false;
031: int maxBasicQueries = 16;
032:
033: String[] docs1 = { "word1 word2 word3", "word4 word5",
034: "ord1 ord2 ord3", "orda1 orda2 orda3 word2 worda3",
035: "a c e a b c" };
036:
037: SingleFieldTestDb db1 = new SingleFieldTestDb(docs1, fieldName);
038:
039: public void normalTest1(String query, int[] expdnrs)
040: throws Exception {
041: BooleanQueryTst bqt = new BooleanQueryTst(query, expdnrs, db1,
042: fieldName, this , new BasicQueryFactory(maxBasicQueries));
043: bqt.setVerbose(verbose);
044: bqt.doTest();
045: }
046:
047: public void test02Terms01() throws Exception {
048: int[] expdnrs = { 0 };
049: normalTest1("word1", expdnrs);
050: }
051:
052: public void test02Terms02() throws Exception {
053: int[] expdnrs = { 0, 1, 3 };
054: normalTest1("word*", expdnrs);
055: }
056:
057: public void test02Terms03() throws Exception {
058: int[] expdnrs = { 2 };
059: normalTest1("ord2", expdnrs);
060: }
061:
062: public void test02Terms04() throws Exception {
063: int[] expdnrs = {};
064: normalTest1("kxork*", expdnrs);
065: }
066:
067: public void test02Terms05() throws Exception {
068: int[] expdnrs = { 0, 1, 3 };
069: normalTest1("wor*", expdnrs);
070: }
071:
072: public void test02Terms06() throws Exception {
073: int[] expdnrs = {};
074: normalTest1("ab", expdnrs);
075: }
076:
077: public void test02Terms10() throws Exception {
078: int[] expdnrs = {};
079: normalTest1("abc?", expdnrs);
080: }
081:
082: public void test02Terms13() throws Exception {
083: int[] expdnrs = { 0, 1, 3 };
084: normalTest1("word?", expdnrs);
085: }
086:
087: public void test02Terms14() throws Exception {
088: int[] expdnrs = { 0, 1, 3 };
089: normalTest1("w?rd?", expdnrs);
090: }
091:
092: public void test02Terms20() throws Exception {
093: int[] expdnrs = { 0, 1, 3 };
094: normalTest1("w*rd?", expdnrs);
095: }
096:
097: public void test02Terms21() throws Exception {
098: int[] expdnrs = { 3 };
099: normalTest1("w*rd??", expdnrs);
100: }
101:
102: public void test02Terms22() throws Exception {
103: int[] expdnrs = { 3 };
104: normalTest1("w*?da?", expdnrs);
105: }
106:
107: public void test02Terms23() throws Exception {
108: int[] expdnrs = {};
109: normalTest1("w?da?", expdnrs);
110: }
111:
112: public void test03And01() throws Exception {
113: int[] expdnrs = { 0 };
114: normalTest1("word1 AND word2", expdnrs);
115: }
116:
117: public void test03And02() throws Exception {
118: int[] expdnrs = { 3 };
119: normalTest1("word* and ord*", expdnrs);
120: }
121:
122: public void test03And03() throws Exception {
123: int[] expdnrs = { 0 };
124: normalTest1("and(word1,word2)", expdnrs);
125: }
126:
127: public void test04Or01() throws Exception {
128: int[] expdnrs = { 0, 3 };
129: normalTest1("word1 or word2", expdnrs);
130: }
131:
132: public void test04Or02() throws Exception {
133: int[] expdnrs = { 0, 1, 2, 3 };
134: normalTest1("word* OR ord*", expdnrs);
135: }
136:
137: public void test04Or03() throws Exception {
138: int[] expdnrs = { 0, 3 };
139: normalTest1("OR (word1, word2)", expdnrs);
140: }
141:
142: public void test05Not01() throws Exception {
143: int[] expdnrs = { 3 };
144: normalTest1("word2 NOT word1", expdnrs);
145: }
146:
147: public void test05Not02() throws Exception {
148: int[] expdnrs = { 0 };
149: normalTest1("word2* not ord*", expdnrs);
150: }
151:
152: public void test06AndOr01() throws Exception {
153: int[] expdnrs = { 0 };
154: normalTest1("(word1 or ab)and or(word2,xyz, defg)", expdnrs);
155: }
156:
157: public void test07AndOrNot02() throws Exception {
158: int[] expdnrs = { 0 };
159: normalTest1("or( word2* not ord*, and(xyz,def))", expdnrs);
160: }
161: }
|