<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Latest posts for the topic "最近看書用eclipse測試lucene的程式碼都有bug?不知那裡出錯了..(程式碼都書本一樣)"]]></title>
		<link>https://forum.andowson.com/posts/list/3.page</link>
		<description><![CDATA[Latest messages posted in the topic "最近看書用eclipse測試lucene的程式碼都有bug?不知那裡出錯了..(程式碼都書本一樣)"]]></description>
		<generator>JForum - http://www.jforum.net</generator>
			<item>
				<title>最近看書用eclipse測試lucene的程式碼都有bug?不知那裡出錯了..(程式碼都書本一樣)</title>
				<description><![CDATA[ [code=java] 
<br>
package ch2.lucenedemo.process; 
<br>
<br>
import java.io.BufferedReader; 
<br>
import java.io.File; 
<br>
import java.io.FileReader; 
<br>
import java.io.IOException; 
<br>
<br>
import javax.swing.filechooser.FileFilter; 
<br>
<br>
import jeasy.analysis.MMAnalyzer; 
<br>
<br>
import org.apache.lucene.document.Document; 
<br>
import org.apache.lucene.document.Field; 
<br>
import org.apache.lucene.index.IndexWriter; 
<br>
<br>
public class IndexProcesser { 
<br>
 // 成員變數儲存建立的索引檔案存放的位置 
<br>
 private String INDEX_STORE_PATH = "d:\\index"; 
<br>
<br>
 // 建立索引 
<br>
 public void createIndex(String inputDir) { 
<br>
 try { 
<br>
 // MMAnalyzer作為分詞工具建立一個IndexWriter 
<br>
 IndexWriter writer = new IndexWriter(INDEX_STORE_PATH, 
<br>
 new MMAnalyzer(), true); 
<br>
 File filesDir = new File(inputDir); 
<br>
 // 取得所有需要建立索引的檔案陣列 
<br>
 File[] files = filesDir.listFiles(); 
<br>
 // 檢查陣列 
<br>
 for (int i = 0; i &lt; files.length; i++) { 
<br>
 // 獲得檔案名 
<br>
 String fileName = files[i].getName(); 
<br>
 // 判斷檔案是否為txt類型的檔案 
<br>
 if (fileName.substring(fileName.lastIndexOf(".")) 
<br>
 .equals(".txt")) { 
<br>
 // 建立一個新的Document 
<br>
 Document doc = new Document(); 
<br>
 // 為檔案名建立一個Field 
<br>
 Field field = new Field("filename", files[i].getName(), 
<br>
 Field.Store.YES, Field.Index.TOKENIZED); 
<br>
 doc.add(field); 
<br>
 // 為檔案內容建立一個Filed 
<br>
 field = new Field("content", loadFileToString(files[i]), 
<br>
 Field.Store.NO, Field.Index.TOKENIZED); 
<br>
 doc.add(field); 
<br>
 // 把Document加入IndexWriter 
<br>
 writer.addDocument(doc); 
<br>
 } 
<br>
 } 
<br>
 // 關閉IndexWriter 
<br>
 writer.close(); 
<br>
<br>
 } catch (Exception e) { 
<br>
 e.printStackTrace(); 
<br>
 } 
<br>
<br>
 } 
<br>
<br>
 public static void main(String[] args) { 
<br>
 IndexProcesser processor = new IndexProcesser(); 
<br>
 processor.createIndex("d:\\testfolder"); 
<br>
 } 
<br>
 public String loadFileToString(File file) { 
<br>
 try { 
<br>
 BufferedReader br = new BufferedReader(new FileReader(file)); 
<br>
 StringBuffer sb = new StringBuffer(); 
<br>
 String line = br.readLine(); 
<br>
 while (line != null) { 
<br>
 sb.append(line); 
<br>
 line = br.readLine(); 
<br>
 } 
<br>
 br.close(); 
<br>
 return sb.toString(); 
<br>
 } catch (IOException e) { 
<br>
 e.printStackTrace(); 
<br>
 return null; 
<br>
 } 
<br>
 } 
<br>
<br>
} 
<br>
[/code] 
<br>
麻煩各位大大幫忙小弟如何解決與並還要安裝什麼語言才可測試.. 
<br>
<br>
此外eclipse測試下列三種都會有bug: 
<br>
import org.apache.lucene.document.Document; 
<br>
import org.apache.lucene.document.Field; 
<br>
import org.apache.lucene.index.IndexWriter; 
<br>
不知eclipse還要安裝什麼檔案才可執行]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/470/970.page</guid>
				<link>https://forum.andowson.com/posts/preList/470/970.page</link>
				<pubDate><![CDATA[Fri, 21 Jan 2011 14:53:22]]> GMT</pubDate>
				<author><![CDATA[ l98179012]]></author>
			</item>
			<item>
				<title>回覆:最近看書用eclips測試lucene的程式碼都有bug?不知那裡出錯了..(程式碼都書本一樣)</title>
				<description><![CDATA[ 就您所提供之圖片來看，基本上程式碼應該沒什麼錯誤，該加入到CLASSPATH的jar檔也都加了，還是有這種找不到Class的問題，我也不清楚原因了。 
<br>
<br>
如果硬要死馬要當活馬醫的話，我的建議就是重新再開一個新的Java Project，然後把程式碼先貼到記事本，再貼過去，再試試看。]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/470/971.page</guid>
				<link>https://forum.andowson.com/posts/preList/470/971.page</link>
				<pubDate><![CDATA[Fri, 21 Jan 2011 19:14:43]]> GMT</pubDate>
				<author><![CDATA[ andowson]]></author>
			</item>
	</channel>
</rss>