`
zhangljerry
  • 浏览: 140736 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

关于compass如何重建索引

 
阅读更多
当重建索引时,先建备份索引,然后通过操作替换原索引文件.compass的一个解决方案是
把备份索引replace操作原索引文件,方法是
getSearchEngineIndexManager().replaceIndex(SearchEngineIndexManager,SearchEngineIndexManager)
  简单code
  indexCompass = compass.clone(
                new CompassSettings().setSetting(CompassEnvironment.CONNECTION_SUB_CONTEXT, "gpsindex"));
        indexCompass.getSearchEngineIndexManager().deleteIndex();
        indexCompass.getSearchEngineIndexManager().createIndex();
        indexCompassTemplate = new CompassTemplate(indexCompass);

        indexCompass.getSearchEngineIndexManager().clearCache();
        compass.getSearchEngineIndexManager().replaceIndex(
                indexCompass.getSearchEngineIndexManager(), new SearchEngineIndexManager.ReplaceIndexCallback() {
            public void buildIndexIfNeeded() throws SearchEngineException {
                for (Iterator it = devices.values().iterator(); it.hasNext();) {
                    // Here we build the new index (based on indexCompass)
                    CompassGpsDevice device = (CompassGpsDevice) it.next();
                    device.index();
                }
            }
        });

        indexCompass.getSearchEngineIndexManager().deleteIndex();
        indexCompass.close();
   indexCompass是创建备份索引,compass是原索引的compass

还有根据DualCompassGps的code
  boolean stoppedMirrorCompassOptimizer = false;
        boolean stoppedIndexCompassOptimizer = false;
        if (mirrorCompass != null && mirrorCompass.getSearchEngineOptimizer().isRunning()) {
            mirrorCompass.getSearchEngineOptimizer().stop();
            stoppedMirrorCompassOptimizer = true;
        }
        if (indexCompass.getSearchEngineOptimizer().isRunning()) {
            indexCompass.getSearchEngineOptimizer().stop();
            stoppedIndexCompassOptimizer = true;
        }

        indexCompass.getSearchEngineIndexManager().clearCache();
        indexCompass.getSearchEngineIndexManager().deleteIndex();
        indexCompass.getSearchEngineIndexManager().createIndex();
       
       mirrorCompass.getSearchEngineIndexManager().replaceIndex(
                indexCompass.getSearchEngineIndexManager(), new SearchEngineIndexManager.ReplaceIndexCallback() {
            public void buildIndexIfNeeded() throws SearchEngineException {
                // Here, we build the index (into the index compass)
                for (Iterator it = devices.values().iterator(); it.hasNext();) {
                    CompassGpsDevice device = (CompassGpsDevice) it.next();
                    device.index();
                }
            }
        });

        if (stoppedMirrorCompassOptimizer) {
            mirrorCompass.getSearchEngineOptimizer().start();
        }
        if (stoppedIndexCompassOptimizer) {
            indexCompass.getSearchEngineOptimizer().start();
        }

  indexcompass是备份索引的Compass, mirrorCompass是当前索引的Compass

根据实现这code 在替换(红色code)是会产生异常现象,主要和搜索时的异常
建议删除原索引,然后重命名为原索引
分享到:
评论
1 楼 kekeemx 2008-03-04  
你好,我最近也在研究Compass做一个站内搜索的项目,
有些问题想与你交流一下可以么.
我的MSN是:kekeemx@hotmail.com

相关推荐

Global site tag (gtag.js) - Google Analytics