001: package org.apache.lucene.search.spans;
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 org.apache.lucene.search.*;
021: import org.apache.lucene.store.RAMDirectory;
022:
023: import org.apache.lucene.index.IndexWriter;
024: import org.apache.lucene.index.IndexReader;
025: import org.apache.lucene.index.Term;
026:
027: import org.apache.lucene.analysis.WhitespaceAnalyzer;
028:
029: import org.apache.lucene.document.Document;
030: import org.apache.lucene.document.Field;
031:
032: import org.apache.lucene.queryParser.QueryParser;
033: import org.apache.lucene.queryParser.ParseException;
034:
035: import junit.framework.TestCase;
036:
037: import java.util.Random;
038: import java.util.BitSet;
039:
040: /**
041: * TestExplanations subclass focusing on span queries
042: */
043: public class TestSpanExplanations extends TestExplanations {
044:
045: /* simple SpanTermQueries */
046:
047: public void testST1() throws Exception {
048: SpanQuery q = st("w1");
049: qtest(q, new int[] { 0, 1, 2, 3 });
050: }
051:
052: public void testST2() throws Exception {
053: SpanQuery q = st("w1");
054: q.setBoost(1000);
055: qtest(q, new int[] { 0, 1, 2, 3 });
056: }
057:
058: public void testST4() throws Exception {
059: SpanQuery q = st("xx");
060: qtest(q, new int[] { 2, 3 });
061: }
062:
063: public void testST5() throws Exception {
064: SpanQuery q = st("xx");
065: q.setBoost(1000);
066: qtest(q, new int[] { 2, 3 });
067: }
068:
069: /* some SpanFirstQueries */
070:
071: public void testSF1() throws Exception {
072: SpanQuery q = sf(("w1"), 1);
073: qtest(q, new int[] { 0, 1, 2, 3 });
074: }
075:
076: public void testSF2() throws Exception {
077: SpanQuery q = sf(("w1"), 1);
078: q.setBoost(1000);
079: qtest(q, new int[] { 0, 1, 2, 3 });
080: }
081:
082: public void testSF4() throws Exception {
083: SpanQuery q = sf(("xx"), 2);
084: qtest(q, new int[] { 2 });
085: }
086:
087: public void testSF5() throws Exception {
088: SpanQuery q = sf(("yy"), 2);
089: qtest(q, new int[] {});
090: }
091:
092: public void testSF6() throws Exception {
093: SpanQuery q = sf(("yy"), 4);
094: q.setBoost(1000);
095: qtest(q, new int[] { 2 });
096: }
097:
098: /* some SpanOrQueries */
099:
100: public void testSO1() throws Exception {
101: SpanQuery q = sor("w1", "QQ");
102: qtest(q, new int[] { 0, 1, 2, 3 });
103: }
104:
105: public void testSO2() throws Exception {
106: SpanQuery q = sor("w1", "w3", "zz");
107: qtest(q, new int[] { 0, 1, 2, 3 });
108: }
109:
110: public void testSO3() throws Exception {
111: SpanQuery q = sor("w5", "QQ", "yy");
112: qtest(q, new int[] { 0, 2, 3 });
113: }
114:
115: public void testSO4() throws Exception {
116: SpanQuery q = sor("w5", "QQ", "yy");
117: qtest(q, new int[] { 0, 2, 3 });
118: }
119:
120: /* some SpanNearQueries */
121:
122: public void testSNear1() throws Exception {
123: SpanQuery q = snear("w1", "QQ", 100, true);
124: qtest(q, new int[] {});
125: }
126:
127: public void testSNear2() throws Exception {
128: SpanQuery q = snear("w1", "xx", 100, true);
129: qtest(q, new int[] { 2, 3 });
130: }
131:
132: public void testSNear3() throws Exception {
133: SpanQuery q = snear("w1", "xx", 0, true);
134: qtest(q, new int[] { 2 });
135: }
136:
137: public void testSNear4() throws Exception {
138: SpanQuery q = snear("w1", "xx", 1, true);
139: qtest(q, new int[] { 2, 3 });
140: }
141:
142: public void testSNear5() throws Exception {
143: SpanQuery q = snear("xx", "w1", 0, false);
144: qtest(q, new int[] { 2 });
145: }
146:
147: public void testSNear6() throws Exception {
148: SpanQuery q = snear("w1", "w2", "QQ", 100, true);
149: qtest(q, new int[] {});
150: }
151:
152: public void testSNear7() throws Exception {
153: SpanQuery q = snear("w1", "xx", "w2", 100, true);
154: qtest(q, new int[] { 2, 3 });
155: }
156:
157: public void testSNear8() throws Exception {
158: SpanQuery q = snear("w1", "xx", "w2", 0, true);
159: qtest(q, new int[] { 2 });
160: }
161:
162: public void testSNear9() throws Exception {
163: SpanQuery q = snear("w1", "xx", "w2", 1, true);
164: qtest(q, new int[] { 2, 3 });
165: }
166:
167: public void testSNear10() throws Exception {
168: SpanQuery q = snear("xx", "w1", "w2", 0, false);
169: qtest(q, new int[] { 2 });
170: }
171:
172: public void testSNear11() throws Exception {
173: SpanQuery q = snear("w1", "w2", "w3", 1, true);
174: qtest(q, new int[] { 0, 1 });
175: }
176:
177: /* some SpanNotQueries */
178:
179: public void testSNot1() throws Exception {
180: SpanQuery q = snot(sf("w1", 10), st("QQ"));
181: qtest(q, new int[] { 0, 1, 2, 3 });
182: }
183:
184: public void testSNot2() throws Exception {
185: SpanQuery q = snot(sf("w1", 10), st("QQ"));
186: q.setBoost(1000);
187: qtest(q, new int[] { 0, 1, 2, 3 });
188: }
189:
190: public void testSNot4() throws Exception {
191: SpanQuery q = snot(sf("w1", 10), st("xx"));
192: qtest(q, new int[] { 0, 1, 2, 3 });
193: }
194:
195: public void testSNot5() throws Exception {
196: SpanQuery q = snot(sf("w1", 10), st("xx"));
197: q.setBoost(1000);
198: qtest(q, new int[] { 0, 1, 2, 3 });
199: }
200:
201: public void testSNot7() throws Exception {
202: SpanQuery f = snear("w1", "w3", 10, true);
203: f.setBoost(1000);
204: SpanQuery q = snot(f, st("xx"));
205: qtest(q, new int[] { 0, 1, 3 });
206: }
207:
208: public void testSNot10() throws Exception {
209: SpanQuery t = st("xx");
210: t.setBoost(10000);
211: SpanQuery q = snot(snear("w1", "w3", 10, true), t);
212: qtest(q, new int[] { 0, 1, 3 });
213: }
214:
215: }
|