第二章:lucene构建索引(新增、查询、更新、删除)

package lucene2;


import java.io.IOException;


import junit.framework.TestCase;


import org.apache.lucene.analysis.WhitespaceAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.Version;
import org.junit.Test;


/**
 * 构建索引(基本的新增、查询、更新、删除)
 * @author zhangwx
 *
 */
public class IndexTest extends TestCase{
	protected String[] ids = {"1","2"};
	protected String[] unidexed = {"Netherlands","Italy"};
	protected String[] unstored ={"Amsterdam has lots of bridges","Venice has lots of canals"};
	protected String[] text = {"Amsterdam","Venice"};
	
	private Directory directory;//索引目录
	
	@Override
	protected void setUp() throws Exception {
		directory = new RAMDirectory();//内存索引
		IndexWriter writer = getWriter();
		for(int i=0;i

你可能感兴趣的:(lucene)