mysearcher.java

来自「java实现的全文搜索引擎」· Java 代码 · 共 58 行

JAVA
58
字号
/**
 * Strategy Pattern
 */
package cn.edu.nju.software.ruse;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.HashSet;

/**
 * @author spring
 *
 */
public class MySearcher extends SearchFiles {

	RUSE ruse;
	
	/**
	 *Hold the index.
	 */
	//private Map<String,HashSet<File>> hm;
	private Index index;
	
	@SuppressWarnings("unchecked")
	public MySearcher(String indexPlace) {
		/**
		 * Read index from disk to memory.
		 * */
//System.err.println("@MySearcher Read index from disk to memory.");

		try {
			ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(new FileInputStream(indexPlace + "\\index.dat")));
			this.index = (Index) ois.readObject();
			ois.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
//System.err.println("@MySearcher Read successfully.");
		this.parser = new OperatorParser(index);

	}

	public HashSet<File> getResult() {
		return ((OperatorParser)this.parser).getResult();
	}
}

⌨️ 快捷键说明

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