<commit_before>/*******************************************************************************
 * Copyright Searchbox - http://www.searchbox.com
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package com.searchbox.core.search.result;

import java.util.Set;
import java.util.TreeSet;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.searchbox.core.SearchAttribute;
import com.searchbox.core.SearchComponent;
import com.searchbox.core.search.SearchElement;
import com.searchbox.core.search.UseCollector;

@SearchComponent
public class TemplateElement extends SearchElement implements UseCollector {

  private static final Logger LOGGER = LoggerFactory.getLogger(TemplateElement.class);
  
  private static final String COLLECTOR_KEY = "hits";
  private static final String DEFAUTL_TEMPLATE = "/WEB-INF/templates/_defaultHitView.jspx";

  @SearchAttribute
  protected Set<String> fields;

  @SearchAttribute
  private String templateFile;

  @SearchAttribute
  String titleField;

  @SearchAttribute
  String urlField;

  @SearchAttribute
  String idField;

  public TemplateElement() {
    super("Result Set with Template", SearchElement.Type.VIEW);
    this.fields = new TreeSet<String>();
  }
  
  public boolean hasTempalte(){
    return this.templateFile != null && !this.templateFile.isEmpty();
  }

  public Set<String> getRequiredFields() {
    Set<String> fields = this.getFields();
    if (idField != null && !idField.isEmpty()) {
      fields.add(idField);
    }
    if (titleField != null && !titleField.isEmpty()) {
      fields.add(titleField);
    }
    if (urlField != null && !urlField.isEmpty()) {
      fields.add(urlField);
    }
    return fields;
  }
  
  public void setTemplateFile(String templateFile) {
    this.templateFile = templateFile;
  }

  public String getTemplateFile() {
    if(hasTempalte()){
      return this.templateFile;
    } else {
      return TemplateElement.DEFAUTL_TEMPLATE;
    }
  }

  public String getTitleField() {
    return titleField;
  }

  public void setTitleField(String titleField) {
    this.titleField = titleField;
  }

  public String getUrlField() {
    return urlField;
  }

  public void setUrlField(String urlField) {
    this.urlField = urlField;
  }

  public String getIdField() {
    return idField;
  }

  public void setIdField(String idField) {
    this.idField = idField;
  }

  public void setFields(Set<String> fields) {
    this.fields = fields;
  }

  public Set<String> getFields() {
    return this.fields;
  }

  @Override
  public String getCollectorKey() {
    return TemplateElement.COLLECTOR_KEY;
  }
}
<commit_msg>Small mistake in getCollectorKey. #ToUpStream<commit_after>/*******************************************************************************
 * Copyright Searchbox - http://www.searchbox.com
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package com.searchbox.core.search.result;

import java.util.Set;
import java.util.TreeSet;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.searchbox.core.SearchAttribute;
import com.searchbox.core.SearchComponent;
import com.searchbox.core.search.SearchElement;
import com.searchbox.core.search.UseCollector;

@SearchComponent
public class TemplateElement extends SearchElement implements UseCollector {

  private static final Logger LOGGER = LoggerFactory.getLogger(TemplateElement.class);
  
  private static final String COLLECTOR_KEY = "hits";
  private static final String DEFAUTL_TEMPLATE = "/WEB-INF/templates/_defaultHitView.jspx";

  @SearchAttribute
  protected Set<String> fields;

  @SearchAttribute
  private String templateFile;

  @SearchAttribute
  String titleField;

  @SearchAttribute
  String urlField;

  @SearchAttribute
  String idField;

  public TemplateElement() {
    super("Result Set with Template", SearchElement.Type.VIEW);
    this.fields = new TreeSet<String>();
  }
  
  public boolean hasTempalte(){
    return this.templateFile != null && !this.templateFile.isEmpty();
  }

  public Set<String> getRequiredFields() {
    Set<String> fields = this.getFields();
    if (idField != null && !idField.isEmpty()) {
      fields.add(idField);
    }
    if (titleField != null && !titleField.isEmpty()) {
      fields.add(titleField);
    }
    if (urlField != null && !urlField.isEmpty()) {
      fields.add(urlField);
    }
    return fields;
  }
  
  public void setTemplateFile(String templateFile) {
    this.templateFile = templateFile;
  }

  public String getTemplateFile() {
    if(hasTempalte()){
      return this.templateFile;
    } else {
      return TemplateElement.DEFAUTL_TEMPLATE;
    }
  }

  public String getTitleField() {
    return titleField;
  }

  public void setTitleField(String titleField) {
    this.titleField = titleField;
  }

  public String getUrlField() {
    return urlField;
  }

  public void setUrlField(String urlField) {
    this.urlField = urlField;
  }

  public String getIdField() {
    return idField;
  }

  public void setIdField(String idField) {
    this.idField = idField;
  }

  public void setFields(Set<String> fields) {
    this.fields = fields;
  }

  public Set<String> getFields() {
    return this.fields;
  }

  @Override
  public String getCollectorKey() {
    if(this.getLabel().isEmpty()){
      return TemplateElement.COLLECTOR_KEY;
    } else {
      return this.getLabel();
    }
  }
}

{'fraction_non_alphanumeric': 0.14106870229007634, 'fraction_numerical': 0.00183206106870229, 'mean_word_length': 3.8815201192250375, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2893004', 'n_tokens_mistral': 1884, 'n_tokens_neox': 1825, 'n_words': 504}