Blog信息 |
blog名称: 日志总数:1304 评论数量:2242 留言数量:5 访问次数:7618770 建立时间:2006年5月29日 |

| |
[Java Open Source]基于SPRING MVC的COMPASS限制搜索 软件技术
lhwork 发表于 2006/7/31 11:46:43 |
当索引数据很多的时候,我们必须做一定的处理来减少数据的压力,我这里提供一个很简单的办法扩展CompassSearchController恩对,也许还有高手的高招,可是我的理解能力有限吧 只学会了他,中间还应用到内部类下面是完整的代码public class CompassPageTest{ public static void main(String[] arg){ CompassPageTest test=new CompassPageTest(); test.search(); } class compassInner extends CompassSearchController{ compassInner(CompassConfiguration config){ compasscompass=config.buildCompass(); CompassSession session=compass.openSession(); CompassTransaction tran=session.beginTransaction(); CompassSearchCommand command=new CompassSearchCommand(); command.setQuery("name:限制"); setPageSize(1); CompassSearchResults results= performSearch(command,session); for(int i=0;i<results.getHits().length;i++){ CompassHit hits=results.getHits()[i]; Entity entity=(Entity)hits.getData(); System.out.println(entity.getName()); System.out.println(entity.getValue()); System.out.println(entity.getId());
} System.out.println("pages:"+results.getHits().length); tran.commit(); } } public void search(){ File file=new File("E:/Projects/proTest/net/my/entity.cpm.xml"); CompassConfiguration config =new CompassConfiguration().configure(file).addClass(Entity.class); config.setConnection(""); config.setSetting("compass.engine.connection","CHINESE"); compassInner inner=new compassInner(config); System.out.println("pages:"+inner.getPageSize()); }}我们只需要在上面加亮显示的位置做自己的参数就可以了是不是很简单,当然也许是个很龌龊的办法,正在研究不是MVC 业务的办法,因为我必须在底层service操作 |
|
|