Package org.compass.core

Examples of org.compass.core.CompassSession


    }

  }
 
  public void removeItem(Item item) {
    CompassSession compassSession = compass.openSession();
    CompassTransaction compassTransaction = compassSession.beginTransaction();
    String query = "+itemId:" + item.getItemId().toString();
    CompassHits hits = compassSession.find(query);
    Iterator<?> iterator = hits.detach().iterator();
    while (iterator.hasNext()) {
      DefaultCompassHit defaultCompassHit = (DefaultCompassHit) iterator.next();
      compassSession.delete(defaultCompassHit.getData());
    }
   
    compassTransaction.commit();
    compassSession.close();
  }
View Full Code Here


  public void updateItem(Item master, SiteProfileClass siteProfileClasses[]) throws Exception {
    if (siteProfileClasses == null) {
      siteProfileClasses = getSiteProfileClasses();
    }
   
    CompassSession compassSession = compass.openSession();
    CompassTransaction compassTransaction = compassSession.beginTransaction();

    String query = "+itemId:" + master.getItemId().toString();
    CompassHits hits = compassSession.find(query);
    Iterator<?> iterator = hits.detach().iterator();
    while (iterator.hasNext()) {
      DefaultCompassHit defaultCompassHit = (DefaultCompassHit) iterator.next();
      compassSession.delete(defaultCompassHit.getData());
    }
   
    if (!master.getItemTypeCd().equals(Constants.ITEM_TYPE_SKU)) {
      if (isShareInventory) {
        for (SiteProfileClass siteProfileClass : siteProfileClasses) {
          boolean found = false;
          for (ItemLanguage language : master.getItemLanguages()) {
            if (language.getSiteProfileClass().getSiteProfileClassId().equals(siteProfileClass.getSiteProfileClassId())) {
              found = true;
              CompassItemLanguage compassItemLanguage = formatItemLanguage(master, language, -1L);
              compassSession.save(compassItemLanguage);
            }
          }
          if (!found) {
            CompassItemLanguage compassItemLanguage = formatItemLanguage(master, master.getItemLanguage(), -1L);
            compassItemLanguage.setSiteProfileClassId(siteProfileClass.getSiteProfileClassId());
            compassSession.save(compassItemLanguage);
          }
        }
      }
      else {
        for (SiteDomain siteDomain : master.getSiteDomains()) {
          for (SiteProfileClass siteProfileClass : siteProfileClasses) {
            boolean found = false;
            for (ItemLanguage language : master.getItemLanguages()) {
              if (language.getSiteProfileClass().getSiteProfileClassId().equals(siteProfileClass.getSiteProfileClassId())) {
                found = true;
                CompassItemLanguage compassItemLanguage = formatItemLanguage(master, language, siteDomain.getSiteDomainId());
                compassSession.save(compassItemLanguage);
              }
            }
            if (!found) {
              CompassItemLanguage compassItemLanguage = formatItemLanguage(master, master.getItemLanguage(), siteDomain.getSiteDomainId());
              compassItemLanguage.setSiteProfileClassId(siteProfileClass.getSiteProfileClassId());
              compassSession.save(compassItemLanguage);
            }
          }
        }
      }
    }
   
    compassTransaction.commit();
    compassSession.close();
  }
View Full Code Here

    compassTransaction.commit();
    compassSession.close();
  }
 
  public void removeContent(Content content) {
    CompassSession compassSession = compass.openSession();
    CompassTransaction compassTransaction = compassSession.beginTransaction();
    String query = "+contentId:" + content.getContentId().toString();
    CompassHits hits = compassSession.find(query);
    Iterator<?> iterator = hits.detach().iterator();
    while (iterator.hasNext()) {
      DefaultCompassHit defaultCompassHit = (DefaultCompassHit) iterator.next();
      compassSession.delete(defaultCompassHit.getData());
    }
   
    compassTransaction.commit();
    compassSession.close();
  }
