Package org.compass.core

Examples of org.compass.core.CompassHits


        CompassHitsOperations hits = compassTemplate
                .executeFind(new CompassCallback() {
                    public Object doInCompass(CompassSession session)
                            throws CompassException {

                        CompassHits hits = session.queryBuilder()
                                .queryString(searchString).toQuery()
                                .setAliases(aliases).addSort(
                                        "searchOrder",
                                        SortPropertyType.INT,
                                        SortDirection.REVERSE).hits();

                        return hits.detach(start, max_num_hits);
                    }
                });
        log.debug("Search " + searchString + " alias "
                + ArrayUtils.toString(aliases) + " hits "
                + hits.getLength());
        return hits;
    }
View Full Code Here


            compassTemplate.execute(new CompassCallback() {
                public Object doInCompass(CompassSession session)
                        throws CompassException {

                    CompassHits hits = session.queryBuilder()
                            .queryString(searchString).toQuery()
                            .setAliases(aliases).addSort(
                                    "popularityCounter",
                                    SortPropertyType.INT,
                                    SortDirection.REVERSE).hits();
                    log.debug("search string " + searchString + " hits "
                            + hits.length());
                    for (int i = start; i < hits.length()
                            && i < max_num_hits; i++) {
                        String name = hits.resource(i).get("name");
                        // log.debug("search string " + searchString
                        // + " hit: " + name + " "
                        // + hits.resource(i));
                        if (name != null) {
                            rtn.add(name);
View Full Code Here

        assertEquals("Matt", user.getFirstName());

        compassTemplate.execute(new CompassCallbackWithoutResult() {
            @Override
            protected void doInCompassWithoutResult(CompassSession compassSession) throws CompassException {
                CompassHits hits = compassSession.find("Matt");
                assertEquals(1, hits.length());
                assertEquals("Matt", ((User) hits.data(0)).getFirstName());
                assertEquals("Matt", hits.resource(0).getValue("firstName"));
            }
        });

        // test mirroring
        user = dao.get(-2L);
        user.setFirstName("MattX");
        dao.saveUser(user);

        // now verify it is reflected in the index
        user = compassTemplate.get(User.class, -2);
        assertNotNull(user);
        assertEquals("MattX", user.getFirstName());

        compassTemplate.execute(new CompassCallbackWithoutResult() {
            @Override
            protected void doInCompassWithoutResult(CompassSession compassSession) throws CompassException {
                CompassHits hits = compassSession.find("MattX");
                assertEquals(1, hits.length());
                assertEquals("MattX", ((User) hits.data(0)).getFirstName());
            }
        });
    }
View Full Code Here

 
  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());
    }
   
View Full Code Here

   
    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());
    }
   
View Full Code Here

 
  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());
    }
   
View Full Code Here

    }
    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());
    }
   
View Full Code Here

    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) {
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);

        //建立页面对象
        Page<T> page= new  Page<>();
        page.setModels(result);
        page.setTotalRecords(hits.getLength());

        return page;
    }
View Full Code Here

      List<Archivale> archivalien = new ArrayList<Archivale>();
      rechercheBean.setArchivalien(archivalien);

      CompassSearchSession session = compass.openSearchSession();
      try {
        CompassHits hits = session.find(suchKriterium);
        System.out.println("Hits");
        for (int i = 0; i < hits.getLength(); i++) {
          archivalien.add((Archivale) hits.data(i));
          System.out.println(hits.hit(i).score() + " "
              + hits.hit(i).getHighlightedText());
        }
      } finally {
        session.close();
      }
    }
View Full Code Here

TOP

Related Classes of org.compass.core.CompassHits

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.