Example usage for org.apache.lucene.store FSDirectory listAll

List of usage examples for org.apache.lucene.store FSDirectory listAll

Introduction

In this page you can find the example usage for org.apache.lucene.store FSDirectory listAll.

Prototype

public static String[] listAll(Path dir) throws IOException 

Source Link

Document

Lists all files (including subdirectories) in the directory.

Usage

From source file:com.aliasi.lingmed.medline.IndexMedline.java

License:Lingpipe license

private boolean isNewDirectory(File mIndex) throws IOException {
    String[] contents = FSDirectory.listAll(mIndex);
    if (contents.length == 0)
        return true;
    return false;
}

From source file:org.openmrs.module.conceptmanagementapps.api.impl.ConceptManagementAppsServiceImpl.java

License:Open Source License

private void indexSnomedFiles(String snomedFiles) throws FileNotFoundException {
    if (!getManageSnomedCTProcessCancelled()) {

        BufferedReader br = null;
        IndexWriter writer = null;/*from  w w  w  .j a  va 2  s  . c  o m*/

        try {

            File file = new File(snomedFiles);

            //check to make sure other processes have had time to clear the directory before starting to index if it takes too long something may be wrong and we should throw an exception
            int tries = 0;
            while (FSDirectory.listAll(new File(snomedIndexFileDirectoryLocation)).length > 0) {
                if (tries > 5) {
                    throw new Exception("index directory is not empty or is locked");
                }
                Thread.sleep(5000);
                tries++;
            }

            FSDirectory dir = FSDirectory.open(new File(snomedIndexFileDirectoryLocation));
            IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_44, analyzer);

            if (file.listFiles() == null) {
                throw new FileNotFoundException("Error finding SNOMED CT files. Please check the path.");
            }

            for (File f : file.listFiles()) {

                writer = new IndexWriter(dir, config);

                if (StringUtils.contains(f.getName(), RELATIONSHIP_FILE)) {

                    br = new BufferedReader(new FileReader(f));

                    for (String line = br.readLine(); line != null; line = br.readLine()) {

                        String[] fileFields = line.split("\t");

                        if (fileFields[0].length() > 0) {

                        }
                        //is term active and an IS-A relationship
                        if (StringUtils.equalsIgnoreCase(fileFields[2], RETIRED_TERM)
                                && StringUtils.equalsIgnoreCase(fileFields[7], IS_A_RELATIONSHIP)) {

                            Document doc = new Document();

                            //get the row id, the parent term, and the child term
                            doc.add(new StringField(ROW_ID, fileFields[0], Field.Store.YES));
                            doc.add(new StringField(PARENT_TERM, fileFields[4], Field.Store.YES));
                            doc.add(new StringField(CHILD_TERM, fileFields[5], Field.Store.YES));
                            writer.addDocument(doc);

                        }
                    }
                }
                if (StringUtils.contains(f.getName(), DESCRIPTION_FILE)) {

                    br = new BufferedReader(new FileReader(f));

                    for (String line = br.readLine(); line != null; line = br.readLine()) {

                        String[] fileFields = line.split("\t");

                        //is the term active
                        if (fileFields[0].length() > 0) {
                            if (StringUtils.equalsIgnoreCase(fileFields[2], RETIRED_TERM)) {

                                Document doc = new Document();

                                //get the term id, the name, and the effective date(effective date for finding out if it is the newest)
                                doc.add(new StringField(TERM_ID, fileFields[4], Field.Store.YES));
                                doc.add(new StringField(TERM_NAME, fileFields[7], Field.Store.YES));
                                doc.add(new StringField(EFFECTIVE_DATE, fileFields[1], Field.Store.YES));
                                writer.addDocument(doc);

                            }
                        }

                    }
                }

                writer.close();
            }
        } catch (FileNotFoundException e) {
            log.error("Error Indexing Snomed Files: File Not Found", e);
            throw new FileNotFoundException("Error finding SNOMED CT files. Please check the path. " + e);

        } catch (IOException e) {
            log.error("Error Indexing Snomed Files ", e);
        } catch (Exception e) {
            log.error("Error Indexing Snomed Files ", e);
        } finally {
            try {
                if (br != null) {
                    br.close();
                }
                if (writer != null) {
                    writer.close();
                }
            } catch (IOException e) {
                log.error("Error Indexing Snomed Files: trying to close buffered reader ", e);
            }
        }
    } else {
        return;
    }
}