Package com.erudika.para.utils

Examples of com.erudika.para.utils.Pager


      logger.info("rebuildIndex(): {}", appid);

      BulkRequestBuilder brb = getClient().prepareBulk();
      BulkResponse resp = null;
      Pager pager = new Pager();

      List<ParaObject> list = dao.readPage(appid, null);

      if (!list.isEmpty()) {
        do {
          for (ParaObject obj : list) {
            brb.add(getClient().prepareIndex(appid, obj.getType(), obj.getId()).
                setSource(Utils.getAnnotatedFields(obj)));
            pager.setLastKey(obj.getId());
          }
          // bulk index 1000 objects
          if (brb.numberOfActions() > 100) {
            resp = brb.execute().actionGet();
            logger.info("rebuildIndex(): indexed {}, hasFailures: {}",
View Full Code Here


    String query = params.containsKey("q") ? params.getFirst("q") : "*";
    String type = (typeOverride != null) ? typeOverride : params.getFirst(Config._TYPE);
    String appid = Config.APP_NAME_NS; // TODO
    String desc = params.containsKey("desc") ? params.getFirst("desc") : "true";

    Pager pager = new Pager();
    pager.setPage(NumberUtils.toLong(params.getFirst("page"), 0));
    pager.setSortby(params.getFirst("sort"));
    pager.setDesc(Boolean.parseBoolean(desc));

    String queryType = params.containsKey("querytype") ? params.getFirst("querytype") : null;
    Map<String, Object> result = new HashMap<String, Object>();
    List<P> items = new ArrayList<P>();

    if ("id".equals(queryType)) {
      String id = params.containsKey(Config._ID) ? params.getFirst(Config._ID) : null;
      P obj = search.findById(appid, id);
      if (obj != null) {
        items = Collections.singletonList(obj);
        pager.setCount(1);
      }
    } else if ("nearby".equals(queryType)) {
      String latlng = params.getFirst("latlng");
      if (latlng != null) {
        String[] coords = latlng.split(",", 2);
        String rad = params.containsKey("radius") ? params.getFirst("radius") : null;
        int radius = NumberUtils.toInt(rad, 10);
        double lat = NumberUtils.toDouble(coords[0], 0);
        double lng = NumberUtils.toDouble(coords[1], 0);
        items = search.findNearby(appid, type, query, radius, lat, lng, pager);
      }
    } else if ("prefix".equals(queryType)) {
      items = search.findPrefix(appid, type, params.getFirst("field"), params.getFirst("prefix"), pager);
    } else if ("similar".equals(queryType)) {
      List<String> fields = params.get("fields");
      if (fields != null) {
        items = search.findSimilar(appid, type, params.getFirst("filterid"),
            fields.toArray(new String[]{}), params.getFirst("like"), pager);
      }
    } else if ("tagged".equals(queryType)) {
      List<String> tags = params.get("tags");
      if (tags != null) {
        items = search.findTagged(appid, type, tags.toArray(new String[]{}), pager);
      }
    } else if ("in".equals(queryType)) {
      items = search.findTermInList(appid, type, params.getFirst("field"), params.get("terms"), pager);
    } else if ("terms".equals(queryType)) {
      String matchAll = params.containsKey("matchall") ? params.getFirst("matchall") : "true";
      List<String> termsList = params.get("terms");
      if (termsList != null) {
        Map<String, String> terms = new HashMap<String, String>(termsList.size());
        for (String termTuple : termsList) {
          if (!StringUtils.isBlank(termTuple) && termTuple.contains(Config.SEPARATOR)) {
            String[] split = termTuple.split(Config.SEPARATOR, 2);
            terms.put(split[0], split[1]);
          }
        }
        if (params.containsKey("count")) {
          pager.setCount(search.getCount(appid, type, terms));
        } else {
          items = search.findTerms(appid, type, terms, Boolean.parseBoolean(matchAll), pager);
        }
      }
    } else if ("wildcard".equals(queryType)) {
      items = search.findWildcard(appid, type, params.getFirst("field"), query, pager);
    } else if ("count".equals(queryType)) {
      pager.setCount(search.getCount(appid, type));
    } else {
      items = search.findQuery(appid, type, query, pager);
    }

    result.put("items", items);
    result.put("totalHits", pager.getCount());
    return result;
  }
View Full Code Here

TOP

Related Classes of com.erudika.para.utils.Pager

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.