//My code: A call is made to getConnectionString().
@Stateful
@Named
@ConversationScoped
public class MyClass implements Serializable {
@Resource(name = "java:jboss/datasources/myDatasource")
private DataSource dataSource;
private Logger logger;
SnomedConceptDatabaseDAO snomedConceptDatabaseDAO;
String connectionString;
public String getConnectionString() {
try {
logger.info("Connection Successful: " +
dataSource.getConnection().getCatalog());
snomedConceptDatabaseDAO = new
SnomedConceptDatabaseDAO(dataSource);
} catch (SQLException ex) {
logger.info("Connection Unsuccessful: " + ex.toString());
}
testLucene();
return "DONE";
}
public void testLucene() {
SnomedLuceneIndexer sli = new SnomedLuceneIndexer(dataSource,
snomedConceptDatabaseDAO);
sli.indexConcepts();
}
}
//The SnomedLuceneIndexer constructor
public SnomedLuceneIndexer(DataSource dataSource,
TerminologyConceptDAO terminologyConceptDAO) {
try {
this.connection = dataSource.getConnection();
this.terminologyConceptDAO = terminologyConceptDAO;
try {
directory = FSDirectory.open(new
File(System.getProperty("user.dir") + "/.myFolder/snomed-desc/
lucene"));
logger.debug("Value of directory : " + directory);
indexWriterConfig = new
IndexWriterConfig(Version.LUCENE_34, new
StandardAnalyzer(Version.LUCENE_34));
// Using the default line below, indexing is still
slow. Your use of indexwriter is also deprecated using lucene 3.4
// indexWriter = new IndexWriter(directory, new
StandardAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED);
indexWriter = new IndexWriter(directory,
indexWriterConfig);
} catch (IOException e) {
logger.warn("Error locating location of index
directory. Nested exception is : " + e.fillInStackTrace());
}
} catch (SQLException e) {
logger.warn("Error obtaining connection from data source.
Nested exception is : " + e.fillInStackTrace());
}
}
//Modified method from SnomedLuceneIndexer
public void indexConcepts() {
try {
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery(""
+ "SELECT DISTINCT CONCEPT_ID FROM
PUBLIC.CONCEPTS_TABLE");
int counter = 1;
while (rs.next()) {
String conceptID = rs.getString("CONCEPT_ID");
SnomedConcept concept = (SnomedConcept)
terminologyConceptDAO.getTerminologyConcept(conceptID);
Document document = new Document();
String preferredTerm = concept.getPreferredLabel();
String fullySpecName =
concept.getFullySpecifiedName();
String isPrimitive =
String.valueOf(concept.isPrimitive());
String source = concept.getSource();
String status = concept.getStatus().name();
String conceptType = concept.getType().name();
conceptType = conceptType.replaceAll(" ", "_");
document.add(new Field("ID", conceptID, Store.YES,
Index.ANALYZED));
document.add(new Field("FSN", fullySpecName,
Store.YES, Index.ANALYZED));
document.add(new Field("TERM", fullySpecName,
Store.NO, Index.ANALYZED));
document.add(new Field("PT", preferredTerm, Store.NO,
Index.ANALYZED));
document.add(new Field("TERM", preferredTerm,
Store.NO, Index.ANALYZED));
document.add(new Field("SOURCE", source, Store.NO,
Index.ANALYZED));
document.add(new Field("STATUS", status, Store.YES,
Index.ANALYZED));
document.add(new Field("IS_PRIM", isPrimitive,
Store.NO, Index.NOT_ANALYZED));
document.add(new Field("TYPE", conceptType, Store.NO,
Index.ANALYZED));
Collection<String> synonyms = concept.getSynonyms();
for (String synonym : synonyms) {
document.add(new Field("SYN", synonym, Store.NO,
Index.ANALYZED));
document.add(new Field("TERM", synonym, Store.NO,
Index.ANALYZED));
}
indexWriter.addDocument(document);
if (logger.isDebugEnabled() && counter % 1000 == 0) {
logger.debug("Concepts indexed : " + counter);
}
counter++;
}
rs.close();
statement.close();
indexWriter.optimize();
indexWriter.commit();
} catch (SQLException e) {
logger.warn(e.fillInStackTrace());
} catch (ConceptNotFoundException e) {
logger.warn(e.fillInStackTrace());
} catch (CorruptIndexException e) {
logger.warn(e.fillInStackTrace());
} catch (IOException e) {
logger.warn(e.fillInStackTrace());
}
}
The above code snippets contain the relevant classes and calls being
made.
Ans 1. I am not calling the index generator directly from my IDE. I am
calling it from my running JBoss application.
Ans 2. I introduced a counter (1000) the first time i attempted to
index and it took approximately 40 minutes to complete.
Ans 3. There is no SNOMED CT data being persisted.
Am i doing anything wrong Jay?
Jonathan
On Feb 19, 12:25 am, Jay Kola <
jay.k...@biomedicalontologies.com>
wrote: