1 package org.apache.lucene.queryParser.surround.query;
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 import java.util.Random;
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;
32 public class SingleFieldTestDb {
34 private String[] docs;
35 private String fieldName;
37 public SingleFieldTestDb(Random random, String[] documents, String fName) {
39 db = new MockDirectoryWrapper(random, new RAMDirectory());
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);
51 } catch (java.io.IOException ioe) {
56 Directory getDb() {return db;}
57 String[] getDocs() {return docs;}
58 String getFieldname() {return fieldName;}