<commit_before><?php

class Sidane_Threadmarks_Search_DataHandler_Threadmark extends XenForo_Search_DataHandler_Abstract
{
  protected $_threadmarkModel = null;
  protected $_postModel = null;
  protected $_threadModel = null;

  /**
   * Inserts a new record or replaces an existing record in the index.
   *
   * @param XenForo_Search_Indexer $indexer Object that will will manipulate the index
   * @param array $data Data that needs to be updated
   * @param array|null $parentData Data about the parent info (eg, for a post, the parent thread)
   */
  protected function _insertIntoIndex(XenForo_Search_Indexer $indexer, array $data, array $parentData = null)
  {
    if ($data['message_state'] != 'visible')
    {
      return;
    }

    $metadata = array();
    $title = '';

    if ($parentData)
    {
      $thread = $parentData;
      if ($thread['discussion_state'] != 'visible')
      {
        return;
      }
      $title = $thread['title'];

      $metadata['node'] = $thread['node_id'];
    }

    $metadata['thread'] = $data['thread_id'];

    $indexer->insertIntoIndex(
      'threadmark', $data['post_id'],
      $title, $data['label'],
      $data['post_date'], $data['user_id'], $data['thread_id'], $metadata
    );
  }

  /**
   * Updates a record in the index.
   *
   * @param XenForo_Search_Indexer $indexer Object that will will manipulate the index
   * @param array $data Data that needs to be updated
   * @param array $fieldUpdates Key-value fields to update
   */
  protected function _updateIndex(XenForo_Search_Indexer $indexer, array $data, array $fieldUpdates)
  {
    $indexer->updateIndex('threadmark', $data['post_id'], $fieldUpdates);
  }

  /**<commit_msg>Correctly handle 'title only' searches<commit_after><?php

class Sidane_Threadmarks_Search_DataHandler_Threadmark extends XenForo_Search_DataHandler_Abstract
{
  protected $_threadmarkModel = null;
  protected $_postModel = null;
  protected $_threadModel = null;

  /**
   * Inserts a new record or replaces an existing record in the index.
   *
   * @param XenForo_Search_Indexer $indexer Object that will will manipulate the index
   * @param array $data Data that needs to be updated
   * @param array|null $parentData Data about the parent info (eg, for a post, the parent thread)
   */
  protected function _insertIntoIndex(XenForo_Search_Indexer $indexer, array $data, array $parentData = null)
  {
    if ($data['message_state'] != 'visible')
    {
      return;
    }

    $metadata = array();
    $title = '';

    if ($parentData)
    {
      $thread = $parentData;
      if ($thread['discussion_state'] != 'visible')
      {
        return;
      }
      // title only makes sense if a collection of threadmarks have their own title independent of threads
      //$title = $thread['title'];

      $metadata['node'] = $thread['node_id'];
    }

    $metadata['thread'] = $data['thread_id'];

    $indexer->insertIntoIndex(
      'threadmark', $data['post_id'],
      $title, $data['label'],
      $data['post_date'], $data['user_id'], $data['thread_id'], $metadata
    );
  }

  /**
   * Updates a record in the index.
   *
   * @param XenForo_Search_Indexer $indexer Object that will will manipulate the index
   * @param array $data Data that needs to be updated
   * @param array $fieldUpdates Key-value fields to update
   */
  protected function _updateIndex(XenForo_Search_Indexer $indexer, array $data, array $fieldUpdates)
  {
    $indexer->updateIndex('threadmark', $data['post_id'], $fieldUpdates);
  }

  /**
{'fraction_non_alphanumeric': 0.12301587301587301, 'fraction_numerical': 0.0, 'mean_word_length': 3.501275510204082, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '5904840', 'n_tokens_mistral': 1093, 'n_tokens_neox': 1064, 'n_words': 304}