⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myprocess.java

📁 java实现的全文搜索引擎
💻 JAVA
字号:
/**
 *First, split the words from the files,and then use them to build index.
 */
package cn.edu.nju.software.ruse;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

/**
 * @author spring
 */
public class MyProcess extends ProcessFiles {

	RUSE ruse;
	
	/**
	 * A data structure for the index
	 */
	//private Map<String,HashSet<File>> hm = new HashMap<String,HashSet<File>>();
	private Index index = new Index();
	
	public MyProcess() {
		
	}
	
	/**
	 * @param list hold all the files read from the directory.
	 * DocHandler implements ProcessDoc interface.
	 * TxtHandler implements ProcessTxt interface.
	 * Strategy Pattern here.
	 */
	public MyProcess(File[] list) {
		index.setFileNameIndex(list);
		this.pd = new DocHandler(index);
		this.pt = new TxtHandler(index);
	}
	
	/**
	 * Use HashMap to build index.
	 * First, serialize the the HashMap, and then write it to a .dat file. 
	 */
	public void buildIndex(String indexPlace) {
		//System.err.println("@MyProcess starting to build index!");
		try {
			File f = new File(indexPlace);
			f.mkdirs();
			ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(indexPlace + "\\index.dat")));
			out.writeObject(index);
			out.flush();
			out.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		//System.err.println("@MyProcess Index successfully!");
	}

	public Index getIndex() {
		return index;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -