Package com.bah.lucene.hdfs

Examples of com.bah.lucene.hdfs.HdfsDirectory


/**
*/
public class WriteReadPerformanceTest {

    public static void main(String[] args) throws Exception {
        HdfsDirectory hdfsDirectory = new HdfsDirectory(new Configuration(), new Path("hdfs://localhost/index"));
        Directory directory = new BlockCacheDirectoryFactoryV2(new Configuration(), 1000000).newDirectory(
                "index", "shard1", hdfsDirectory, null
        );

        String[] names = new String[]{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
View Full Code Here


            Path localIndexPath = new Path("/localindex");
            fileSystem.mkdirs(localIndexPath);
            fileSystem.copyFromLocalFile(new Path(localDir.getAbsolutePath() + "/"), localIndexPath);
            Path hdfsIndexPath = fileSystem.listStatus(localIndexPath)[0].getPath();

            HdfsDirectory hdfsDirectory = new HdfsDirectory(conf, hdfsIndexPath);
            Directory directory = new BlockCacheDirectoryFactoryV2(new Configuration(), 1000000).newDirectory(
                    "index", "shard1", hdfsDirectory, null
            );

            try (DirectoryReader reader = DirectoryReader.open(directory)) {
                IndexSearcher indexSearcher = new IndexSearcher(reader);

                long start = System.currentTimeMillis();
                Query query = new QueryParser(Version.LUCENE_43, "name", analyzer).parse("r");
                TopDocs search = indexSearcher.search(query, 1000);
                ScoreDoc[] scoreDocs = search.scoreDocs;
                System.out.println("Found " + scoreDocs.length + " num of documents from search in " +
                        (System.currentTimeMillis() - start) +
                        " ms. Total[" + search.totalHits + "]");

                start = System.currentTimeMillis();
                for (ScoreDoc scoreDoc : scoreDocs) {
                    Document doc = indexSearcher.doc(scoreDoc.doc);
                    assert doc != null;
                }
                System.out.println("Took [" + (System.currentTimeMillis() - start) + "] ms to retrieve all docs");
            }

            hdfsDirectory.close();
            directory.close();
        } finally {
            localDirectory.close();
            FileDeleteStrategy.FORCE.delete(localDir);
        }
View Full Code Here

TOP

Related Classes of com.bah.lucene.hdfs.HdfsDirectory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.