Package com.dotcms.repackage.org.elasticsearch.action.search

Examples of com.dotcms.repackage.org.elasticsearch.action.search.SearchResponse


          bw.write(MAPPING_MARKER);
          bw.write(mapping);
          bw.newLine();

          // setting up the search for all content
      SearchResponse scrollResp = client.prepareSearch(index).setSearchType(SearchType.SCAN).setQuery(QueryBuilders.matchAllQuery())
          .setSize(100).setScroll(TimeValue.timeValueMinutes(2)).execute().actionGet();
      while (true) {
        scrollResp = client.prepareSearchScroll(scrollResp.getScrollId()).setScroll(TimeValue.timeValueMinutes(2)).execute()
            .actionGet();
        boolean hitsRead = false;
        for (SearchHit hit : scrollResp.getHits()) {
          bw.write(hit.getId());
          bw.write(JSON_RECORD_DELIMITER);
          bw.write(hit.sourceAsString());
          bw.newLine();
          hitsRead = true;
View Full Code Here


    @Override
    protected List<Contentlet> findAllCurrent ( int offset, int limit ) throws ElasticSearchException {

        QueryBuilder builder = QueryBuilders.matchAllQuery();

        SearchResponse response = client.getClient().prepareSearch()
                .setQuery( builder ).addFields("inode","identifier")
                .setSize( limit ).setFrom( offset ).execute().actionGet();
        SearchHits hits = response.getHits();
        List<Contentlet> cons = new ArrayList<Contentlet>();

        for ( SearchHit hit : hits ) {
            try {
                cons.add( find( hit.field("inode").getValue().toString() ) );
View Full Code Here

      sw.append(" +deleted:false");

      SearchRequestBuilder request = createRequest(client, sw.toString());

      IndiciesInfo info=APILocator.getIndiciesAPI().loadIndicies();
      SearchResponse response = request.setIndices((live ? info.live : info.working))
              .addFields("inode","identifier").execute().actionGet();
      SearchHits hits = response.getHits();
      Contentlet contentlet = find(hits.getAt(0).field("inode").getValue().toString());
      return contentlet;
    }
    // if we don't have the con in this language
    catch(java.lang.ArrayIndexOutOfBoundsException aibex){
View Full Code Here

  }

  protected List<Contentlet> findContentletsByHost(String hostId, int limit, int offset) throws DotDataException {
    try {

      SearchResponse response = createRequest(client.getClient(), "+conhost:"+hostId).
              setSize(limit).setFrom(offset).addFields("inode","identifier").execute()
          .actionGet();

      SearchHits hits = response.getHits();

      List<Contentlet> cons = new ArrayList<Contentlet>();
      for (int i = 0; i < hits.getHits().length; i++) {
        try {
          cons.add(find(hits.getAt(i).field("inode").getValue().toString()));
View Full Code Here

          indexToHit=info.live;
      else
          indexToHit=info.working;

      Client client=new ESClient().getClient();
      SearchResponse resp = null;
        try {

          SearchRequestBuilder srb = createRequest(client,qq);

          srb.setIndices(indexToHit);
          srb.addFields("inode","identifier");

            if(limit>0)
                srb.setSize(limit);
            if(offset>0)
                srb.setFrom(offset);

            if(UtilMethods.isSet(sortBy)) {
              if(sortBy.equals("random")) {
                srb.addSort(SortBuilders.scriptSort("Math.random()", "number"));
              }
              else if(sortBy.endsWith("-order")) {
                  // related content ordering
                  int ind0=sortBy.indexOf('-'); // relationships tipicaly have a format stname1-stname2
                  int ind1=ind0>0 ? sortBy.indexOf('-',ind0+1) : -1;
                  if(ind1>0) {
                      String relName=sortBy.substring(0, ind1);
                      if((ind1+1)<sortBy.length()) {
                          String identifier=sortBy.substring(ind1+1, sortBy.length()-6);
                          if(UtilMethods.isSet(identifier)) {
                              srb.addSort(SortBuilders.scriptSort("related", "number")
                                                      .lang("native")
                                                      .param("relName", relName)
                                                      .param("identifier", identifier)
                                                      .order(SortOrder.ASC));
                          }
                      }
                  }
              }
              else if(!sortBy.startsWith("undefined") && !sortBy.startsWith("undefined_dotraw")) {
                String[] sortbyArr=sortBy.split(",");
                for (String sort : sortbyArr) {
                  String[] x=sort.trim().split(" ");
  //                srb.addSort(SortBuilders.fieldSort(x[0].toLowerCase()).order(x.length>1 && x[1].equalsIgnoreCase("desc") ?
  //                            SortOrder.DESC : SortOrder.ASC));
  //                srb.addSort(SortBuilders.fieldSort(x[0].toLowerCase() + ".org").order(x.length>1 && x[1].equalsIgnoreCase("desc") ?
  //                          SortOrder.DESC : SortOrder.ASC));
                  srb.addSort(SortBuilders.fieldSort(x[0].toLowerCase() + "_dotraw").order(x.length>1 && x[1].equalsIgnoreCase("desc") ?
                                  SortOrder.DESC : SortOrder.ASC));
  //                srb.addSort(x[0].toLowerCase(),x.length>1 && x[1].equalsIgnoreCase("desc") ?
  //                            SortOrder.DESC : SortOrder.ASC);

          }
              }
            }
            try{
              resp = srb.execute().actionGet();
            }catch (SearchPhaseExecutionException e) {
        if(e.getMessage().contains("dotraw] in order to sort on")){
          return new InternalSearchHits(InternalSearchHits.EMPTY,0,0);
        }else{
          throw e;
        }
      }
        } catch (Exception e) {         
            throw new RuntimeException(e);
        }
      return resp.getHits();
  }
View Full Code Here

            APILocator.getSiteSearchAPI().createSiteSearchIndex( indexName, null, 1 );
            APILocator.getSiteSearchAPI().activateIndex( indexName );
        }

        Client client = new ESClient().getClient();
        SearchResponse resp;
        try {
            QueryStringQueryBuilder qb = QueryBuilders.queryString( qq );
            SearchRequestBuilder srb = client.prepareSearch();
            srb.setQuery( qb );

            srb.setIndices( indexName );
            srb.addFields( "id" );

            try {
                resp = srb.execute().actionGet();
            } catch ( SearchPhaseExecutionException e ) {
                if ( e.getMessage().contains( "dotraw] in order to sort on" ) ) {
                    return new InternalSearchHits( InternalSearchHits.EMPTY, 0, 0 );
                } else {
                    throw e;
                }
            }
        } catch ( Exception e ) {
            Logger.error( ESContentFactoryImpl.class, e.getMessage(), e );
            throw new RuntimeException( e );
        }
        return resp.getHits();
    }
View Full Code Here

TOP

Related Classes of com.dotcms.repackage.org.elasticsearch.action.search.SearchResponse

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.