TestNearSpansOrderedpublic class TestNearSpansOrdered extends TestCase Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You 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. |
Fields Summary |
---|
protected IndexSearcher | searcher | public static final String | FIELD | public static final QueryParser | qp | protected String[] | docFields |
Methods Summary |
---|
protected org.apache.lucene.search.spans.SpanNearQuery | makeQuery(java.lang.String s1, java.lang.String s2, java.lang.String s3, int slop, boolean inOrder)
return new SpanNearQuery
(new SpanQuery[] {
new SpanTermQuery(new Term(FIELD, s1)),
new SpanTermQuery(new Term(FIELD, s2)),
new SpanTermQuery(new Term(FIELD, s3)) },
slop,
inOrder);
| protected org.apache.lucene.search.spans.SpanNearQuery | makeQuery()
return makeQuery("w1","w2","w3",1,true);
| public java.lang.String | s(org.apache.lucene.search.spans.Spans span)
return s(span.doc(), span.start(), span.end());
| public java.lang.String | s(int doc, int start, int end)
return "s(" + doc + "," + start + "," + end +")";
| public void | setUp()
RAMDirectory directory = new RAMDirectory();
IndexWriter writer= new IndexWriter(directory, new WhitespaceAnalyzer(), true);
for (int i = 0; i < docFields.length; i++) {
Document doc = new Document();
doc.add(new Field(FIELD, docFields[i], Field.Store.NO, Field.Index.TOKENIZED));
writer.addDocument(doc);
}
writer.close();
searcher = new IndexSearcher(directory);
| public void | tearDown()
searcher.close();
| public void | testNearSpansNext()
SpanNearQuery q = makeQuery();
Spans span = q.getSpans(searcher.getIndexReader());
assertEquals(true, span.next());
assertEquals(s(0,0,3), s(span));
assertEquals(true, span.next());
assertEquals(s(1,0,4), s(span));
assertEquals(false, span.next());
| public void | testNearSpansNextThenSkipPast()
SpanNearQuery q = makeQuery();
Spans span = q.getSpans(searcher.getIndexReader());
assertEquals(true, span.next());
assertEquals(s(0,0,3), s(span));
assertEquals(false, span.skipTo(2));
| public void | testNearSpansNextThenSkipTo()
SpanNearQuery q = makeQuery();
Spans span = q.getSpans(searcher.getIndexReader());
assertEquals(true, span.next());
assertEquals(s(0,0,3), s(span));
assertEquals(true, span.skipTo(1));
assertEquals(s(1,0,4), s(span));
assertEquals(false, span.next());
| public void | testNearSpansSkipPast()
SpanNearQuery q = makeQuery();
Spans span = q.getSpans(searcher.getIndexReader());
assertEquals(false, span.skipTo(2));
| public void | testNearSpansSkipTo0()
SpanNearQuery q = makeQuery();
Spans span = q.getSpans(searcher.getIndexReader());
assertEquals(true, span.skipTo(0));
assertEquals(s(0,0,3), s(span));
| public void | testNearSpansSkipTo1()
SpanNearQuery q = makeQuery();
Spans span = q.getSpans(searcher.getIndexReader());
assertEquals(true, span.skipTo(1));
assertEquals(s(1,0,4), s(span));
| public void | testNearSpansSkipToLikeNext()test does not imply that skipTo(doc+1) should work exactly the
same as next -- it's only applicable in this case since we know doc
does not contain more than one span
SpanNearQuery q = makeQuery();
Spans span = q.getSpans(searcher.getIndexReader());
assertEquals(true, span.skipTo(0));
assertEquals(s(0,0,3), s(span));
assertEquals(true, span.skipTo(1));
assertEquals(s(1,0,4), s(span));
assertEquals(false, span.skipTo(2));
| public void | testSpanNearQuery()
SpanNearQuery q = makeQuery();
CheckHits.checkHits(q, FIELD, searcher, new int[] {0,1});
| public void | testSpanNearScorerExplain()not a direct test of NearSpans, but a demonstration of how/when
this causes problems
SpanNearQuery q = makeQuery();
Weight w = q.createWeight(searcher);
Scorer s = w.scorer(searcher.getIndexReader());
Explanation e = s.explain(1);
assertTrue("Scorer explanation value for doc#1 isn't positive: "
+ e.toString(),
0.0f < e.getValue());
| public void | testSpanNearScorerSkipTo1()not a direct test of NearSpans, but a demonstration of how/when
this causes problems
SpanNearQuery q = makeQuery();
Weight w = q.createWeight(searcher);
Scorer s = w.scorer(searcher.getIndexReader());
assertEquals(true, s.skipTo(1));
assertEquals(1, s.doc());
|
|