<commit_before><?php
 
/**
 * A decorator that adds the ability to index a DataObject in Solr
 * 
 * @author <NAME> <<EMAIL>>
 * @license http://silverstripe.org/bsd-license/
 *
 */
class SolrIndexable extends DataExtension {
	/**
	 * We might not want to index, eg during a data load
	 * 
	 * @var boolean
	 */
	public static $indexing = true;

	/**
	 * Should we index draft content too?
	 *
	 * @var boolean
	 */
	public static $index_draft = true;
	
	/**
	 * @var array
	 */
	public static $dependencies = array(
		'searchService'		=> '%$SolrSearchService',
		'jobQueue'			=> '%$QueuedJobService',
	);
	
	public static $db = array(
		'ResultBoost'		=> 'Int',
	);
	
	protected function createIndexJob($item, $stage = null, $mode = 'index') {
		$job = new SolrIndexItemJob($item, $stage, $mode);
		$this->jobQueue->queueJob($job);
	}

	/**
	 * Index after publish
	 */
	function onAfterPublish() {
		if (!self::$indexing) return;

		if (class_exists('SolrIndexItemJob')) {
			$this->createIndexJob($this->owner, 'Live');
		} else {
			// make sure only the fields that are highlighted in searchable_fields are included!!
			$this->searchService->index($this->owner, 'Live');
		}
	}

	/**
	 * Index after every write; this lets us search on Draft data as well as live data
	 */
	public function onAfterWrite() {
		if (!self::$indexing) return;

		$changes = $this->owner->getChangedFields(true, 2);
		<commit_msg>Don't require the queued jobs module.<commit_after><?php
 
/**
 * A decorator that adds the ability to index a DataObject in Solr
 * 
 * @author <NAME> <<EMAIL>>
 * @license http://silverstripe.org/bsd-license/
 *
 */
class SolrIndexable extends DataExtension {
	/**
	 * We might not want to index, eg during a data load
	 * 
	 * @var boolean
	 */
	public static $indexing = true;

	/**
	 * Should we index draft content too?
	 *
	 * @var boolean
	 */
	public static $index_draft = true;
	
	/**
	 * @var array
	 */
	public static $dependencies = array(
		'searchService'		=> '%$SolrSearchService',
	);
	
	public static $db = array(
		'ResultBoost'		=> 'Int',
	);
	
	protected function createIndexJob($item, $stage = null, $mode = 'index') {
		$job = new SolrIndexItemJob($item, $stage, $mode);
		Injector::inst()->get('QueuedJobService')->queueJob($job);
	}

	/**
	 * Index after publish
	 */
	function onAfterPublish() {
		if (!self::$indexing) return;

		if (class_exists('SolrIndexItemJob')) {
			$this->createIndexJob($this->owner, 'Live');
		} else {
			// make sure only the fields that are highlighted in searchable_fields are included!!
			$this->searchService->index($this->owner, 'Live');
		}
	}

	/**
	 * Index after every write; this lets us search on Draft data as well as live data
	 */
	public function onAfterWrite() {
		if (!self::$indexing) return;

		$changes = $this->owner->getChangedFields(true, 2);
		
{'fraction_non_alphanumeric': 0.1522198731501057, 'fraction_numerical': 0.0007047216349541931, 'mean_word_length': 3.5351437699680512, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 32, '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': '2342716', 'n_tokens_mistral': 1003, 'n_tokens_neox': 903, 'n_words': 267}