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

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


      StringWriter sw= new StringWriter();
      sw.append(" +identifier:" + identifier);
      sw.append(" +languageid:" + languageId);
      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;
    }
View Full Code Here


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

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

TOP

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

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.