Commit 6d57a2b5 authored by John David Osborne's avatar John David Osborne
Browse files

Poorly performing UMLS search using Lucene

parent 46ba453c
......@@ -46,5 +46,34 @@
<artifactId>lucene-core</artifactId>
<version>6.0.0</version>
</dependency>
<!-- http://mvnrepository.com/artifact/org.apache.lucene/lucene-queryparser -->
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-queryparser</artifactId>
<version>6.0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19</version>
<configuration>
<argLine>-Xmx1000m</argLine>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
package edu.uab.ccts.nlp.umlsIndex.test.integration;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import static org.junit.Assert.*;
import java.io.IOException;
import java.nio.file.Paths;
import org.junit.Test;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.FSDirectory;
/**
* Unit test for simple App.
*/
public class LuceneIndexIT
extends TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public LuceneIndexIT( String testName )
{
super( testName );
}
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( LuceneIndexIT.class );
}
/**
* Rigourous Test :-)
*/
public void testApp()
{
assertTrue( true );
}
private IndexSearcher searcher = null;
private QueryParser parser = null;
/**
* Create the test case
*
* @param testName name of the test case
*/
public LuceneIndexIT() throws IOException
{
searcher = new IndexSearcher(DirectoryReader.open(FSDirectory.open(Paths.get("target/index.lucene"))));
parser = new QueryParser("stemmedTerms", new StandardAnalyzer());
}
/**
*/
@org.junit.Test
public void testIndex() throws Exception
{
TopDocs td = performSearch("cancer", 2);
ScoreDoc[] hits = td.scoreDocs;
System.out.println("Number of hits: " + hits.length);
for (int i = 0; i < hits.length; i++) {
Document hitDoc = searcher.doc(hits[i].doc);
System.out.println(hitDoc.get("stemmedTerms"));
System.out.println(hitDoc.get("cui"));
System.out.println(hitDoc.get("sty"));
//assertEquals("C0814136", hitDoc.get("cui"));
}
}
public TopDocs performSearch(String queryString, int n)
throws IOException, ParseException {
Query query = parser.parse(queryString);
return searcher.search(query, n);
}
public Document getDocument(int docId)
throws IOException {
return searcher.doc(docId);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment