mirror of https://github.com/apache/lucene.git
New Span query tests for LUCENE-557
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@415481 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c5cd491839
commit
20240390e3
|
@ -0,0 +1,189 @@
|
|||
package org.apache.lucene.search.spans;
|
||||
|
||||
/**
|
||||
* Copyright 2006 Apache Software Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import org.apache.lucene.search.*;
|
||||
import org.apache.lucene.store.RAMDirectory;
|
||||
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.Term;
|
||||
|
||||
import org.apache.lucene.analysis.WhitespaceAnalyzer;
|
||||
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field;
|
||||
|
||||
import org.apache.lucene.queryParser.QueryParser;
|
||||
import org.apache.lucene.queryParser.ParseException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.BitSet;
|
||||
|
||||
/**
|
||||
* TestExplanations subclass focusing on span queries
|
||||
*/
|
||||
public class TestSpanExplanations extends TestExplanations {
|
||||
|
||||
/* simple SpanTermQueries */
|
||||
|
||||
public void testST1() throws Exception {
|
||||
SpanQuery q = st("w1");
|
||||
qtest(q, new int[] {0,1,2,3});
|
||||
}
|
||||
public void testST2() throws Exception {
|
||||
SpanQuery q = st("w1");
|
||||
q.setBoost(1000);
|
||||
qtest(q, new int[] {0,1,2,3});
|
||||
}
|
||||
public void testST4() throws Exception {
|
||||
SpanQuery q = st("xx");
|
||||
qtest(q, new int[] {2,3});
|
||||
}
|
||||
public void testST5() throws Exception {
|
||||
SpanQuery q = st("xx");
|
||||
q.setBoost(1000);
|
||||
qtest(q, new int[] {2,3});
|
||||
}
|
||||
|
||||
/* some SpanFirstQueries */
|
||||
|
||||
public void testSF1() throws Exception {
|
||||
SpanQuery q = sf(("w1"),1);
|
||||
qtest(q, new int[] {0,1,2,3});
|
||||
}
|
||||
public void testSF2() throws Exception {
|
||||
SpanQuery q = sf(("w1"),1);
|
||||
q.setBoost(1000);
|
||||
qtest(q, new int[] {0,1,2,3});
|
||||
}
|
||||
public void testSF4() throws Exception {
|
||||
SpanQuery q = sf(("xx"),2);
|
||||
qtest(q, new int[] {2});
|
||||
}
|
||||
public void testSF5() throws Exception {
|
||||
SpanQuery q = sf(("yy"),2);
|
||||
qtest(q, new int[] { });
|
||||
}
|
||||
public void testSF6() throws Exception {
|
||||
SpanQuery q = sf(("yy"),4);
|
||||
q.setBoost(1000);
|
||||
qtest(q, new int[] {2});
|
||||
}
|
||||
|
||||
/* some SpanOrQueries */
|
||||
|
||||
public void testSO1() throws Exception {
|
||||
SpanQuery q = sor("w1","QQ");
|
||||
qtest(q, new int[] {0,1,2,3});
|
||||
}
|
||||
public void testSO2() throws Exception {
|
||||
SpanQuery q = sor("w1","w3","zz");
|
||||
qtest(q, new int[] {0,1,2,3});
|
||||
}
|
||||
public void testSO3() throws Exception {
|
||||
SpanQuery q = sor("w5","QQ","yy");
|
||||
qtest(q, new int[] {0,2,3});
|
||||
}
|
||||
public void testSO4() throws Exception {
|
||||
SpanQuery q = sor("w5","QQ","yy");
|
||||
qtest(q, new int[] {0,2,3});
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* some SpanNearQueries */
|
||||
|
||||
public void testSNear1() throws Exception {
|
||||
SpanQuery q = snear("w1","QQ",100,true);
|
||||
qtest(q, new int[] {});
|
||||
}
|
||||
public void testSNear2() throws Exception {
|
||||
SpanQuery q = snear("w1","xx",100,true);
|
||||
qtest(q, new int[] {2,3});
|
||||
}
|
||||
public void testSNear3() throws Exception {
|
||||
SpanQuery q = snear("w1","xx",0,true);
|
||||
qtest(q, new int[] {2});
|
||||
}
|
||||
public void testSNear4() throws Exception {
|
||||
SpanQuery q = snear("w1","xx",1,true);
|
||||
qtest(q, new int[] {2,3});
|
||||
}
|
||||
public void testSNear5() throws Exception {
|
||||
SpanQuery q = snear("xx","w1",0,false);
|
||||
qtest(q, new int[] {2});
|
||||
}
|
||||
|
||||
public void testSNear6() throws Exception {
|
||||
SpanQuery q = snear("w1","w2","QQ",100,true);
|
||||
qtest(q, new int[] {});
|
||||
}
|
||||
public void testSNear7() throws Exception {
|
||||
SpanQuery q = snear("w1","xx","w2",100,true);
|
||||
qtest(q, new int[] {2,3});
|
||||
}
|
||||
public void testSNear8() throws Exception {
|
||||
SpanQuery q = snear("w1","xx","w2",0,true);
|
||||
qtest(q, new int[] {2});
|
||||
}
|
||||
public void testSNear9() throws Exception {
|
||||
SpanQuery q = snear("w1","xx","w2",1,true);
|
||||
qtest(q, new int[] {2,3});
|
||||
}
|
||||
public void testSNear10() throws Exception {
|
||||
SpanQuery q = snear("xx","w1","w2",0,false);
|
||||
qtest(q, new int[] {2});
|
||||
}
|
||||
|
||||
|
||||
/* some SpanNotQueries */
|
||||
|
||||
public void testSNot1() throws Exception {
|
||||
SpanQuery q = snot(sf("w1",10),st("QQ"));
|
||||
qtest(q, new int[] {0,1,2,3});
|
||||
}
|
||||
public void testSNot2() throws Exception {
|
||||
SpanQuery q = snot(sf("w1",10),st("QQ"));
|
||||
q.setBoost(1000);
|
||||
qtest(q, new int[] {0,1,2,3});
|
||||
}
|
||||
public void testSNot4() throws Exception {
|
||||
SpanQuery q = snot(sf("w1",10),st("xx"));
|
||||
qtest(q, new int[] {0,1,2,3});
|
||||
}
|
||||
public void testSNot5() throws Exception {
|
||||
SpanQuery q = snot(sf("w1",10),st("xx"));
|
||||
q.setBoost(1000);
|
||||
qtest(q, new int[] {0,1,2,3});
|
||||
}
|
||||
public void testSNot7() throws Exception {
|
||||
SpanQuery f = snear("w1","w3",10,true);
|
||||
f.setBoost(1000);
|
||||
SpanQuery q = snot(f, st("xx"));
|
||||
qtest(q, new int[] {0,1,3});
|
||||
}
|
||||
public void testSNot10() throws Exception {
|
||||
SpanQuery t = st("xx");
|
||||
t.setBoost(10000);
|
||||
SpanQuery q = snot(snear("w1","w3",10,true), t);
|
||||
qtest(q, new int[] {0,1,3});
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package org.apache.lucene.search.spans;
|
||||
|
||||
/**
|
||||
* Copyright 2006 Apache Software Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.search.CheckHits;
|
||||
|
||||
|
||||
/**
|
||||
* subclass of TestSimpleExplanations that verifies non matches.
|
||||
*/
|
||||
public class TestSpanExplanationsOfNonMatches
|
||||
extends TestSpanExplanations {
|
||||
|
||||
/**
|
||||
* Overrides superclass to ignore matches and focus on non-matches
|
||||
*
|
||||
* @see CheckHits#checkNoMatchExplanations
|
||||
*/
|
||||
public void qtest(Query q, int[] expDocNrs) throws Exception {
|
||||
CheckHits.checkNoMatchExplanations(q, FIELD, searcher, expDocNrs);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue