Example usage for org.apache.lucene.index CodecReader getChildResources

List of usage examples for org.apache.lucene.index CodecReader getChildResources

Introduction

In this page you can find the example usage for org.apache.lucene.index CodecReader getChildResources.

Prototype

@Override
    public Collection<Accountable> getChildResources() 

Source Link

Usage

From source file:perf.SearchTaxis.java

License:Apache License

public static void main(String[] args) throws IOException, InterruptedException {
    Path indexPath = Paths.get(args[0]);

    String sparseOrNot = args[1];
    boolean sparse;
    if (sparseOrNot.equals("sparse")) {
        sparse = true;/*from ww  w .j  av  a  2s .co m*/
    } else if (sparseOrNot.equals("nonsparse")) {
        sparse = false;
    } else {
        throw new IllegalArgumentException("expected sparse or nonsparse but got: " + sparseOrNot);
    }

    Directory dir = FSDirectory.open(indexPath);

    IndexReader reader = DirectoryReader.open(dir);
    System.out.println("READER: " + reader);
    long bytes = 0;
    for (LeafReaderContext ctx : reader.leaves()) {
        CodecReader cr = (CodecReader) ctx.reader();
        System.out.println("\nREADER: " + cr);
        for (Accountable acc : cr.getChildResources()) {
            System.out.println("  " + Accountables.toString(acc));
        }
        bytes += cr.ramBytesUsed();
    }
    System.out.println("HEAP: " + bytes);

    IndexSearcher searcher = new IndexSearcher(reader);

    Random random = new Random(17);

    SearchThread[] threads = new SearchThread[2];
    for (int i = 0; i < threads.length; i++) {
        threads[i] = new SearchThread(i, sparse, searcher, 500, new Random(random.nextLong()));
        threads[i].start();
    }

    for (SearchThread thread : threads) {
        thread.join();
    }

    /*
    SearchThread[] threads = new SearchThread[] {new SearchThread(0, sparse, searcher, 1000, new Random(random.nextLong()))};
    threads[0].run();
    */

    for (SearchThread thread : threads) {
        for (String line : thread.results) {
            System.out.println(line);
        }
    }

    IOUtils.close(reader, dir);
}