View Full Code Here

 
  public void updateContent(Content master, SiteProfileClass siteProfileClasses[]) throws Exception {
    if (siteProfileClasses == null) {
      siteProfileClasses = getSiteProfileClasses();
    }
    CompassSession compassSession = compass.openSession();
    CompassTransaction compassTransaction = compassSession.beginTransaction();

    String query = "+contentId:" + master.getContentId().toString();
    CompassHits hits = compassSession.find(query);
    Iterator<?> iterator = hits.detach().iterator();
    while (iterator.hasNext()) {
      DefaultCompassHit defaultCompassHit = (DefaultCompassHit) iterator.next();
      compassSession.delete(defaultCompassHit.getData());
    }
   
    for (SiteProfileClass siteProfileClass : siteProfileClasses) {
      boolean found = false;
      for (ContentLanguage language : master.getContentLanguages()) {
        if (language.getSiteProfileClass().getSiteProfileClassId().equals(siteProfileClass.getSiteProfileClassId())) {
          found = true;
          CompassContentLanguage compassContentLanguage = formatContentLanguage(master, language);
          compassSession.save(compassContentLanguage);
        }
      }
      if (!found) {
        CompassContentLanguage compassContentLanguage = formatContentLanguage(master, master.getContentLanguage());
        compassContentLanguage.setSiteProfileClassId(siteProfileClass.getSiteProfileClassId());
        compassSession.save(compassContentLanguage);
      }
    }
   
    compassTransaction.commit();
    compassSession.close();
  }
View Full Code Here

        indexerInfo.setContentUpdateCount(contentUpdateCount);
        updateIndexerInfo(indexerInfo);
  }
 
  public QueryResult search(String criteria, Long siteProfileClassId, Long siteDomainId, int pageNum, int pageSize) throws Exception {
    CompassSession compassSession = compass.openSession();
    CompassTransaction compassTransaction = compassSession.beginTransaction();
   
    Calendar calendar = Calendar.getInstance();
    String infoPublishTo = dateFormat.format(calendar.getTime());
    calendar.add(Calendar.DATE, 1);
    String infoExpireFrom = dateFormat.format(calendar.getTime());
   
    QueryResult result = new QueryResult();
    String query = "+siteId:" + siteId +
             " +siteProfileClassId:" + siteProfileClassId.toString() +
             " +published:" + "Y" +
             " +infoPublishOn:[19000101 TO " + infoPublishTo + "]" +
             " +infoExpireOn:[" + infoExpireFrom + " TO 29991231]";
    if (!isShareInventory) {
      query += " +siteDomainId:" + siteDomainId;
    }
    query += " +(" + criteria + ")";
//query = criteria;
    CompassHits hits = compassSession.find(query);
    result.setHitCount(hits.getLength());
   
    int start = (pageNum - 1) * pageSize;
    int end = start + pageSize - 1;
    Vector<Object> queryHits = new Vector<Object>();
    Iterator<?> iterator = hits.detach().iterator();
    int pos = -1;
    while (iterator.hasNext()) {
      pos++;
      DefaultCompassHit defaultCompassHit = (DefaultCompassHit) iterator.next();
      if (pos < start) {
        continue;
      }
      if (pos > end) {
        break;
      }
      queryHits.add(defaultCompassHit.getData());
    }
    result.setQueryHits(queryHits);
    compassTransaction.commit();
    compassSession.close();
    return result;
  }
View Full Code Here

        return null;
    }

    public List executeQuery (ObjectContext context, QuerySpecification spec)
    {
        CompassSession session = getCompass(context).openSession();
        CompassTransaction tr = session.beginTransaction();
        CompassQueryBuilder builder = session.queryBuilder();
        CompassQuery query = queryForPredicate(builder, spec.getPredicate());

        Class targetClass = ClassUtil.classForName(spec.getEntityName());
        query.setTypes(targetClass);

        // CompassHits hits = session.find(query);
        List results = processHits(context, query.hits());

        tr.commit();
        session.close();

        return results;
    }
