ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dlig...@apache.org
Subject svn commit: r1696842 - in /ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/index: IndexSentences.java SearchUtility.java
Date Thu, 20 Aug 2015 19:03:26 GMT
Author: dligach
Date: Thu Aug 20 19:03:26 2015
New Revision: 1696842

URL: http://svn.apache.org/r1696842
Log:
upgrades to lucene 4.0 plus minor refactoring

Modified:
    ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/index/IndexSentences.java
    ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/index/SearchUtility.java

Modified: ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/index/IndexSentences.java
URL: http://svn.apache.org/viewvc/ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/index/IndexSentences.java?rev=1696842&r1=1696841&r2=1696842&view=diff
==============================================================================
--- ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/index/IndexSentences.java (original)
+++ ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/index/IndexSentences.java Thu
Aug 20 19:03:26 2015
@@ -76,7 +76,7 @@ public class IndexSentences {
    */
   public static class RelationContextPrinter extends JCasAnnotator_ImplBase {
     
-    final static String searchField = "text";
+    final static String fieldName = "text";
     final static String indexLocation = "/Users/dima/Boston/Data/DeepPhe/Index/";
     
     IndexWriter indexWriter;
@@ -113,8 +113,7 @@ public class IndexSentences {
         Document document = new Document();
         String withLineBreaks = sentence.getCoveredText();
         String noLineBreaks = withLineBreaks.replace("\n", " ");
-        // document.add(new Field("content", noLineBreaks, Field.Store.YES, Field.Index.ANALYZED,
Field.TermVector.YES));
-        document.add(new Field(searchField, noLineBreaks, TextField.TYPE_STORED));
+        document.add(new Field(fieldName, noLineBreaks, TextField.TYPE_STORED));
         try {
           indexWriter.addDocument(document);
         } catch (IOException e) {

Modified: ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/index/SearchUtility.java
URL: http://svn.apache.org/viewvc/ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/index/SearchUtility.java?rev=1696842&r1=1696841&r2=1696842&view=diff
==============================================================================
--- ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/index/SearchUtility.java (original)
+++ ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/index/SearchUtility.java Thu
Aug 20 19:03:26 2015
@@ -6,30 +6,32 @@ import java.io.IOException;
 import javax.swing.JOptionPane;
 
 import org.apache.lucene.document.Document;
-import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.DirectoryReader;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.PhraseQuery;
 import org.apache.lucene.search.ScoreDoc;
 import org.apache.lucene.search.TopDocs;
+import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.FSDirectory;
 
 public class SearchUtility {
   
   public static void main(String[] args) throws IOException {
 
-    final int maxHits = 100;
-    final String searchField = "content";
+    final int maxHits = 1000;
+    final String fieldName = "text";
     final String indexLocation = "/Users/dima/Boston/Data/DeepPhe/Index/";
 
     String queryText = JOptionPane.showInputDialog("Enter query");
     
-    IndexReader indexReader = IndexReader.open(FSDirectory.open(new File(indexLocation)));
+    Directory directory = FSDirectory.open(new File(indexLocation));
+    DirectoryReader indexReader = DirectoryReader.open(directory);
     IndexSearcher indexSearcher = new IndexSearcher(indexReader);
 
     PhraseQuery phraseQuery = new PhraseQuery();
     for(String word : queryText.split(" ")) {
-      phraseQuery.add(new Term(searchField, word));
+      phraseQuery.add(new Term(fieldName, word));
     }
     phraseQuery.setSlop(0);
     
@@ -38,11 +40,14 @@ public class SearchUtility {
 
     for(ScoreDoc scoreDoc : scoreDocs) {
       Document document = indexSearcher.doc(scoreDoc.doc);
-      String text = document.get(searchField).toLowerCase().replace('\n', ' ');
+      String text = document.get(fieldName);
       System.out.println(text);
+      System.out.println();
     }
-    
-    // indexSearcher.close();
+
+    directory.close();
+    indexReader.close();
+
     System.out.println("total hits: " + scoreDocs.length);
   }
 }



Mime
View raw message