<commit_before><?php

/**
 * This is a bridge to the Apache_Solr_Service class
 **/
class Search_Handler_Solr implements Search_Handler_Interface
{
  protected $_service;

  /**
   * __construct builds a Apache_Solr_Service
   *
   * @param $host The Solr host
   * @param $port The Solr port
   * @param $path The Solr url prefix
   **/
  public function __construct($host, $port, $path)
  {
    $this->_service = new Apache_Solr_Service($host, $port, $path);
  }

  /**
   * @see Search_Handler_Interface::isAvailable()
   **/
  public function isAvailable()
  {
    return $this->_service->ping();
  }

  /**
   * @see Search_Handler_Interface::index()
   **/
  public function index(array $document)
  {
    $doc = new Apache_Solr_Document();

    foreach($document as $fieldName => $field)
    {
      $value = $field['value'];

      // Apache_Solr_Document always expect arrays
      if(!is_array($value))
        $value = array($value);

      $fieldBoost = $field['boost'];

      $doc->setField($fieldName, $value, $fieldBoost);
    }
<commit_msg>split a method to ease testing<commit_after><?php

/**
 * This is a bridge to the Apache_Solr_Service class
 **/
class Search_Handler_Solr implements Search_Handler_Interface
{
  protected $_service;

  /**
   * __construct builds a Apache_Solr_Service
   *
   * @param $host The Solr host
   * @param $port The Solr port
   * @param $path The Solr url prefix
   **/
  public function __construct($host, $port, $path)
  {
    $this->_service = new Apache_Solr_Service($host, $port, $path);
  }

  /**
   * @see Search_Handler_Interface::isAvailable()
   **/
  public function isAvailable()
  {
    return $this->_service->ping();
  }

  /**
   * Builds an Apache_Solr_Document to pass to Apache_Solr_Service
   **/
  public function buildDocument(array $document)
  {
    $doc = new Apache_Solr_Document();

    foreach($document as $fieldName => $field)
    {
      $value = $field['value'];

      // Apache_Solr_Document always expect arrays
      if(!is_array($value))
        $value = array($value);

      $fieldBoost = $field['boost'];

      $doc->setField($fieldName, $value, $fieldBoost);
    }

    return $doc;
  }

  /**
   * @see Search_Handler_Interface::index()
   **/
  public function index(array $document)
  {
    $doc = $this->buildDocument($document);
{'fraction_non_alphanumeric': 0.1369098712446352, 'fraction_numerical': 0.0, 'mean_word_length': 3.2151898734177213, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5080240', 'n_tokens_mistral': 769, 'n_tokens_neox': 740, 'n_words': 178}