01: package org.apache.lucene.search;
02:
03: /**
04: * Copyright 2004 The Apache Software Foundation
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: import org.apache.lucene.analysis.WhitespaceAnalyzer;
20: import org.apache.lucene.document.Document;
21: import org.apache.lucene.document.Field;
22: import org.apache.lucene.index.IndexReader;
23: import org.apache.lucene.index.IndexWriter;
24: import org.apache.lucene.store.RAMDirectory;
25: import org.apache.lucene.util.English;
26: import org.apache.lucene.util.LuceneTestCase;
27:
28: import java.io.IOException;
29:
30: public class TestExtendedFieldCache extends LuceneTestCase {
31: protected IndexReader reader;
32: private static final int NUM_DOCS = 1000;
33:
34: public TestExtendedFieldCache(String s) {
35: super (s);
36: }
37:
38: protected void setUp() throws Exception {
39: super .setUp();
40: RAMDirectory directory = new RAMDirectory();
41: IndexWriter writer = new IndexWriter(directory,
42: new WhitespaceAnalyzer(), true);
43: long theLong = Long.MAX_VALUE;
44: double theDouble = Double.MAX_VALUE;
45: for (int i = 0; i < NUM_DOCS; i++) {
46: Document doc = new Document();
47: doc.add(new Field("theLong", String.valueOf(theLong--),
48: Field.Store.NO, Field.Index.UN_TOKENIZED));
49: doc.add(new Field("theDouble", String.valueOf(theDouble--),
50: Field.Store.NO, Field.Index.UN_TOKENIZED));
51: doc.add(new Field("text", English.intToEnglish(i),
52: Field.Store.NO, Field.Index.TOKENIZED));
53: writer.addDocument(doc);
54: }
55: writer.close();
56: reader = IndexReader.open(directory);
57: }
58:
59: public void test() throws IOException {
60: ExtendedFieldCache cache = new ExtendedFieldCacheImpl();
61: double[] doubles = cache.getDoubles(reader, "theDouble");
62: assertTrue("doubles Size: " + doubles.length + " is not: "
63: + NUM_DOCS, doubles.length == NUM_DOCS);
64: for (int i = 0; i < doubles.length; i++) {
65: assertTrue(doubles[i] + " does not equal: "
66: + (Double.MAX_VALUE - i),
67: doubles[i] == (Double.MAX_VALUE - i));
68:
69: }
70: long[] longs = cache.getLongs(reader, "theLong");
71: assertTrue("longs Size: " + longs.length + " is not: "
72: + NUM_DOCS, longs.length == NUM_DOCS);
73: for (int i = 0; i < longs.length; i++) {
74: assertTrue(longs[i] + " does not equal: "
75: + (Long.MAX_VALUE - i),
76: longs[i] == (Long.MAX_VALUE - i));
77:
78: }
79: }
80: }
|