add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / queryparser / src / test / org / apache / lucene / queryParser / surround / query / SingleFieldTestDb.java
1 package org.apache.lucene.queryParser.surround.query;
2
3 /**
4  * Licensed to the Apache Software Foundation (ASF) under one or more
5  * contributor license agreements.  See the NOTICE file distributed with
6  * this work for additional information regarding copyright ownership.
7  * The ASF licenses this file to You under the Apache License, Version 2.0
8  * (the "License"); you may not use this file except in compliance with
9  * the License.  You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 import java.util.Random;
21
22 import org.apache.lucene.store.Directory;
23 import org.apache.lucene.store.MockDirectoryWrapper;
24 import org.apache.lucene.store.RAMDirectory;
25 import org.apache.lucene.util.Version;
26 import org.apache.lucene.analysis.MockAnalyzer;
27 import org.apache.lucene.document.Document;
28 import org.apache.lucene.document.Field;
29 import org.apache.lucene.index.IndexWriter;
30 import org.apache.lucene.index.IndexWriterConfig;
31
32 public class SingleFieldTestDb {
33   private Directory db;
34   private String[] docs;
35   private String fieldName;
36   
37   public SingleFieldTestDb(Random random, String[] documents, String fName) {
38     try {
39       db = new MockDirectoryWrapper(random, new RAMDirectory());
40       docs = documents;
41       fieldName = fName;
42       IndexWriter writer = new IndexWriter(db, new IndexWriterConfig(
43           Version.LUCENE_CURRENT,
44           new MockAnalyzer(random)));
45       for (int j = 0; j < docs.length; j++) {
46         Document d = new Document();
47         d.add(new Field(fieldName, docs[j], Field.Store.NO, Field.Index.ANALYZED));
48         writer.addDocument(d);
49       }
50       writer.close();
51     } catch (java.io.IOException ioe) {
52       throw new Error(ioe);
53     }
54   }
55   
56   Directory getDb() {return db;}
57   String[] getDocs() {return docs;}
58   String getFieldname() {return fieldName;}
59 }
60
61