2
* Copyright 2006 The Apache Software Foundation
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
16
package org.apache.lucene.store.instantiated;
18
import org.apache.lucene.search.IndexSearcher;
19
import org.apache.lucene.search.TermQuery;
20
import org.apache.lucene.search.Scorer;
21
import org.apache.lucene.document.Document;
22
import org.apache.lucene.document.Field;
23
import org.apache.lucene.index.Term;
24
import org.apache.lucene.index.IndexReader;
25
import org.apache.lucene.util.LuceneTestCase;
28
* Assert that the content of an index
29
* is instantly available
30
* for all open searchers
31
* also after a commit.
33
public class TestRealTime extends LuceneTestCase {
35
public void test() throws Exception {
37
InstantiatedIndex index = new InstantiatedIndex();
38
InstantiatedIndexReader reader = new InstantiatedIndexReader(index);
39
IndexSearcher searcher = newSearcher(reader, false);
40
InstantiatedIndexWriter writer = new InstantiatedIndexWriter(index);
46
doc.add(new Field("f", "a", Field.Store.NO, Field.Index.NOT_ANALYZED));
47
writer.addDocument(doc);
50
collector = new Collector();
51
searcher.search(new TermQuery(new Term("f", "a")), collector);
52
assertEquals(1, collector.hits);
55
doc.add(new Field("f", "a", Field.Store.NO, Field.Index.NOT_ANALYZED));
56
writer.addDocument(doc);
59
collector = new Collector();
60
searcher.search(new TermQuery(new Term("f", "a")), collector);
61
assertEquals(2, collector.hits);
65
public static class Collector extends org.apache.lucene.search.Collector {
68
public void setScorer(Scorer scorer) {}
70
public void setNextReader(IndexReader reader, int docBase) {}
72
public boolean acceptsDocsOutOfOrder() { return true; }
74
public void collect(int doc) {