Ejemplo n.º 1
0
  @Override
  protected void addSearchLocalizedTerm(
      BooleanQuery searchQuery, SearchContext searchContext, String field, boolean like)
      throws Exception {

    if (Validator.isNull(field)) {
      return;
    }

    String value = String.valueOf(searchContext.getAttribute(field));

    if (Validator.isNull(value)) {
      value = searchContext.getKeywords();
    }

    if (Validator.isNull(value)) {
      return;
    }

    field = DocumentImpl.getLocalizedName(searchContext.getLocale(), field);

    if (searchContext.isAndSearch()) {
      searchQuery.addRequiredTerm(field, value, like);
    } else {
      searchQuery.addTerm(field, value, like);
    }
  }
  @Override
  protected Map<String, Query> addSearchLocalizedTerm(
      BooleanQuery searchQuery, SearchContext searchContext, String field, boolean like)
      throws Exception {

    if (Validator.isNull(field)) {
      return Collections.emptyMap();
    }

    String value = String.valueOf(searchContext.getAttribute(field));

    if (Validator.isNull(value)) {
      value = searchContext.getKeywords();
    }

    if (Validator.isNull(value)) {
      return Collections.emptyMap();
    }

    String localizedField = DocumentImpl.getLocalizedName(searchContext.getLocale(), field);

    Map<String, Query> queries = new HashMap<>();

    if (Validator.isNull(searchContext.getKeywords())) {
      BooleanQuery localizedQuery = new BooleanQueryImpl();

      Query query = localizedQuery.addTerm(field, value, like);

      queries.put(field, query);

      Query localizedFieldQuery = localizedQuery.addTerm(localizedField, value, like);

      queries.put(field, localizedFieldQuery);

      BooleanClauseOccur booleanClauseOccur = BooleanClauseOccur.SHOULD;

      if (searchContext.isAndSearch()) {
        booleanClauseOccur = BooleanClauseOccur.MUST;
      }

      searchQuery.add(localizedQuery, booleanClauseOccur);
    } else {
      Query query = searchQuery.addTerm(localizedField, value, like);

      queries.put(field, query);
    }

    return queries;
  }