コード例 #1
0
ファイル: SearchAction.java プロジェクト: mwagdi/gbif-portal
  /**
   * Checks if the dataset search result match (highlighted text) only occurred in the full text
   * field. This method goes through all highlighted fields that may be highlighted:
   *
   * <pre>
   * <arr name="hl.fl">
   *   <str>dataset_title</str>
   *   <str>keyword</str>
   *   <str>iso_country_code</str>
   *   <str>owning_organization_title</str>
   *   <str>hosting_organization_title</str>
   *   <str>description</str>
   * </arr>
   * </pre>
   *
   * If there is no highlighted text in any of these fields, it can be inferred that the match must
   * have occurred in the full text field. </br> If the query text was null, there can be no
   * matching anyways so the method just returns false.
   *
   * @param result DatasetSearchResult
   * @return whether a match only occurred on the full text field or not
   */
  public static boolean isFullTextMatchOnly(DatasetSearchResult result, String query) {
    if (Strings.isNullOrEmpty(query)) {
      return false;
    }
    final String keywords =
        result.getKeywords() == null ? "" : TOKEN_JOINER.join(result.getKeywords());
    if (isHighlightedText(result.getTitle())
        || isHighlightedText(result.getDescription())
        || isHighlightedText(result.getOwningOrganizationTitle())
        || isHighlightedText(result.getHostingOrganizationTitle())
        || isHighlightedText(keywords)) {

      return false;
    }
    // otherwise, it must have been a match against the full_text field
    return true;
  }