📄 testlucene.java
字号:
package com.laozizhu.search.demo;
import java.util.List;
import com.laozizhu.search.Factory;
import com.laozizhu.search.Item;
import com.laozizhu.search.SearchResult;
import com.laozizhu.search.Store;
import com.laozizhu.search.util.EngineUtil;
public class TestLucene {
/**
* @param args
*/
public static void main(String[] args) {
Store store = (Store) Factory.getBean("LuceneStore");
SearchResult sr = store.seach("java", 0, 10);
List<Item> items = sr.getReturnList();
for (Item o : items) {
System.out.println(o.getUrl());
}
}
public static void main2(String[] args) {
// 获得数据
System.out.println("Fetching...");
String url = "http://blog.csdn.net/java2000_net/archive/2009/02/05/3864808.aspx";
Item item = EngineUtil.get(url);
// 加入索引
System.out.println("Indexing...");
Store store = (Store) Factory.getBean("LuceneStore");
store.save(item);
show(store, url);
// 关键字查询
System.out.println("Searching...");
SearchResult sr = store.seach("老紫竹", 0, 10);
List<Item> items = sr.getReturnList();
for (Item o : items) {
System.out.println(o.getTitle());
}
// 更新索引数据
System.out.println("Updating...");
item.setTitle("CHANGED:" + item.getTitle());
store.save(item);
show(store, url);
// 优化索引
store.optimize();
// 删除索引
System.out.println("Deleting....");
store.deleteByUrl(url);
// 再次查询
System.out.println("ReSearching...");
show(store, url);
System.out.println("Finished!");
}
private static void show(Store lucene, String url) {
Item item = lucene.searchByUrl(url);
if (item == null) {
System.out.println("NOT FOUND!");
return;
}
System.out.println(item.getTitle());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -