Exemple #1
0
  public QProfileRuleResult search(ProfileRuleQuery query, Paging paging) {
    SearchHits ruleHits =
        searchRules(
            query,
            paging,
            ruleFilterForActiveRuleSearch(query)
                .must(hasChildFilter(ESActiveRule.TYPE_ACTIVE_RULE, activeRuleFilter(query))));
    List<Integer> ruleIds = Lists.newArrayList();
    for (SearchHit ruleHit : ruleHits) {
      ruleIds.add(Integer.valueOf(ruleHit.id()));
    }

    List<QProfileRule> result = Lists.newArrayList();
    if (!ruleIds.isEmpty()) {
      SearchHits activeRuleHits = searchActiveRules(query, ruleIds, FIELD_SOURCE, FIELD_PARENT);

      Map<String, SearchHit> activeRuleByParent = Maps.newHashMap();
      for (SearchHit activeRuleHit : activeRuleHits) {
        activeRuleByParent.put(
            (String) activeRuleHit.field(FIELD_PARENT).getValue(), activeRuleHit);
      }

      for (SearchHit ruleHit : ruleHits) {
        result.add(
            new QProfileRule(
                ruleHit.sourceAsMap(), activeRuleByParent.get(ruleHit.id()).sourceAsMap()));
      }
    }
    return new QProfileRuleResult(
        result,
        PagingResult.create(paging.pageSize(), paging.pageIndex(), ruleHits.getTotalHits()));
  }
Exemple #2
0
 public QProfileRuleResult searchInactives(ProfileRuleQuery query, Paging paging) {
   SearchHits hits =
       searchRules(
           query, paging, ruleFilterForInactiveRuleSearch(query), FIELD_SOURCE, FIELD_PARENT);
   List<QProfileRule> result = Lists.newArrayList();
   for (SearchHit hit : hits.getHits()) {
     result.add(new QProfileRule(hit.sourceAsMap()));
   }
   return new QProfileRuleResult(
       result, PagingResult.create(paging.pageSize(), paging.pageIndex(), hits.getTotalHits()));
 }