Commits

Jonathan Simms committed b59384f

more work porting the SearchFiles thing to scala

Comments (0)

Files changed (1)

src/net/freenose/lucener/SearchFiles.scala

 package net.freenose.lucener
 
 import com.frugalmechanic.optparse.OptParse
-import java.io.File
+import java.io.{InputStreamReader, FileInputStream, BufferedReader, File}
 import org.apache.lucene.index.{DirectoryReader, IndexReader}
 import org.apache.lucene.store.FSDirectory
+import org.apache.lucene.search.IndexSearcher
+import org.apache.lucene.analysis.standard.StandardAnalyzer
+import org.apache.lucene.util.Version
+import org.apache.lucene.queryparser.classic.QueryParser
 
 /*
 "Usage:\tjava org.apache.lucene.demo.SearchFiles [-index dir] [-field f] [-repeat n] [-queries file] [-query string] [-raw] [-paging hitsPerPage]\n\nSee http://lucene.apache.org/java/4_0/demo.html for details.";
 */
 
-class SearchFiles {
+class SearchFiles(val reader: IndexReader,
+                  val searcher: IndexSearcher,
+                  val analyzer: StandardAnalyzer,
+                  val parser: QueryParser,
+                  val input: BufferedReader) {
 
 }
 
 object SearchFiles {
   object options extends OptParse {
-    val index = FileOpt(desc = "index dir")
+    val index = FileOpt(
+      default = new File(Default.IndexDir),
+      desc = "index dir"
+    )
+
     val field = StrOpt(default = "contents")
 
     val repeat = IntOpt(
-      default = 0,
       short = 'r',
+      default = 0,
       desc = "dunno what it does, but it better be an int"
     )
 
     )
   }
 
-
   def main(args: Array[String]) {
     options.parse(args)
+
+    withIndexReader(options.index.get) { reader =>
+      repl(reader)
+    }
+
+  }
+
+  private def repl(reader: IndexReader) {
+    val searcher = new IndexSearcher(reader)
+    val analyzer = new StandardAnalyzer(Version.LUCENE_40)
+    val parser = new QueryParser(Version.LUCENE_40, options.field.get, analyzer)
+
+  }
+
+  private def withBufferedIn(f: BufferedReader => Unit) {
+    val in = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"))
+    try {
+      f(in)
+    } finally {
+      in.close()
+    }
+  }
+
+  private def inputStream: FileInputStream = {
+    options.queries.value match {
+      case Some(f)  => new FileInputStream(f)
+      case None     => System.in
+    }
   }
 
   private def withIndexReader(file: File)(f: IndexReader => Unit) {