FileDocCategorySizeDatePackage
TestWindowsMMap.javaAPI DocApache Lucene 2.1.02349Wed Feb 14 10:46:34 GMT 2007org.apache.lucene.store

TestWindowsMMap

public class TestWindowsMMap extends TestCase

Fields Summary
private static final String
alphabet
private Random
random
private static final String
storePathname
Constructors Summary
Methods Summary
private java.lang.StringrandomField()

		int fl = 1 + random.nextInt(3);
		StringBuffer fb = new StringBuffer();
		for(int fx = 0; fx < fl; fx ++) {
			fb.append(randomToken());
			fb.append(" ");
		}
		return fb.toString();
	
private java.lang.StringrandomToken()

		int tl = 1 + random.nextInt(7);
		StringBuffer sb = new StringBuffer();
		for(int cx = 0; cx < tl; cx ++) {
			int c = random.nextInt(25);
			sb.append(alphabet.substring(c, c+1));
		}
		return sb.toString();
	
private voidrmDir(java.io.File dir)

          File[] files = dir.listFiles();
          for (int i = 0; i < files.length; i++) {
            files[i].delete();
          }
          dir.delete();
        
public voidsetUp()

	
	   
		random = new Random();
		System.setProperty("org.apache.lucene.FSDirectory.class", "org.apache.lucene.store.MMapDirectory");
	
public voidtestMmapIndex()


	     
		FSDirectory storeDirectory;
		storeDirectory = FSDirectory.getDirectory(storePathname);

		// plan to add a set of useful stopwords, consider changing some of the
		// interior filters.
		StandardAnalyzer analyzer = new StandardAnalyzer(new HashSet());
		// TODO: something about lock timeouts and leftover locks.
		IndexWriter writer = new IndexWriter(storeDirectory, analyzer, true);
		IndexSearcher searcher = new IndexSearcher(storePathname);
		
		for(int dx = 0; dx < 1000; dx ++) {
			String f = randomField();
			Document doc = new Document();
			doc.add(new Field("data", f, Field.Store.YES, Field.Index.TOKENIZED));	
			writer.addDocument(doc);
		}
		
		searcher.close();
		writer.close();
                rmDir(new File(storePathname));