View Full Code Here

    }

    public <T extends Model> Page<T> search(String queryString,PageCriteria pageCriteria,Class<T> modelClass){
        List<T> result =  new ArrayList<>();
        Compass compass = compassTemplate.getCompass();
        CompassSession session=compass.openSession();
        CompassHits hits=  session.find(queryString);
        LOG.info("命中:"+hits.getLength());
        LOG.info("查询字符串:"+queryString);
        if(pageCriteria!=null){
            int start = (pageCriteria.getPage()-1) * pageCriteria.getSize();
            int end = (pageCriteria.getPage()-1) * pageCriteria.getSize() + pageCriteria.getSize();
            if (end > hits.getLength()) {
                end = hits.getLength();
            }
            for(int i=start;i<end;i++){
                if(hits.data(i).getClass()==modelClass){
                    //T t=(T)hits.data(i);
                    try{
                        T t=hightlight(modelClass,hits,i);
                        result.add(t);
                    }catch(Exception e){
                        result.add((T)hits.data(i));
                    }
                }
            }
        }else{
            for(int i=0;i<hits.getLength();i++){
                if(hits.data(i).getClass()==modelClass){
                    //T t=(T)hits.data(i);
                    try{
                        T t=hightlight(modelClass,hits,i);
                        result.add(t);
                    }catch(Exception e){
                        result.add((T)hits.data(i));
                    }
                }
            }
        }
        session.close();

        //对搜索结果按主键递减的顺序排序,最新的数据在最前面
        //Comparator comparter=new BeanComparator("id");
        //Collections.sort(result, comparter);
        //Collections.reverse(result);
View Full Code Here

        session.close();
    }
    @Transactional
    public void createIndex(Model model) {
        try{
            CompassSession session = getCompassSession();
            try {
                session.create(model);
            } catch (Exception e) {
                String info=e.getMessage();
                LOG.error("创建索引失败", e);
                LOG.error("Failed in building index", e, Locale.ENGLISH);

                if(info.indexOf("LockObtainFailedException")!=-1){
                    int index=info.indexOf("@");
                    String path=info.substring(index+1);
                    File file=new File(path);
                    file.delete();
                    fixIndex();
                    session.create(model);
                }
            } finally{
                closeCompassSession(session);
            }
        }catch(Exception e){
View Full Code Here

    }
    @Transactional
    public void updateIndex(Class<? extends Model> type, Model model) {
        try{
            deleteIndex(type,model.getId());
            CompassSession session = getCompassSession();
            try {
                session.save(model);
            } catch (Exception e) {
                String info=e.getMessage();
                LOG.error("更新索引失败", e);
                LOG.error("Failed to update index", e, Locale.ENGLISH);
                if(info.indexOf("LockObtainFailedException")!=-1){
                    int index=info.indexOf("@");
                    String path=info.substring(index+1);
                    File file=new File(path);
                    file.delete();
                    fixIndex();
                    session.save(model);
                }
            } finally{
                closeCompassSession(session);
            }
        }catch(Exception e){
View Full Code Here

        }
    }
    @Transactional
    public void deleteIndex(Class<? extends Model> type, Object objectID) {
        try{
            CompassSession session = getCompassSession();
            try {
                session.delete(session.load(type, objectID));
            } catch (Exception e) {
                String info=e.getMessage();
                LOG.error("删除索引失败", e);
                LOG.error("Failed to delete index", e , Locale.ENGLISH);
                if(info.indexOf("LockObtainFailedException") != -1){
                    int index=info.indexOf("@");
                    String path=info.substring(index+1);
                    File file=new File(path);
                    file.delete();
                    fixIndex();
                    //再次删除
                    session.delete(session.load(type, objectID));
                }
            } finally{
                closeCompassSession(session);
            }
        }catch(Exception e){
View Full Code Here

TOP

Related Classes of org.compass.core.CompassSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.